Exemplo n.º 1
2
void addXData()
{
	// Get an Entity.
	ads_name mnEnt;
    ads_point ptSel;
    int nRet = acedEntSel(_T("\nSelect an Entity: "), mnEnt, ptSel);
	if (nRet != RTNORM)
		return;
	AcDbObjectId oid;
	
    Acad::ErrorStatus retStat;
    retStat = acdbGetObjectId(oid, mnEnt);
    if (retStat != Acad::eOk)
		return;

    AcDbObject* pObj = NULL;

    if ((retStat = acdbOpenObject(pObj, oid, AcDb::kForRead)) != Acad::eOk)
    {
        return;
    }
	// Get new XData.
	TCHAR appName[132] = {0};
	TCHAR resString[200] = {0};

    acedGetString(NULL, _T("\nEnter application name: "), appName);
    acedGetString(NULL, _T("\nEnter string to be added: "), resString);

    // XData
    resbuf *pRb = NULL;
	resbuf *pTemp = NULL;
    
    pRb = pObj->xData(appName);

    if (pRb != NULL)
	{
        for (pTemp = pRb; pTemp->rbnext != NULL; pTemp = pTemp->rbnext);
    }
	else
	{
        acdbRegApp(appName);
        pRb = acutNewRb(AcDb::kDxfRegAppName);
        pTemp = pRb;
        pTemp->resval.rstring = (TCHAR*)malloc((_tcslen(appName) + 1) * sizeof(TCHAR));
        _tcscpy(pTemp->resval.rstring, appName);
    }

    pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);
    pTemp = pTemp->rbnext;
    pTemp->resval.rstring = (TCHAR*)malloc((_tcslen(resString) + 1) * sizeof(TCHAR));
    _tcscpy(pTemp->resval.rstring, resString);

	// Set XData.
    pObj->upgradeOpen();
    pObj->setXData(pRb);
    
    pObj->close();
    acutRelRb(pRb);
}
Exemplo n.º 2
0
String GetSelectedExtent() {
  ads_name selection;
  int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection);
  if (returnValue == RTCAN) return 0;
  if (returnValue != RTNORM) {
    return L"";
  }

  if (acedSSSetFirst(selection, NULL) != RTNORM) {
    acedSSFree(selection);
    return L"";
  }
  ads_name element;
  acedSSName(selection, 0, element);
  acedSSFree(selection);
  
  AcDbObjectId idEntity;
  if (acdbGetObjectId(idEntity, element) != Acad::eOk) {
    acedSSFree(element);
    return L"";
  }
  
  AcDbEntity * entity;
  if ((acdbGetObjectId(idEntity, element) != Acad::eOk) || 
      (acdbOpenObject(entity, idEntity, AcDb::kForRead) != Acad::eOk)) {
    
    acedSSFree(element);
    return L"";
  }
  
  acedSSFree(element);
  
  if (!entity->isKindOf(AcDbPolyline::desc())) return L"";
  
  AcDbPolyline * poly = static_cast<AcDbPolyline*>(entity);
  if (!poly->isClosed()) return 0;
  
  String extent = L"POLYGON((";
  AcGePoint2d start;
  AcGePoint2d current;
  for (int i = 0; i < poly->numVerts(); i++) {
    poly->getPointAt(i, current);
    
    if (i > 0) {
      extent += L", ";
    } else {
      start = current;
    }
    extent += Round(current.x, 0) + L" " + Round(current.y, 0);
  }
  if (!start.isEqualTo(current)) {
    extent += L", " + Round(start.x, 0) + L" " + Round(start.y, 0);
  }
  
  extent += L"))";
  
  poly->close();
  
  return extent;
}
Exemplo n.º 3
0
void jig3d()
{
    
    try
    {
        struct resbuf rb;
        acedGetVar("cvport", &rb);
        if (rb.resval.rint==1)
            throw CmdException("3djig cannot be used in layout mode");
        ads_name ename;
        ads_point pt;
		int rt;
        if ((rt = acedEntSel("Select object:",ename,pt))==RTCAN)
			return;
		if (rt!=RTNORM)
			throw CmdException(Acad::eInvalidInput,"Invalid selection. Try again!");
        AcDbObjectId id;
        acdbGetObjectId(id,ename);

        Jig3d jig;
        jig.init(id, asPnt3d(pt), rb.resval.rint);
        jig.engage();
    }
    catch(CmdException e)
    {
        const char* strDesc = e.description();
        if (strDesc == NULL)
            strDesc = "No description.";
        acutPrintf("ERROR:%s (es=%s)",strDesc,acadErrorStatusText(e.errorStatus()));
    }
}
Exemplo n.º 4
0
AcDbObject* ZcEntityReactor::selectObject(AcDb::OpenMode openMode)
{
	int nRet = 0;
	ads_name en;
	ads_point pt;

	nRet = acedEntSel(_T("\nSelect an entity:"), en, pt);
	if (nRet != RTNORM)
	{
		return NULL;
	}

	AcDbObjectId eId;
	Acad::ErrorStatus retStat;
	retStat = acdbGetObjectId(eId, en);
	if (retStat != Acad::eOk)
	{
		acutPrintf(_T("\nacdbGetObjectId failed!"));
		return NULL;
	}

	AcDbObject* obj = NULL;
	if ((retStat = acdbOpenObject(obj, eId, openMode)) != Acad::eOk)
	{
		acutPrintf(_T("\nOpen Failed!"));
		return NULL;
	}

	return obj;
}
Exemplo n.º 5
0
// Files data in from a DXF file.
//
Acad::ErrorStatus
AsdkOwnerDemo::dxfInFields(AcDbDxfFiler* filer)
{
    assertWriteEnabled();

    Acad::ErrorStatus es;
    if ((es = AcDbObject::dxfInFields(filer))
            != Acad::eOk)
    {
        return es;
    }

    // Check if we're at the right subclass data marker.
    //
    if (!filer->atSubclassData("AsdkOwnerDemo")) {
        return Acad::eBadDxfSequence;
    }

    struct resbuf inbuf;
    while (es == Acad::eOk) {
        if ((es = filer->readItem(&inbuf)) == Acad::eOk) {
            if (inbuf.restype == AcDb::kDxfInt16) {
                mIntval = inbuf.resval.rint;
            } else if (inbuf.restype
                       == AcDb::kDxfHardOwnershipId)
            {
                acdbGetObjectId(mObjId,
                                inbuf.resval.rlname);
            }
        }
    }
    return filer->filerStatus();
}
Exemplo n.º 6
0
	// - MfcArx.syj_mfc command (do not rename)
	static void MfcArxsyj_mfc(void)
	{
		// Add your code for command MfcArx.syj_mfc here
		ads_name ss;
		resbuf rb;
		AcDbObjectIdArray objIds = NULL;
		acedSSGet(NULL,NULL,NULL,NULL,ss);
		long len;
		//取得选择集的长度
		acedSSLength(ss,&len);
		//遍历选择集中的实体,将其打开并修改其颜色为红色
		for (int i =0;i<len;i++)
		{
			ads_name entres;
			AcDbObjectId objId;
			//取得选择集中实体的名称ads_name
			acedSSName(ss,i,entres);
			//取得实体的ObjectId
			acdbGetObjectId(objId,entres);
			objIds.append(objId);
		}
		acedSSFree(ss);
		CDetailShow ds(objIds,NULL,NULL);
		ds.DoModal();

	}
// This is the main function of this app.  It allows the
// user to select an entity.  It then checks to see if the
// entity is a 2d-polyline.  If so, then it calls iterate
// passing in the objectId of the pline.
// 
void
listPline()
{
    int rc;
    ads_name en;
    AcGePoint3d pt;
    rc = acedEntSel(_T("\nSelect a polyline: "), en,
        asDblArray(pt));

    if (rc != RTNORM) {
        acutPrintf(_T("\nError during object selection"));
        return;
    }

    AcDbObjectId eId;
    acdbGetObjectId(eId, en);

    AcDbObject *pObj;
    acdbOpenObject(pObj, eId, AcDb::kForRead);
    if (pObj->isKindOf(AcDb2dPolyline::desc())) {
        pObj->close();
        iterate(eId);
    } else {
        pObj->close();
        acutPrintf(_T("\nSelected entity is not an AcDb2dPolyline. \nMake sure the setvar PLINETYPE is set to 0 before createing a polyline"));
    }
}
Exemplo n.º 8
0
BOOL TWBlockRefenceTool::Insert( IN const CString& strBlockName, IN const AcGePoint3d& PtIns, IN double dScale, IN double dRat, AcDbDatabase* pDb /*= NULL */ )
{
	/*
		使用简单的实现方法
	*/
	ads_name entPre = { 0, 0 };
	ads_entlast( entPre );

	resbuf rbOld;
	resbuf rbNew;
	rbNew.restype = RTSHORT;
	rbNew.resval.rint = 0;
	acedGetVar( _T("ATTREQ"), &rbOld );
	acedSetVar( _T("ATTREQ"), &rbNew );

	ads_command( RTSTR, _T("insert"), RTSTR, strBlockName, RT3DPOINT, asDblArray(PtIns), RTREAL, 1.0, RTSTR, _T(""), RTREAL, 0.0, 0 );

	acedSetVar( _T("ATTREQ"), &rbOld );

	ads_name ent = { 0 ,0 };
	ads_entlast( ent );

	//判定是否正确生成块参照
	if( ads_name_equal(ent, entPre) )
		return FALSE;

	acdbGetObjectId( m_IdblockRef, ent );
	return IsValid();
}
Exemplo n.º 9
0
// The selectObject() function prompts the user to select an 
// entity or enter an object's handle.  It then proceeds to 
// open the object/entity and return a pointer to it.
// 
AcDbObject*
selectObject(AcDb::OpenMode openMode)
{
    ads_name en;
    ads_point pt;
    char handleStr[132];
    AcDbObjectId eId;

    Acad::ErrorStatus retStat;
    int ss;

    // Allow user to either pick an entity,
    // or type in the object handle.
    //
    acedInitGet(RSG_OTHER, "_Handle Handle");
    ss = acedEntSel("\nSelect an Entity or enter"
        " 'H' to enter its handle:  ", en, pt);

    switch (ss) {
    case RTNORM:   // got it!
        break;
    case RTKWORD:
        if ((acedGetString(Adesk::kFalse,
            "Enter Valid Object Handle: ",
            handleStr) == RTNORM)
            && (acdbHandEnt(handleStr, en) == RTNORM))
        {
            break;
        }
    // Fall-through intentional
    //
    default:
        acutPrintf("Nothing Selected, Return Code==%d\n",
            ss);
        return NULL;
    }

    // Now, exchange the ads_name for the object Id...
    //
    retStat = acdbGetObjectId(eId, en);
    if (retStat != Acad::eOk) {
        acutPrintf("\nacdbGetObjectId failed");
        acutPrintf("\nen==(%lx,%lx), retStat==%d\n",
            en[0], en[1], eId);
        return NULL;
    }

    AcDbObject* pObj;

    if ((retStat = acdbOpenObject(pObj, eId, openMode))
        != Acad::eOk)
    {
        acutPrintf("acdbOpenEntity failed: ename:"
            "(%lx,%lx), mode:%d retStat:%d", en[0],
            en[1], openMode, retStat);
        return NULL;
    }
    return pObj;
}
Exemplo n.º 10
0
    // ----- AsdkSelectionFilterUI.SubentSel command (do not rename)
    static void AsdkSelectionFilterUI_SubentSel(void)
    {
        // we have to allow duplicates; otherwise, the xref would be selectable
        // only once (because the main entity is the one that counts).

        setAllowDuplicateSelection(curDoc(), true);
        ads_name sset, eName;
        AcDbObjectId id;

        // "_:n" gives us nested entities
        //
        if (RTNORM == acedSSGet("_:n", NULL, NULL, NULL, sset))
        {
            acutPrintf("\n");
            long len = 0;
            acedSSLength(sset, &len);
            for (long i = 0; i < len; i++)// For each entity in sset
            {

                resbuf *rb = NULL;
                // We use ssnamex() here, because the regular ssname()
                // would give only the main entity (the xref)
                //
                if (RTNORM == acedSSNameX(&rb, sset, i))//Get the sub entity
                {
                    resbuf *rbWalk = rb;
                    while (NULL != rbWalk)
                    {
                        if (RTENAME == rbWalk->restype)
                        {
                            eName[0] = rbWalk->resval.rlname[0];
                            eName[1] = rbWalk->resval.rlname[1];
                            if(Acad::eOk == acdbGetObjectId(id, eName))
                            {
                                acutPrintf("Entity %d: <%x>", i, id.asOldId());
                                AcDbEntity *pEnt;
                                if (Acad::eOk == acdbOpenObject(pEnt, id, AcDb::kForRead))
                                {
                                    acutPrintf("(%s)\n", pEnt->isA()->name());
                                    pEnt->close();
                                }
                                else
                                    acutPrintf("\nCouldn't open object");
                            }
                            rbWalk = NULL; //force quit out of loop
                        }
                        else
                            rbWalk = rbWalk->rbnext;
                    }
                    acutRelRb(rb);
                }
            }
            acedSSFree(sset);
        }

        setAllowDuplicateSelection(curDoc(), false);
    }
Exemplo n.º 11
0
    //-------------------------------------------------------------------------------------------
    //
    //  功能: 将从AcDbObject派生数据库对象保存到实体的扩展词典中
    //
    //  作者:Qin H.X.
    //
    // 日期:200709
    //
    //  历史:
    //          2007.10.08 修改 by Qin H.X.
    //
    //----------------------------------------------------------------------------------------------
    // - CSCH081.AddAttribute command (do not rename)
    static void CSCH081AddAttribute(void)
    {
        AcDbObjectId dictObjId,eId, attId;
        AcDbDictionary* pDict;
        //选择管道(多义线)
        ads_name en;
        ads_point pt;
        if (  acedEntSel(_T("\n选择管道(多义线): "), en, pt)!= RTNORM)
        {
            acutPrintf(_T("\n选择失败,退出: "));
            return ;
        }
        // 打开对象
        acdbGetObjectId(eId, en);
        AcDbEntity * pEnt;
        acdbOpenObject(pEnt, eId,  AcDb::kForWrite);
        if(!pEnt->isKindOf (AcDbPolyline::desc ()))
        {
            acutPrintf(_T("\n选择的不是管道(多义线),退出: " ));
            return ;
        }

        // 判断实体的扩展词典是否创建,如果没有则创建
        dictObjId = pEnt->extensionDictionary();
        if(	dictObjId ==  AcDbObjectId::kNull )
        {
            pEnt->createExtensionDictionary();
        }

        // 获取实体的扩展词典
        dictObjId = pEnt->extensionDictionary();
        pEnt->close();

        // 	判断词典中的属性是否创建
        CPipeAttribute* pAttribute;
        acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
        pDict->getAt (_T("属性"),attId);
        if(attId!= AcDbObjectId::kNull )//如果已经创建则输出数据
        {
            acdbOpenObject(pAttribute, attId, AcDb::kForRead);
            acutPrintf(_T("\n管径:%4.2f " ),pAttribute->m_dRadius);
            acutPrintf(_T("\n壁厚:%4.2f " ),pAttribute->m_dThickness );
            acutPrintf(_T("\n埋深:%4.2f " ),pAttribute->m_dDeep );
            acutPrintf(_T("\n材质:%s " ),pAttribute->m_cMaterial  );
        }
        else
        {
            //没有则创建属性
            pAttribute = new CPipeAttribute();
            pDict->setAt(_T("属性"), pAttribute, attId);
        }
        //关闭对象
        pDict->close();
        pAttribute->close();

    }
Acad::ErrorStatus
ArxDbgUtils::enameToObjId(ads_name ent, AcDbObjectId& objId)
{
    Acad::ErrorStatus es = acdbGetObjectId(objId, ent);
    ASSERT(es == Acad::eOk);
    if (es != Acad::eOk)
        ArxDbgUtils::rxErrorMsg(es);
    
    return es;
}
Exemplo n.º 13
0
void selectObject(AcDbObjectId& eID)
{
	ads_name en;
	ads_point pt;
	int nReturn;
	nReturn = acedEntSel(_T("\nSelecteaza polilinia de contur: "), en, pt);
	if (nReturn != RTNORM)
		return;
	if (acdbGetObjectId(eID, en) != Acad::eOk)
		return;
}
Exemplo n.º 14
0
void Additional_Class::Get_EntityID( ads_name RtEntity, AcDbObjectId &RtEntityID )
{
	AcDbObjectId PolyLineId;
	Acad::ErrorStatus es = acdbGetObjectId(RtEntityID, RtEntity);
	if (es != Acad::eOk)
	{
		acutPrintf(_T("\nGET ENTITY ID ERROR!"));
// 		this->SetError("GET ENTITY ID ERROR!\n", "Get_EntityID");
// 		m_ErrorList.push_back(m_Error);
		return;
	}
	return;
}
void frgExtractTopologicalEntsFromLinesAlgm::_search_related_segs(AcDbObjectIdArray &ids, const AcGeLineSeg2d &seg)
{
	double tolerance = rlTolerance::equal_point();
	if (seg.length() < 2 * tolerance)
		return;

	// - 构造反选矩形
	// -- 计算四个点
	AcGePoint2d p1, p2, p3, p4;

	AcGeVector2d dir = seg.direction();
	AcGeVector2d offset = dir;
	offset.rotateBy(rlPi / 2.0);

	p1 = seg.startPoint(); p1.transformBy(-offset * tolerance);
	p2 = seg.endPoint(); p2.transformBy(-offset * tolerance);
	p3 = seg.endPoint(); p3.transformBy(offset * tolerance);
	p4 = seg.startPoint(); p4.transformBy(offset * tolerance);

	// -- 构造矩形
	ads_point _p1, _p2, _p3, _p4;
	_p1[0] = p1.x; _p1[1] = p1.y, _p1[2] = 0;
	_p2[0] = p2.x; _p2[1] = p2.y, _p2[2] = 0;
	_p3[0] = p3.x; _p3[1] = p3.y, _p3[2] = 0;
	_p4[0] = p4.x; _p4[1] = p4.y, _p4[2] = 0;
	resbuf *rect = acutBuildList(RTPOINT, _p1, RTPOINT, _p2, RTPOINT, _p3, RTPOINT, _p4, RTNONE);

	// - 交叉查询
	ads_name ss;
	int ret = acedSSGet(_T("CP"), rect, NULL, _filter, ss);
	acutRelRb(rect);
	if (ret != RTNORM)
		return;

	// - 获取查询结果
	long len = 0;
	acedSSLength(ss, &len);
	for (int i = 0; i < len; i++)
	{
		ads_name name;
		acedSSName(ss, i, name);

		AcDbObjectId id;
		if (acdbGetObjectId(id, name) == Acad::eOk)
			ids.append(id);
	}
	acedSSFree(ss);
}
Exemplo n.º 16
0
void CMyDlg::OnSelectLine()
{
	// TODO: Add your control notification handler code here
	ads_name adsNameSet, adsName;
	AcDbObjectId objId;
	int ret = 0;
	long lSelCnt = 0;
	AcDbEntity *pEnt = NULL;
	int nCount = m_ListCtr.GetItemCount();
	long lId;
	CString str;
	AcDbObjectId LineId;

	acDocManager->lockDocument(curDoc());

	ShowWindow(SW_HIDE);
	ret = acedSSGet(NULL, NULL, NULL, NULL, adsNameSet);
	
	if (RTNORM == ret)
	{
		m_ListCtr.SetFocus();
		acedSSLength(adsNameSet, &lSelCnt);
		for (long i = 0; i < lSelCnt; ++i)
		{
			acedSSName(adsNameSet, i, adsName);
			acdbGetObjectId(objId, adsName);
			if (nCount > 0)
			{
				for (int i = 0; i < nCount; ++i)
				{
					str = m_ListCtr.GetItemText(i, 0);
					lId = atol(str);
					LineId.setFromOldId(lId);
					if (LineId == objId)
					{				
						m_ListCtr.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
					}
				}
			}			
		}
		ShowWindow(SW_SHOW);
	}

	acedSSFree(adsName);
//	acutRelRb(stResBuf);
	acDocManager->unlockDocument(curDoc());
}
Exemplo n.º 17
0
void printXData()
{
	// Get an Entity.
	ads_name mnEnt;
    ads_point ptSel;
    int nRet = acedEntSel(_T("\nSelect an Entity: "), mnEnt, ptSel);
	if (nRet != RTNORM)
		return;
	AcDbObjectId oid;
	
    Acad::ErrorStatus retStat;
    retStat = acdbGetObjectId(oid, mnEnt);
    if (retStat != Acad::eOk)
		return;

    AcDbObject* pObj = NULL;

    if ((retStat = acdbOpenObject(pObj, oid, AcDb::kForRead)) != Acad::eOk)
    {
        return;
    }

    // Get the application name for the xdata.
    //
	TCHAR appname[133] = {0};
    if (acedGetString(NULL, _T("\nEnter the Xdata application name: "), appname) != RTNORM)
    {
        return;
    }

    // Get the xdata for the application name.
    //
    resbuf *pRb = pObj->xData(appname);

    if (pRb != NULL)
	{
        printXDList(pRb);
        acutRelRb(pRb);
    }
	else
	{
        acutPrintf(_T("\nNo xdata for appname: %s."), appname);
    }
    pObj->close();
}
Exemplo n.º 18
0
bool CMakeBlkFile::SelectEnt()
{
	ads_name ssname,ename;
	AcDbObjectId objId = AcDbObjectId::kNull;
	int nRet = acedSSGet(NULL, NULL, NULL, NULL, ssname);
	if (nRet != RTNORM)
	{
		return false;
	}
	long sslen;
	acedSSLength(ssname, &sslen);
	for (int i=0; i<sslen; i++)
	{
		acedSSName(ssname, i, ename);
		acdbGetObjectId(objId, ename);
		m_objIdArrs.append(objId);
	}
	acedSSFree(ssname);
	return true;
}
Exemplo n.º 19
0
//assign the xrecord to the object
//the xrecord stores the value for the properties
//for now it looks like this:
//double,double,long
//
void assignData()
{
    if (!PropertyAdmin::isInitialized())
    {
        acutPrintf("\nThe dynamic properties failed to intialize. Command is disabled.");
        return;
    }
    ads_name ss;
    if (acedSSGet(NULL,NULL,NULL,NULL,ss)!=RTNORM)
        return;
    long len=0;
    acedSSLength(ss,&len);
    ads_name ent;
    AcDbObjectId id;
    for (long i=0;i<len;i++){
        if (acedSSName(ss,i,ent)==RTNORM)
            if (acdbGetObjectId(id,ent)==Acad::eOk)
                XRecordManager::createDefaultData(id);
    }
    ads_ssfree(ss);
}
Exemplo n.º 20
0
	static void shYDsysXDataDel()
	{
		ads_name ssName;
		if(RTNORM == acedSSGet(":S", NULL, NULL, NULL, ssName))
		{
			AcDbObjectId tempObjId;
			ads_name ssTemp;
			long nLen=0;
			if(RTNORM != acedSSLength(ssName,&nLen)) return;
			for(int j=0; j<nLen; j++)
			{
				if(RTNORM == acedSSName(ssName,j,ssTemp)) continue;
				if(Acad::eOk != acdbGetObjectId(tempObjId, ssTemp)) continue;
				AcDbEntity* pEnt = NULL;
				if(Acad::eOk == acdbOpenObject(pEnt,tempObjId,AcDb::kForWrite))
				{
					
					resbuf* pHead = pEnt->xData(NULL);
					if(pHead == NULL)
					{
						pEnt->close(); continue;
					}
					resbuf* pNext =pHead->rbnext;
					if(pNext == NULL)
					{
						acutRelRb(pHead); pEnt->close(); continue;
					}
					while(pNext != NULL)
					{
						acutRelRb(pHead);
						pHead = pNext;
						pNext = pNext->rbnext;
					}
					pEnt->setXData(NULL);
					pEnt->close();
				}
			}
			acedSSFree(ssName);
		}
	}
Exemplo n.º 21
0
int ads_gm_write() 
{
  ads_name selection;
  int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection);
  if (returnValue == RTCAN || returnValue != RTNORM) return 0;
  
  long num = 0;
  returnValue = acedSSLength(selection, &num);
  if (returnValue == RTCAN || returnValue != RTNORM) return 0;
  if (num == 0) return 0;
  
  CCadEntities entities;
  
  ads_name element;
  for (long i = 0; i < num; i++) {
    acedSSName(selection, i, element);
    
    AcDbObjectId idEntity;
    if (acdbGetObjectId(idEntity, element) != Acad::eOk) {
      acedSSFree(element);
      acedSSFree(selection);
      return 0;
    }
    
    acedSSFree(element);
    
    CCadEntity * cadEntity = CCadEntityFactory::GetCadEntity(idEntity);
    entities.push_back(cadEntity);
  }
  acedSSFree(selection);
  
  // Obtener el feature class en edición
  CFeatureClass * featureClass = 0;
  CFeatureWriter writer(featureClass);
  writer.Write(&entities);
  
  delete featureClass;
  
  return 1;
}
Exemplo n.º 22
0
int ads_gm_get_data() 
{
  ads_name selection;
  int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection);
  if (returnValue == RTCAN || returnValue != RTNORM) return 0;
  
  long num = 0;
  returnValue = acedSSLength(selection, &num);
  if (returnValue == RTCAN || returnValue != RTNORM) return 0;
  if (num != 1) {
    acedSSSetFirst(NULL, NULL);
    
    returnValue = acedSSGet(L"_:S", NULL, NULL, NULL, selection);
    if (returnValue == RTCAN || returnValue != RTNORM) return 0;
    
    if (acedSSSetFirst(selection, NULL) != RTNORM) {
      acedSSFree(selection);
      return 0;
    }
  }
  ads_name element;
  acedSSName(selection, 0, element);
  acedSSFree(selection);
  
  AcDbObjectId idEntity;
  if (acdbGetObjectId(idEntity, element) != Acad::eOk) {
    acedSSFree(element);
    return 0;
  }

  acedSSFree(element);
  
  CCadEntity * cadEntity = CCadEntityFactory::GetCadEntity(idEntity);
  acutPrintf((L"\n" + cadEntity->GetData().ToFormattedString() + L"\n").c_str());
  delete cadEntity;
  
  return 1;
}
Exemplo n.º 23
0
void
getExtDictOfObject(AcDbDictionary*& pExtDict)
{
    ads_name ename;
    ads_point pt;

    ADSOK(acedEntSel("Select employee:",ename,pt));
    //do a quick check
    //a more comprehensive check could include 
    //whether we already have the detail object on this candidate
    AcDbObjectId idO;
    ARXOK(acdbGetObjectId(idO,ename));
    AcDbObject* pO;
    ARXOK(actrTransactionManager->getObject(pO,idO,AcDb::kForRead));
    if (!pO->isKindOf(AcDbBlockReference::desc()))
        throw Acad::eNotThatKindOfClass;        
    if ((idO = pO->extensionDictionary())==AcDbObjectId::kNull)
        throw Acad::eKeyNotFound;
    //make sure that you open erased extension dictionaries
    ARXOK(actrTransactionManager->getObject((AcDbObject*&)pExtDict,idO,AcDb::kForWrite, Adesk::kTrue));
    if (pExtDict->isErased())
        ARXOK(pExtDict->erase(Adesk::kFalse));

}
Exemplo n.º 24
0
void CDlgReadInfo::OnBnClickedBtnSelect()
{
	//交互选择实体
	BeginEditorCommand();

	CString strCadName;
	CComboBox* pCmb = (CComboBox*)GetDlgItem(IDC_COMBO_CADLY);
	pCmb->GetLBText(pCmb->GetCurSel(),strCadName);

	
	ads_name ssName;
	struct resbuf *filter=NULL;
	if(strCadName.CompareNoCase("所有图层") != 0)
	{
		filter=acutNewRb(AcDb::kDxfLayerName);
		filter->restype=AcDb::kDxfLayerName;
		filter->resval.rstring = (char*) malloc((strCadName.GetLength()+1)*sizeof(char));
		strcpy(filter->resval.rstring,strCadName.GetBuffer(0));
		filter->rbnext=NULL;
	}
	
	if (acedSSGet(":S", NULL, NULL, filter, ssName) != RTNORM)
	{
		acutPrintf("\n选择实体有误!");
		acedSSFree(ssName); acutRelRb(filter);
		CompleteEditorCommand();
		return;
	}
	if(filter != NULL) acutRelRb(filter);

	AcDbObjectId tempObjId;
	ads_name ssTemp;
	long nNum = 0;
	int nPos = 0;
	acedSSLength(ssName,&nNum);
	CString strSdeName,strId,strRowId;

	m_wndTree.DeleteAllItems();

	// 清空属性列表
	ResetListItems();

	for(int i=0; i<nNum; i++)
	{
		acedSSName(ssName, i, ssTemp);
		if(Acad::eOk != acdbGetObjectId(tempObjId, ssTemp)) continue;
		strId.Format("%d",tempObjId.asOldId());
		CDistXData tempXData(tempObjId,"ROWID_OBJS");
		if(tempXData.Select("SDELYNAME",strSdeName)==FALSE) continue;
		if(tempXData.Select("OBJECTID",strRowId)==FALSE) continue;
		tempXData.Close();

		HTREEITEM hItem = m_wndTree.InsertItem(strId);

		AcDbEntity *pEnt = NULL;
		if (Acad::eOk != acdbOpenObject(pEnt, tempObjId, AcDb::kForRead))
		{
			return;
		}
		pEnt->close();

		ITEM_DATA xxItemData;
		xxItemData.strID = strId;
		xxItemData.strSdelayerName = strSdeName;
		xxItemData.strCadLayerName = pEnt->layer();
		xxItemData.strRowId = strRowId;

		mapItemData[strId] = xxItemData;

		nPos++;
	}
	
	acedSSFree(ssName);

	CompleteEditorCommand();

	if (m_wndTree.GetCount() <= 0)
	{
		return;
	}

	HTREEITEM hItem = m_wndTree.GetFirstVisibleItem();

	// 显示属性
	OnSelectChanged(hItem);
}
void asdktest1 () {
    //----- Select the entities
    ads_name ss, en ;
    if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM )
        return ;

    //----- Append entity IDs to the collector
    long n ;
    AcDbObjectId id ;
    AsdkHlrCollector collector ;
    collector.setDeleteState (true) ;
    acedSSLength (ss, &n) ;
    for ( int i =0 ; i < n ; i++ ) {
        acedSSName (ss, i, en) ;
        acdbGetObjectId (id, en) ;
        collector.addEntity (id) ;
    }
    acedSSFree (ss) ;

    //----- Get current viewport settings
    struct resbuf rb;
    acedGetVar(ACRX_T(/*NOXLATE*/"viewdir"), &rb);
    ads_point dirPt;
    acdbUcs2Wcs (rb.resval.rpoint, dirPt, Adesk::kTrue) ;
    acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb);
    ads_point tarPt;
    acdbUcs2Wcs (rb.resval.rpoint, tarPt, Adesk::kFalse) ;

    //----- Ask if non-visible edges should be created
    int hidLines =AfxMessageBox (ACRX_T("Would you like to see hidden lines?"), MB_YESNO) ;
    int honorInt =AfxMessageBox (ACRX_T("Would you like to honor internal visibility of polyface meshes or ACIS objects?"), MB_YESNO) ;
    int meshSils =AfxMessageBox (ACRX_T("Would you like to calculate silhouettes of polyface meshes?"), MB_YESNO) ;
    int unit =AfxMessageBox (ACRX_T("Would you like to unit solid before processing?"), MB_YESNO) ;

    //----- Process hidden line removal
    AsdkHlrEngine hlr (
        asPnt3d (tarPt), asVec3d (dirPt),
        kEntity | kBlock | kSubentity | kProgress
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlr.setAcisConversionProgressCallBack (progress1) ;
    hlr.setAhlProgressCallBack (progress2) ;
    hlr.setAcadConversionProgressCallBack (progress3) ;

    acedSetStatusBarProgressMeter (ACRX_T("HLR running: "), 0, 300) ;
    hlr.run (collector) ;
    acedRestoreStatusBar () ;

    //----- Assign color to the resulting entities
    //----- red for visible edges
    //----- blue for non-visible edges
    //----- yellow for internal edges
    n =collector.mOutputData.logicalLength () ;
    for (int i =0 ; i < n ; i++ ) {
        AsdkHlrData *p =collector.mOutputData [i] ;

        AcDbEntity *pEnt =p->getResultEntity () ;
        AsdkHlrData::Visibility vis =p->getVisibility () ;
        if ( vis == AsdkHlrData::kVisible ) {
            pEnt->setColorIndex (1) ; //----- Read
        } else if ( vis == AsdkHlrData::kInternallyHidden ) {
            if ( p->getHlrVisibility () == AsdkHlrData::kVisible )
                pEnt->setColorIndex (2) ; //----- Yellow
            else
                pEnt->setColorIndex (3) ; //----- Green
        } else {
            pEnt->setColorIndex (5) ; //----- Blue
        }

        if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) {
            acutPrintf (_T("Failed to add entity to current space.\n")) ;
            break ;
        }
        if ( acdbOpenAcDbEntity (pEnt, id, AcDb::kForRead) != Acad::eOk ) {
            acutPrintf (_T("Failed to open last added outputed curve.\n")) ;
            break ;
        }

        //----- Entity originator path for block reference entities
        AcDbObjectIdArray ids =p->getObjectIds () ;
        if ( ids.logicalLength () > 0 ) {
            acutPrintf (ACRX_T("\n%lx, "), pEnt->objectId ().asOldId ()) ;
            if ( p->getSubentId ().type () != AcDb::kNullSubentType )
                acutPrintf (ACRX_T("[%ld, %ld], "), p->getSubentId ().type (), p->getSubentId ().index ()) ;
            for ( int j =0 ; j < ids.logicalLength () ; j++ )
                acutPrintf (ACRX_T("%lx, "), ids.at (j).asOldId ()) ;
            AcDbObjectId id =ids.last () ;
            if ( !id.isNull () ) {
                AcDbEntity *ent =NULL ;
                acdbOpenAcDbEntity (ent, id, AcDb::kForRead) ;
                id =ent->linetypeId () ;
                ent->close () ;
                if ( pEnt->upgradeOpen () == Acad::eOk )
                pEnt->setLinetype (id) ;
            }
        }

        pEnt->close () ;
    }
}
Exemplo n.º 26
0
void ModifyEntityLayer()
{
	int nRet = 0;
	ads_name entName;
	ads_point ptPick;
	nRet = acedEntSel(_T("\nSelect an entity to change it's layer:"), entName, ptPick);
	if (nRet != RTNORM)
	{
		acutPrintf(_T("\nFailed to select!"));
		return;
	}

	Acad::ErrorStatus es;
	AcDbObjectId objId;
	AcDbEntity* pEnt = NULL;
	acdbGetObjectId(objId, entName);
	es = acdbOpenAcDbEntity(pEnt, objId, AcDb::kForWrite);
	if (es != Acad::eOk)
	{
		acutPrintf(_T("\nFailed to open entity!"));
		return;
	}

	ACHAR szNewName[255];
	_tcscpy(szNewName, _T("NewLayer"));
	bool bHasDone = false;

	AcDbDatabase* pCurDb = acdbHostApplicationServices()->workingDatabase();
	if (pCurDb == NULL)
	{
		acutPrintf(_T("\nError:Current database is NULL!"));
		return;
	}

	AcDbObjectId layerId;
	AcDbLayerTable* pLayerTbl = NULL;
	es = pCurDb->getLayerTable(pLayerTbl, AcDb::kForRead);
	if (es == Acad::eOk)
	{
		if (pLayerTbl->has(szNewName))
		{
			es = pLayerTbl->getAt(szNewName, layerId);
			if (es == Acad::eOk)
			{
				es = pEnt->setLayer(layerId);
				if (es == Acad::eOk)
				{
					bHasDone = true;
				}
			}
		}

		pLayerTbl->close();
	}

	pEnt->close();

	if (bHasDone)
	{
		acutPrintf(_T("\nThe layer of entity has modified to layer:\"%s\""), szNewName);
	}
	else
	{
		acutPrintf(_T("\nFailed to modify the layer of entity to layer:\"%s\""), szNewName);
	}

}
Exemplo n.º 27
0
void 
hilitPoly()
{
	Adesk::Boolean interrupted = Adesk::kFalse;
    ads_printf("\nSelect a poly");

    AsdkPoly    *poly = NULL;
    AcDbEntity  *ent = NULL;
    AcDbObjectId polyId;
    ads_name     ename, sset;

    for (;;) {

        switch (ads_ssget(NULL, NULL, NULL, NULL, sset)) {

        case RTNORM:

        // Get the poly from the selection set and do some subentity
        // highlighting testing.
        //
        // This code assumes that the user selected only one item.

        {
            struct resbuf *rb;
            if (ads_ssnamex(&rb, sset, 0) != RTNORM) {
                ads_ssfree(sset);
                return;
            }
            int            sel_method;
            ads_name       subname;
            short          marker;
            AcGePoint3d    pickpnt;
            AcGeVector3d   pickvec;

            if (!extractEntityInfo(rb,
                              sel_method,
                              ename,
                              subname,
                              marker,
                              pickpnt,
                              pickvec)) {
                ads_ssfree(sset);
                return;
            }

            AOK(acdbGetObjectId(polyId, ename));

            AOK(acdbOpenAcDbEntity(ent, polyId, AcDb::kForRead));
            assert(ent != NULL);

            poly = AsdkPoly::cast(ent);
            if (poly == NULL) {
                ads_printf("\nNot a polygon.");
                AOK(ent->close());
                ads_ssfree(sset);
                continue;
            }

            // Get the subentity and highlight it.

            int                  numPaths;
            AcDbFullSubentPath*  subentPaths;
            AcGeMatrix3d         xform;
            poly->getSubentPathsAtGsMarker( AcDb::kEdgeSubentType,
                                            marker,
                                            pickpnt,
                                            xform,
                                            numPaths,
                                            subentPaths);
            if(numPaths == 1)
            {
                // Highlight and unhighlight the subentity.
                //
                ads_printf("\nHighlighting the subentity");
                poly->highlight(subentPaths[0]);
                pressEnterToContinue();
                poly->unhighlight(subentPaths[0]);
            }
            else
            {
                // No path, user selected a section without a marker,
                // the text label for example
                //
                ads_printf("\nNo subentity to highlight");
            }

            // Highlight and unhighlight the whole entity.
            //
            ads_printf("\nHighlighting the whole entity");
            poly->highlight();
            pressEnterToContinue();
            poly->unhighlight();

            delete []subentPaths;
            ads_ssfree(sset);
        }
        break;

        case RTNONE:
        case RTCAN:
            return;
        default:
            continue;
        }
        ads_ssfree(sset);
        break;
    }
    AOK(ent->close());
    return;
}
Exemplo n.º 28
0
void 
hilitInsert()
{
	Adesk::Boolean interrupted = Adesk::kFalse;
    ads_printf("\nSelect an insert");

    Acad::ErrorStatus es = Acad::eOk;
    AcDbEntity  *ent = NULL;
    AcDbEntity  *ent2 = NULL;
    AcDbBlockReference *blRef = NULL;
    AcDbObjectId objectId, blRefId;
    ads_name     ename, sset;

    for (;;) {
        switch (ads_ssget(NULL, NULL, NULL, NULL, sset)) {
        case RTNORM:
        {
            struct resbuf *rb;
            if (ads_ssnamex(&rb, sset, 0) != RTNORM) {
                ads_printf("\nads_ssnamex failed");
                ads_ssfree(sset);
                return;
            }

            int            sel_method;
            ads_name       subname;
            short          marker;
            AcGePoint3d    pickpnt;
            AcGeVector3d   pickvec;

            if (!extractEntityInfo(rb,
                              sel_method,
                              ename,
                              subname,
                              marker,
                              pickpnt,
                              pickvec)) {
                ads_printf("\nextractEntityInfo failed");
                ads_ssfree(sset);
                return;
            }

            ads_ssfree(sset);

            assert(marker != 0);
            if (marker == 0) {
                ads_printf("\nmarker == 0");
                return;
            }

            // Get the insert first.
            //
            AOK(acdbGetObjectId(blRefId, ename));
            AOK(acdbOpenAcDbEntity(ent, blRefId,
                AcDb::kForRead));
            assert(ent != NULL);

            blRef = AcDbBlockReference::cast(ent);
            if (blRef == NULL) {
                ads_printf("\nNot an insert.");
                AOK(ent->close());
                continue;
            }

            struct resbuf *insStack;
            ads_point pickpoint;
            ads_matrix adsmat;

            pickpoint[0] = pickpnt[0];
            pickpoint[1] = pickpnt[1];
            pickpoint[2] = pickpnt[2];
           
            // Now get details on the entity that was
            // selected.
            // 
            if (ads_nentselp(NULL, ename, pickpoint, TRUE,
                adsmat, &insStack) != RTNORM)
            {
                ads_printf("\nFailure in ads_nentselp");
                return;
            }
            assert(insStack != NULL);

            AOK(acdbGetObjectId(objectId, ename));
            AOK(acdbOpenAcDbEntity(ent2, objectId,
                AcDb::kForRead));
            assert(ent2 != NULL);

            // Make an array of AcDbObjectIds from the
            // insertStack.  Don't use the "smart array" 
            // AcDbObjectIdArray class, because the 
            // getSubentPathsAtGsMarker() function expects argument
            // eight to be of type AcDbObjectId*. Just 
            // make room for approximately 100 IDs in the array.
            //
            AcDbObjectId *idArray = new AcDbObjectId[100];
            int count = 0;
            struct resbuf *rbIter = insStack; 
            AcDbObjectId objId;
            acdbGetObjectId(objId, ename);
            idArray[count++] = objId;

            while (rbIter != NULL) {
                ename[0] = rbIter->resval.rlname[0];
                ename[1] = rbIter->resval.rlname[1];
                acdbGetObjectId(objId, ename);
                idArray[count++] = objId;

                rbIter = rbIter->rbnext;
            }
            count--;

            ads_relrb(insStack);

            // First, we'll highlight an edge.
            //
            int                  numPaths;
            AcDbFullSubentPath  *subentPaths;
            AcGeMatrix3d         xform;
            es = blRef->getSubentPathsAtGsMarker(
                AcDb::kEdgeSubentType,
                marker,
                pickpnt,
                xform,
                numPaths,
                subentPaths,
                count,
                idArray);

            assert(numPaths == 1);

            // Highlight and unhighlight the selected edge.
            //
            ads_printf("\nHighlighting the first edge.");
            es = blRef->highlight(subentPaths[0]);
            pressEnterToContinue();
            es = blRef->unhighlight(subentPaths[0]);

            // If this is a solid, it will have faces.
            // In this case, let's highlight them.
            //
            if(ent2->isKindOf(AcDb3dSolid::desc())) {
                es = blRef->getSubentPathsAtGsMarker(
                    AcDb::kFaceSubentType,
                    marker,
                    pickpnt,
                    xform,
                    numPaths,
                    subentPaths,
                    count,
                    idArray);
                assert(numPaths == 2);

                // Highlight and unhighlight the selected
                // faces.
                //
                ads_printf("\nHighlighting the first"
                    " face.");
                es = blRef->highlight(subentPaths[0]);
                pressEnterToContinue();
                es = blRef->unhighlight(subentPaths[0]);

                ads_printf("\nHighlighting the next face.");
                es = blRef->highlight(subentPaths[1]);
                pressEnterToContinue();
                es = blRef->unhighlight(subentPaths[1]);
            }
            delete []subentPaths;

            // Now, let's highlight the whole entity.
            //
            ads_printf("\nHighlighting the entire entity");

            AcDbFullSubentPath subPath;

            for (int i = count; i >= 0; i--) {
                subPath.objectIds().append(idArray[i]);
            }
            es = blRef->highlight(subPath);
            pressEnterToContinue();
            es = blRef->unhighlight(subPath);

            // Finally, let's highlight each enclosing
            // insert.
            //
            for (i = count -1; i >= 0; i --) {
                subPath.objectIds().removeAt(
                    subPath.objectIds().length() - 1);
                ads_printf("\nHighlighting insert layer %d",
                    i + 1);
                blRef->highlight(subPath);
                pressEnterToContinue();
                es = blRef->unhighlight(subPath);
            }

        } // case RTNORM
            break;
        case RTNONE:
        case RTCAN:
            return;
        default:
            continue;
        } // switch
        break;
    } //for (;;)

    AOK(ent->close());
    AOK(ent2->close());
    return;
}
Exemplo n.º 29
0
void 
hilitSolid()
{
	Adesk::Boolean interrupted = Adesk::kFalse;
    ads_printf("\nSelect a solid");

    Acad::ErrorStatus es = Acad::eOk;

    AcDb3dSolid *solid = NULL;
    AcDbEntity  *ent = NULL;
    AcDbObjectId solidId;
    ads_name     ename, sset;

    for (;;) {

        switch (ads_ssget(NULL, NULL, NULL, NULL, sset)) {

        case RTNORM:
        {
            struct resbuf *rb;
            if (ads_ssnamex(&rb, sset, 0) != RTNORM) {
                ads_ssfree(sset);
                return;
            }
            int            sel_method;
            ads_name       subname;
            short          marker;
            AcGePoint3d    pickpnt;
            AcGeVector3d   pickvec;

            if (!extractEntityInfo(rb,
                              sel_method,
                              ename,
                              subname,
                              marker,
                              pickpnt,
                              pickvec)) {
                ads_ssfree(sset);
                return;
            }

            AOK(acdbGetObjectId(solidId, ename));

            AOK(acdbOpenAcDbEntity(ent, solidId, AcDb::kForRead));
            assert(ent != NULL);

            solid = AcDb3dSolid::cast(ent);
            if (solid == NULL) {
                ads_printf("\nNot a solid.");
                AOK(ent->close());
                ads_ssfree(sset);
                continue;
            }

            int                  numPaths;
            AcDbFullSubentPath*  subentPaths;
            AcGeMatrix3d         xform;
            es = solid->getSubentPathsAtGsMarker( AcDb::kEdgeSubentType,
                                            marker,
                                            pickpnt,
                                            xform,
                                            numPaths,
                                            subentPaths);
            // For objects with no edges (such as a sphere) the code to
            // highlight an edge is meaningless and must be skipped.
            //
            if (numPaths > 0) {

                // Highlight and unhighlight the selected edge of the solid.
                //
                ads_printf("\nHighlighting the selected edge.");
                es = solid->highlight(subentPaths[0]);
                pressEnterToContinue();
                es = solid->unhighlight(subentPaths[0]);
            } else
                ads_printf("\nNo edges to highlight.");
            delete []subentPaths;

            // Highlight and unhighlight the faces corresponding to the
            // first edge of the solid.
            //
            es = solid->getSubentPathsAtGsMarker( AcDb::kFaceSubentType,
                                            marker,
                                            pickpnt,
                                            xform,
                                            numPaths,
                                            subentPaths);
            for (int i = 0; i < numPaths; i++) {
                ads_printf("\nHighlighting face %d of %d", i + 1, numPaths);
                es = solid->highlight(subentPaths[i]);
                pressEnterToContinue();
                es = solid->unhighlight(subentPaths[i]);
            }
            delete []subentPaths;
            ads_ssfree(sset);

            // Highlight the entire solid, then unhighlight it.
            //
            ads_printf("\nHighlighting the entire solid");
            es = solid->highlight();
            pressEnterToContinue();
            es = solid->unhighlight();
        }
        break;
        case RTNONE:
        case RTCAN:
            return;
        default:
            continue;
        }
        ads_ssfree(sset);
        break;
    }

    AOK(ent->close());
    return;
}
Exemplo n.º 30
-7
// This function has the user select an entity and then
// calls the reflectedEnergy() function in the protocol
// extension class attached to that entity's class.
// 
void
energy()
{
    AcDbEntity *pEnt;
    AcDbObjectId pEntId;
    ads_name en;
    ads_point pt;

    if (acedEntSel("\nSelect an Entity:  ", en, pt)
        != RTNORM)
    {
        acutPrintf("Nothing Selected\n");
        return;
    }
    acdbGetObjectId(pEntId, en);
    acdbOpenObject(pEnt, pEntId, AcDb::kForRead);

    // call the protocol extension class's method
    //
    double eTemp = ACRX_X_CALL(pEnt,
        AsdkEntTemperature)->reflectedEnergy(pEnt);

    acutPrintf("\nEnergy == %f\n", eTemp);
    pEnt->close();
}