示例#1
1
// 查找连接点junctionPt关联的分支图元(包含隐形的图元)
static void FindLinesByPoint( const AcGePoint3d& junctionPt, AcDbObjectIdArray& objIds )
{
    AcDbBlockTable* pBlkTbl;
    acdbHostApplicationServices()->workingDatabase()->getSymbolTable( pBlkTbl, AcDb::kForRead );

    AcDbBlockTableRecord* pBlkTblRcd;
    pBlkTbl->getAt( ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead );
    pBlkTbl->close();

    AcDbBlockTableRecordIterator* pBlkTblRcdItr;
    pBlkTblRcd->newIterator( pBlkTblRcdItr );

    for ( pBlkTblRcdItr->start(); !pBlkTblRcdItr->done(); pBlkTblRcdItr->step() )
    {
        // 不采用transaction的方法查找LinkedGE,
        // 等价于排除当前正在以write状态编辑的LinkedGE
        // 重要(***)
        AcDbEntity* pEnt = 0;
        if( Acad::eOk != pBlkTblRcdItr->getEntity( pEnt, AcDb::kForRead ) ) continue;

        LinkedGE* pEdge = LinkedGE::cast( pEnt );
        if( pEdge != 0 )
        {
            AcGePoint3d startPt, endPt;
            pEdge->getSEPoint( startPt, endPt );
            if( startPt == junctionPt || endPt == junctionPt )
            {
                objIds.append( pEdge->objectId() );
            }
        }
        pEnt->close();
    }
    delete pBlkTblRcdItr;
    pBlkTblRcd->close();
}
示例#2
0
void readDatabase()
{
	// Use kFalse to create an empty database.
    AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);

    // Use readDwgFile to load the DWG file.
	acutPrintf(_T("\nRead file \"d:\\temp\\testfile.dwg\"."));
    if(Acad::eOk != pDb->readDwgFile(_T("d:\\temp\\testfile.dwg")))
        return;

    // Get the BlockTable.
    AcDbBlockTable *pBTable = NULL;
    pDb->getSymbolTable(pBTable, AcDb::kForRead);

	// Get the ModelSpace.
    AcDbBlockTableRecord *pRecord = NULL;
    pBTable->getAt(ACDB_MODEL_SPACE, pRecord, AcDb::kForRead);
    pBTable->close();

	// Get new iterator.
    AcDbBlockTableRecordIterator *pItr = NULL;
    pRecord->newIterator(pItr);

    AcDbEntity *pEnt = NULL;
    for (pItr->start(); !pItr->done(); pItr->step())
    {
        pItr->getEntity(pEnt, AcDb::kForRead);
        acutPrintf(_T("\nclassname: %s"), (pEnt->isA())->name());
        pEnt->close();
    }
    pRecord->close();
    delete pItr;
    delete pDb;
}
示例#3
0
//0,不显示属性,1,显示属性,2,显示属性默认值
void CZhfPalette::FilterDb(AcDbDatabase* pDb, int iFilterMode)
{
	if (iFilterMode==1)
	{
		return ;
	}
	Acad::ErrorStatus es ;
	AcDbBlockTable* pBT = NULL ;
	pDb->getBlockTable(pBT, AcDb::kForRead);
	AcDbBlockTableRecord* pBTR = NULL;
	es = pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite);
	pBT->close();

	AcDbBlockTableRecordIterator* pIT;
	es = pBTR->newIterator(pIT) ;
	for (; !pIT->done(); pIT->step()) 
	{
		AcDbEntity* pEnt = NULL ;
		if (Acad::eOk==pIT->getEntity(pEnt, AcDb::kForWrite))
		{
			if (pEnt->isKindOf(AcDbAttributeDefinition::desc()))
			{
				AcDbAttributeDefinition *pAttDef = AcDbAttributeDefinition::cast(pEnt);

				if (iFilterMode==0)
				{
					pEnt->erase() ;
				}
				else if (iFilterMode>1)
				{
					if (pAttDef != NULL && !pAttDef->isConstant())
					{
						// We have a non-constant attribute definition,
						// so build an attribute entity.
						CString strShowVal ;

						if (iFilterMode==2)
						{
							strShowVal = pAttDef->textString() ;
						}
						else if (iFilterMode==3)
						{
							strShowVal = pAttDef->prompt() ; //显示中文为乱码
						}
						pAttDef->setTag(strShowVal) ;
					}
				}
			}
			pEnt->close() ;
		}
	}

	delete pIT;
	pBTR->close();
}
Acad::ErrorStatus
ArxDbgUtils::defineNewBlock(LPCTSTR blkName, AcDbBlockTableRecord*& newBlkRec,
                            AcDbObjectId& newBlkRecId, AcDbDatabase* db)
{
	ASSERT(db != NULL);

    AcDbBlockTable* blkTbl;
	Acad::ErrorStatus es = db->getSymbolTable(blkTbl, AcDb::kForWrite);
    if (es != Acad::eOk)
        return es;

        // if this block already exists, erase its contents first
    if (blkTbl->getAt(blkName, newBlkRec, AcDb::kForWrite) == Acad::eOk) {
        newBlkRecId = newBlkRec->objectId();
        AcDbBlockTableRecordIterator* iter;
        es = newBlkRec->newIterator(iter);
        if (es != Acad::eOk) {
            ArxDbgUtils::rxErrorMsg(es);
            newBlkRec->close();
        }
        else {
            AcDbEntity* ent;
            for (; !iter->done(); iter->step()) {
                if (iter->getEntity(ent, AcDb::kForWrite) == Acad::eOk) {
                    ent->erase();
                    ent->close();
                }
            }
            delete iter;
        }
    }
    else {    // create a new block table record and add it to the block table
        newBlkRec = new AcDbBlockTableRecord;
        newBlkRec->setPathName(AcadString::nullStr);    // constructor doesn't do it properly

        es = newBlkRec->setName(blkName);
        if (es == Acad::eOk)
            es = blkTbl->add(newBlkRecId, newBlkRec);

        if (es != Acad::eOk) {
            ArxDbgUtils::rxErrorMsg(es);
            delete newBlkRec;
        }
    }

    blkTbl->close();    // doesn't need to be open anymore
    return es;
}
示例#5
0
BOOL ElevationObjectPick::PickElevationObjects( OUT vector<AcDbObjectId>& vIsoHeight, OUT vector<AcDbObjectId>& vElePoint ) const
{
	AcDbObjectId IdSpace = acdbCurDwg()->currentSpaceId();

	AcDbBlockTableRecord* pBtr = NULL;
	acdbOpenObject( pBtr, IdSpace, AcDb::kForRead );
	if( pBtr == NULL ) return FALSE;
	pBtr->close();

	AcDbBlockTableRecordIterator* pIte = NULL;
	pBtr->newIterator( pIte );
	if( pIte == NULL ) return FALSE;

	//遍历当前所有对象
	for ( pIte->start(); !pIte->done(); pIte->step() )
	{
		AcDbObjectId Id;
		pIte->getEntityId( Id );
	}


	return FALSE;
}
void

readDwg()

{

    // Set constructor parameter to kFalse so that the

    // database will be constructed empty.  This way only

    // what is read in will be in the database.

    //

    AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);



    // The AcDbDatabase::readDwgFile() function

    // automatically appends a DWG extension if it is not

    // specified in the filename parameter.

    //

    if(Acad::eOk != pDb->readDwgFile(_T("./test1.dwg")))

        return;



    // Open the model space block table record.

    //

    AcDbBlockTable *pBlkTbl;

    pDb->getSymbolTable(pBlkTbl, AcDb::kForRead);



    AcDbBlockTableRecord *pBlkTblRcd;

    pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,

        AcDb::kForRead);

    pBlkTbl->close();



    AcDbBlockTableRecordIterator *pBlkTblRcdItr;

    pBlkTblRcd->newIterator(pBlkTblRcdItr);



    AcDbEntity *pEnt;

    for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done();

        pBlkTblRcdItr->step())

    {

        pBlkTblRcdItr->getEntity(pEnt,

            AcDb::kForRead);

        acutPrintf(_T("classname: %s\n"),

            (pEnt->isA())->name());

        pEnt->close();

    }

    pBlkTblRcd->close();

    delete pBlkTblRcdItr;

    delete pDb;

}
示例#7
0
void setInsertLayer()
{
	// Iterate through Model Space to find every instance of the EMPLOYEE block
	// When found, change its layer to "USER"
	
	Acad::ErrorStatus es;
	AcDbBlockTable* pBlockTbl;
	AcDbBlockTableRecord* pMS;

	if ((es = acdbCurDwg()->getBlockTable(pBlockTbl, AcDb::kForRead)) == Acad::eOk)
	{
	//Get the Model Space record and open it for read.
        if ((es = pBlockTbl->getAt(ACDB_MODEL_SPACE, pMS, AcDb::kForWrite)) != Acad::eOk)
		{
			acrx_abort("\nCouldn't get Model Space! Drawing corrupt.\n");
		}
	    pBlockTbl->close();
    }

	// declare the appropriate iterator
	// get the iterator from the object to be iterated through

	// in this case, the Model Space block table record will provide the iterator
	// start at the beginning of the record and skip deleted entities

	AcDbBlockTableRecordIterator* pBtrIter;
	if ((es = pMS->newIterator(pBtrIter)) != Acad::eOk)
	{
		acutPrintf("\nCouldn't create Model Space iterator: %s", acadErrorStatusText(es));
		return;
	}

	char* blockName;  
	AcDbEntity* pEnt;
	AcDbBlockTableRecord* pCurEntBlock;
	AcDbObjectId blockId;

	for (pBtrIter->start(); !pBtrIter->done(); pBtrIter->step())
	{
		// first open each entity for read, just to check its class
		// if it's what we want, we can upgrade open later
		// Don't bother with erased entities
		if ((es = pBtrIter->getEntity(pEnt, AcDb::kForRead)) != Acad::eOk)
		{
			acutPrintf("\nCouldn't open entity:  %s", acadErrorStatusText(es));
			continue;
		}

		// check isf the entity is an instance of type AcDbBlockReference
		if (pEnt->isA() != AcDbBlockReference::desc())
		{
			pEnt->close();
			continue;
		}
		
		// get the insert's block table record and compare its name
		// to make sure we've got the right block.  If so, set the layer
		blockId = (AcDbBlockReference::cast(pEnt))->blockTableRecord();
		if (acdbOpenObject((AcDbObject*&)pCurEntBlock, blockId, AcDb::kForRead) == Acad::eOk)
		{
			pCurEntBlock->getName(blockName);
			if (strcmp(blockName, "EMPLOYEE") == 0)
			{
				if (pEnt->upgradeOpen() == Acad::eOk)
					// setLayer also has an overload that takes a layer ID
					// but to avoid global variables we specify the layer name
					pEnt->setLayer("USER");
			}
			pCurEntBlock->close();
			acdbFree ( blockName );
		}
		pEnt->close();
	}

	// delete, rather than close, the iterator object
	delete pBtrIter;
    pMS->close();
	return;

}
示例#8
0
Acad::ErrorStatus CGraphListCtrl::GetBlock1( LPCTSTR szBlockName, AcDbBlockTableRecord*& pBlockRecord )
{
	Acad::ErrorStatus es;
	pBlockRecord = NULL;

	AcDbBlockTableRecordPointer pSrcRc(szBlockName, m_pCurDb, AcDb::kForRead);
	es = pSrcRc.openStatus();
	if (Acad::eOk != es)
		return es;

	AcDbBlockTablePointer pDestTbl(m_DefDb, AcDb::kForRead);
	es = pDestTbl.openStatus();
	if (Acad::eOk != es)
		return es;

	AcDbBlockTableRecordPointer pDestRc;
	pDestRc.create();
	es = pDestRc.openStatus();
	if (Acad::eOk != es)
		return es;

	es = pDestRc->setName(szBlockName);
	if (Acad::eOk != es)
		return es;

	pDestTbl->upgradeOpen();
	es = pDestTbl->add(pDestRc.object());
	pDestTbl->downgradeOpen();
	if (Acad::eOk != es)
		return es;

	AcDbBlockTableRecordIterator* pIter = NULL;
	es = pSrcRc->newIterator(pIter);
	if (Acad::eOk != es)
		return es;

	AcDbObjectId objId;
	AcDbIdMapping idMap;
	AcDbObject* pObject = NULL;
	for (pIter->start(); !pIter->done(); pIter->step())
	{
		es = pIter->getEntityId(objId);
		if (Acad::eOk != es)
			continue;

		AcDbEntityPointer pEnt(objId, AcDb::kForRead);
		es = pEnt.openStatus();
		if (Acad::eOk != es)
			continue;

		if (pEnt->isKindOf(AcDbText::desc()))
		{
			continue;
		}

		es = pEnt->deepClone(pDestRc.object(), pObject, idMap, true);
		if (Acad::eOk != es)
			continue;

		pObject->close();
	}

	pBlockRecord = pDestRc.object();
	return es;
}
示例#9
0
Acad::ErrorStatus CZhfPalette::Wblock(AcDbDatabase*& pDbFrom, AcDbDatabase*& pDbTo, /*const AcGePoint3d& pt_3d_base,*/ const AcGeMatrix3d & xform)
{
	Acad::ErrorStatus es ;

	AcDbObjectIdArray objIdsOut;

	AcDbBlockTable* pBT = NULL ;
	pDbFrom->getBlockTable(pBT, AcDb::kForRead);
	AcDbBlockTableRecord* pBTR = NULL;
	es = pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForRead);
	pBT->close();

	AcDbBlockTableRecordIterator* pIT;
	es = pBTR->newIterator(pIT) ;
	for (; !pIT->done(); pIT->step()) 
	{ 
		AcDbEntity* pEnt = NULL ;
		if (Acad::eOk==pIT->getEntity(pEnt, AcDb::kForRead))
		{
// 			if (!pEnt->isKindOf(AcDbAttributeDefinition::desc()))
// 			{
				AcDbObjectId objId;
				if (Acad::eOk == pIT->getEntityId(objId))
				{
					objIdsOut.append(objId);
				}
// 			}
			pEnt->close() ;
		}
	}

	delete pIT;
	pBTR->close();

	if (!objIdsOut.isEmpty()) 
	{
		for (int i=0; i<objIdsOut.length(); i++)
		{
			AcDbObjectId objId = objIdsOut.at(i);
			AcDbEntity *pEnt = NULL ;
			if(Acad::eOk==acdbOpenAcDbEntity(pEnt,objId, AcDb::kForRead))
			{
				AcDbObjectId objIdDic ;
				if ((objIdDic = pEnt->extensionDictionary())!= AcDbObjectId::kNull)
				{
					AcDbDictionary *pDict = NULL;				
					if (Acad::eOk==acdbOpenObject(pDict, objIdDic, AcDb::kForWrite))
					{
						pDict->setTreatElementsAsHard(Adesk::kTrue);
						pDict->close();
					}
				}
				pEnt->close() ;
			}
		}

		AcDbDatabase *pTempDb ;
		es = pDbFrom->wblock( pTempDb, objIdsOut, AcGePoint3d::kOrigin ) ;
		if (Acad::eOk != es )
		{
			acedAlert( _T("wblock failed!") );
			return es ;
		}
		es = pDbTo->insert( xform, pTempDb ) ;
		if (Acad::eOk != es)
			acedAlert( _T("insert failed!" ));
		if (pTempDb)
		{
			delete pTempDb;
			pTempDb = NULL ;
		}
	}
	else
	{
		acutPrintf(_T("\nNo entities found in model space of DWG"));
	}

	return es ;
}
示例#10
0
bool Additional_Class::Get_LayerLW( CString LayerName, double &Length, double &Width )
{
	AcDbLayerTable *pLayerTbl = NULL;
	acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl,AcDb::kForRead);
	if (!pLayerTbl->has(LayerName))
	{
		//acutPrintf("\n木有%s层!", LayerName);
		//SetError("THERE ISN`T"+LayerName+"LATYER!",  "Get_LayerLW");
		pLayerTbl->close();
		return false;
	}
	AcDbObjectId layerId;
	pLayerTbl->getAt(LayerName, layerId);
	pLayerTbl->close();
	AcDbBlockTable *pBlkTbl = NULL;
	////获得当前数据库块表
	acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
	////获得模型空间块表记录
	AcDbBlockTableRecord *pBlkTblRcd = NULL;
	pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead);
	pBlkTbl->close();

	////创建块表记录遍历器

	AcDbBlockTableRecordIterator *pltr;
	pBlkTblRcd->newIterator(pltr);

	AcDbEntity *pEnt;
	//AcDbEntityPointer pEnt_Ptr;
	////AcDbObjectPointer<AcDbPolyline> pPolyLine_Ptr;
	AcDbPolyline *pPolyLine = NULL;
	AcDbObjectIdArray PolyLineID_List;
	for (pltr->start(); !pltr->done(); pltr->step())
	{
		pltr->getEntity(pEnt, AcDb::kForRead);
	//	//pEnt_Ptr.acquire(pEnt);
		if (pEnt->layerId()==layerId)
		{
			if (pEnt->isKindOf(AcDbPolyline::desc()))
			{
				pPolyLine = AcDbPolyline::cast(pEnt);
				if (pPolyLine != NULL)
				{
					if (PolyLineIfRectangle(pPolyLine)==true)
					{
						PolyLineID_List.append(pPolyLine->objectId());
					}
				}
			}
		}
	}

	if (PolyLineID_List.length() >1)
	{
		acutPrintf(_T("Bom Error 1002\n"));// 有很多矩形
		delete pltr;
		pEnt->close();
		pPolyLine->close();
		pBlkTblRcd->close();
		return false;
	}
	////pPolyLine.open(PolyLineID_List[0], AcDb::kForRead);
	acdbOpenAcDbEntity(pEnt,PolyLineID_List[0], AcDb::kForRead);	//error!
	pPolyLine =  AcDbPolyline::cast(pEnt);
	Get_RectangleLW(pPolyLine, Length, Width);
	pBlkTblRcd->close();
	pPolyLine->close();
	pEnt->close();
	delete pltr;
	return true;
}
示例#11
0
bool Additional_Class::LaylerFilter( CString LaylerName, AcDbObjectIdArray &EntityID_Array, bool(*Filter)(AcDbEntity*, AcDbObjectId&) )
{
	AcDbLayerTable *pLayerTbl;
	acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForWrite);
	if (false == (pLayerTbl->has(LaylerName)))
	{
		//acutPrintf("\n木有%s层!", LaylerName);
		//SetError("THERE ISTN`T"+LaylerName+"LAYER!", "LaylerFilter");
		pLayerTbl->close();
		return false;
	}
	AcDbObjectId layerId;
	pLayerTbl->getAt(LaylerName,layerId);

	AcDbBlockTable *pBlkTbl;
	//获得当前数据库块表
	acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite);
	
	//获得模型空间块表记录
	AcDbBlockTableRecord *pBlkTblRcd;
	pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);

	//创建块表记录遍历器
	AcDbBlockTableRecordIterator *pltr;
	pBlkTblRcd->newIterator(pltr);

	AcDbEntity *pEnt;
	AcDbObjectId temp_layerId;
	AcDbObjectId entityID;
	//pBlkTblRcd->close();
	//pBlkTbl->close();
	//pLayerTbl->close();
	for (pltr->start(); !pltr->done(); pltr->step())
	{
		if(Acad::eOk ==pltr->getEntity(pEnt, AcDb::kForRead, false))
		{
			//if (200>Check_Entity(pEnt)>=100)
			//{
			temp_layerId = pEnt->layerId();
			if (temp_layerId == layerId)		// 在当前图层中
			{
				entityID = pEnt->objectId();
				if (Filter(pEnt, entityID) == true)  // 符合过滤条件
				{
					EntityID_Array.append(entityID);
				}
			}
			//}
			pEnt->close();
		}
	}
	int Len = EntityID_Array.length();
	if (Len == 0)
	{
		pBlkTbl->close();
		pLayerTbl->close();
		pBlkTblRcd->close();
		return false;
	}
	pBlkTbl->close();
	pLayerTbl->close();
	pBlkTblRcd->close();
	return true;
}
void
refEditApiExample()
{

    AcDbObjectId transId;
    AcDbDatabase* pDb;
    char *fname;
    struct resbuf *rb;

    // Get a dwg file from the user.
    //
    rb = acutNewRb(RTSTR);
    int stat = acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb);
    
    if ((stat != RTNORM) || (rb == NULL)) {
        acutPrintf("\nYou must pick a drawing file.");
        return;
    }

    fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1);
    strcpy(fname, rb->resval.rstring);
    acutRelRb(rb);
    
    // Open the dwg file.
    //
    pDb = new AcDbDatabase(Adesk::kFalse);
    if (pDb->readDwgFile(fname) != Acad::eOk) {
        acutPrintf("\nSorry, that draing is probably already open.");
        return;
    }

    // Get the Block Table and then the model space record.
    //
    AcDbBlockTable *pBlockTable;
    pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
    AcDbBlockTableRecord *pOtherMsBtr;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb::kForRead);
    pBlockTable->close();

    // Create an iterator.
    //
    AcDbBlockTableRecordIterator *pIter;
    pOtherMsBtr->newIterator(pIter);

    // Set up an object ID array.
    //
    AcDbObjectIdArray objIdArray;

    // Iterate over the model space BTR. Look specifically 
    // for lines and append their object ID to the array.
    //
    for (pIter->start(); !pIter->done(); pIter->step()) {
        AcDbEntity *pEntity;
        pIter->getEntity(pEntity, AcDb::kForRead);

        // Look for only AcDbLine objects and add them to the 
        // object ID array.
        //
        if (pEntity->isKindOf(AcDbLine::desc())) {
            objIdArray.append(pEntity->objectId());
        }
        pEntity->close();
    }
    delete pIter;
    pOtherMsBtr->close();

    if (objIdArray.isEmpty()) {
        acad_free(fname);
        acutPrintf("\nYou must pick a drawing file that contains lines.");
        return;
    }

    // Now get the current database and the object ID for the
    // current database's model space BTR.
    //
    AcDbBlockTable *pThisBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pThisBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pThisMsBtr;
    pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr, AcDb::kForWrite);
    pThisBlockTable->close();
    
    AcDbObjectId id = pThisMsBtr->objectId();
    pThisMsBtr->close();


    // Create the long transaction. This will check all the entities 
    // out of the external database.
    //
    AcDbIdMapping errorMap;
    acapLongTransactionManagerPtr()->checkOut(transId, objIdArray, id, errorMap);

    // Now modify the color of these entities.
    //
    int colorIndex;
    acedGetInt("\nEnter color number to change entities to: ", &colorIndex);
    AcDbObject* pObj;
    if (acdbOpenObject(pObj, transId, AcDb::kForRead) == Acad::eOk) {

        // Get a pointer to the transaction.
        //
        AcDbLongTransaction* pLongTrans = AcDbLongTransaction::cast(pObj);
        if (pLongTrans != NULL) {

            // Get a work set iterator.
            //
            AcDbLongTransWorkSetIterator* pWorkSetIter;
            pLongTrans->newWorkSetIterator(pWorkSetIter);

            // Iterate over the entities in the work set and change the color.
            //
            for (pWorkSetIter->start(); !pWorkSetIter->done(); pWorkSetIter->step()) {
                AcDbEntity *pEntity;
                acdbOpenAcDbEntity(pEntity, pWorkSetIter->objectId(), AcDb::kForWrite);
                pEntity->setColorIndex(colorIndex);
                pEntity->close();
            }
            delete pWorkSetIter;
        }
        pObj->close();
    }

    // Pause to see the change.
    //
    char str[132];
    acedGetString(0, "\nSee the new colors. Press return to check the object into the original database", str);

    // Check the entities back in to the original database.
    //
    acapLongTransactionManagerPtr()->checkIn(transId, errorMap);

    // Save the original database, since we have made changes.
    //
    pDb->saveAs(fname);

    // Close/Delete the database
    //
    delete pDb;
    pDb = NULL;

    acad_free(fname);
}
示例#13
0
static void BlockToEntity( const AcDbObjectId& blkId, const AcGeMatrix3d& blkXform,
                           const AcStringArray& names, const AcStringArray& attValues,
                           AcGeVoidPointerArray& ents )
{
    // 将块定义分解成独立的图元
    // 将属性替换成多行文字
    AcTransaction* pTrans = actrTransactionManager->startTransaction();
    AcDbObject* pObj;
    if( Acad::eOk != pTrans->getObject( pObj, blkId, AcDb::kForRead ) )
    {
        actrTransactionManager->abortTransaction();
        return;
    }

    AcDbBlockTableRecord* pBTR = AcDbBlockTableRecord::cast( pObj );
    // BUG:不能调用hasAttributeDefinitions()方法
    // 调用之后,如果没有在块编辑器中对块进行修改,
    // 那么进行移动、夹点编辑等操作,没有动态显示效果
    //if(!pBTR->hasAttributeDefinitions())
    //{
    //	// 没有属性定义
    //	acutPrintf(_T("\n没有属性定义"));
    //	actrTransactionManager->abortTransaction();
    //	return;
    //}

    AcDbBlockTableRecordIterator* pIterator;
    if( Acad::eOk != pBTR->newIterator( pIterator ) )
    {
        actrTransactionManager->abortTransaction();
        return;
    }

    // 遍历块中的图元,查找AcDbAttributeDefinition
    for( pIterator->start( true ); !pIterator->done(); pIterator->step( true ) )
    {
        AcDbObjectId objId;
        if( Acad::eOk != pIterator->getEntityId( objId ) ) continue;
        if( Acad::eOk != pTrans->getObject( pObj, objId, AcDb::kForWrite ) ) continue;

        AcDbEntity* pEnt = AcDbEntity::cast( pObj );
        if( !pEnt->isKindOf( AcDbAttributeDefinition::desc() ) )
        {
            AcDbEntity* pClone = AcDbEntity::cast( pEnt->clone() );
            pClone->transformBy( blkXform );
            // 添加到实体集合
            ents.append( pClone );
        }
        else
        {
            AcDbAttributeDefinition* pAttDef = AcDbAttributeDefinition::cast( pEnt );
            pAttDef->convertIntoMTextAttributeDefinition( Adesk::kTrue );

            // 获取标签名称
            ACHAR* pTag = pAttDef->tag();
            int pos = names.find( pTag );
            if( pos != -1 )
            {
                // 获取多行文本对象
                AcDbMText* pMText = pAttDef->getMTextAttributeDefinition();
                pMText->transformBy( blkXform );
                pMText->setContents( attValues[pos].kACharPtr() );
                // 添加到实体集合
                ents.append( pMText );
            }
            acutDelString( pTag );
        }
    }
    delete pIterator;
    actrTransactionManager->endTransaction();
}
示例#14
0
void
printAll()
{
    int rc;
    char blkName[50];
    rc = acedGetString(Adesk::kTrue,
        "Enter Block Name <CR for current space>: ",
        blkName);

    if (rc != RTNORM)
        return;

    if (blkName[0] == '\0') {
        if (acdbHostApplicationServices()->workingDatabase()->tilemode() 
            == Adesk::kFalse) {
            struct resbuf rb;
            acedGetVar("cvport", &rb);
            if (rb.resval.rint == 1) {
                strcpy(blkName, ACDB_PAPER_SPACE);
            } else {
                strcpy(blkName, ACDB_MODEL_SPACE);
            }
        } else {
            strcpy(blkName, ACDB_MODEL_SPACE);
        }
    }
    AcDbBlockTable *pBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pBlockTableRecord;
    pBlockTable->getAt(blkName, pBlockTableRecord,
        AcDb::kForRead);
    pBlockTable->close();

    AcDbBlockTableRecordIterator *pBlockIterator;
    pBlockTableRecord->newIterator(pBlockIterator);

    for (; !pBlockIterator->done();
        pBlockIterator->step())
    {
        AcDbEntity *pEntity;
        pBlockIterator->getEntity(pEntity, AcDb::kForRead);

        AcDbHandle objHandle;
        pEntity->getAcDbHandle(objHandle);

        char handleStr[20];
        objHandle.getIntoAsciiBuffer(handleStr);
        const char *pCname = pEntity->isA()->name();

        acutPrintf("Object Id %lx, handle %s, class %s.\n",
            pEntity->objectId(), handleStr, pCname);

        pEntity->close();
    }
    delete pBlockIterator;
    pBlockTableRecord->close();

    acutPrintf("\n");
}
示例#15
0
void
addBlockWithAttributes()
{
    // Get an insertion point for the block reference,
    // definition, and attribute definition.
    //
    AcGePoint3d basePoint;
    if (acedGetPoint(NULL, "\nEnter insertion point: ",
        asDblArray(basePoint)) != RTNORM)
        return;

    // Get the rotation angle for the attribute definition.
    //
    double textAngle;
    if (acedGetAngle(asDblArray(basePoint),
        "\nEnter rotation angle: ", &textAngle) != RTNORM)
        return;

    // Define the height used for the attribute definition text.
    //
    double textHeight;
    if (acedGetDist(asDblArray(basePoint),
        "\nEnter text height: ", &textHeight) != RTNORM)
        return;

    // Build the block definition to be inserted.
    //
    AcDbObjectId blockId;
    defineBlockWithAttributes(blockId, basePoint,
        textHeight, textAngle);

    // Step 1: Allocate a block reference object.
    //
    AcDbBlockReference *pBlkRef = new AcDbBlockReference;

    // Step 2: Set up the block reference to the newly
    // created block definition.
    //
    pBlkRef->setBlockTableRecord(blockId);

    // Give it the current UCS normal.
    //
    struct resbuf to, from;

    from.restype = RTSHORT;
    from.resval.rint = 1; // UCS
    to.restype = RTSHORT;
    to.resval.rint = 0; // WCS

    AcGeVector3d normal(0.0, 0.0, 1.0);
    acedTrans(&(normal.x), &from, &to, Adesk::kTrue,
        &(normal.x));

    // Set the insertion point for the block reference.
    //
    pBlkRef->setPosition(basePoint);

    // Indicate the LCS 0.0 angle, not necessarily the UCS 0.0 angle.
    //
    pBlkRef->setRotation(0.0);
    pBlkRef->setNormal(normal);

    // Step 3: Open the current database's model space
    // block Table Record.
    //
    AcDbBlockTable *pBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pBlockTableRecord;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
        AcDb::kForWrite);

    pBlockTable->close();

    // Append the block reference to the model space
    // block Table Record.
    //
    AcDbObjectId newEntId;
    pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
    pBlockTableRecord->close();

    // Step 4: Open the block definition for read.
    //
    AcDbBlockTableRecord *pBlockDef;
    acdbOpenObject(pBlockDef, blockId, AcDb::kForRead);

    // Set up a block table record iterator to iterate
    // over the attribute definitions.
    //
    AcDbBlockTableRecordIterator *pIterator;
    pBlockDef->newIterator(pIterator);

    AcDbEntity *pEnt;
    AcDbAttributeDefinition *pAttdef;
    for (pIterator->start(); !pIterator->done();
        pIterator->step())
    {
        // Get the next entity.
        //
        pIterator->getEntity(pEnt, AcDb::kForRead);

        // Make sure the entity is an attribute definition
        // and not a constant.
        //
        pAttdef = AcDbAttributeDefinition::cast(pEnt);

        if (pAttdef != NULL && !pAttdef->isConstant()) {

            // We have a non-constant attribute definition,
            // so build an attribute entity.
            //
            AcDbAttribute *pAtt = new AcDbAttribute();
            pAtt->setPropertiesFrom(pAttdef);
            pAtt->setInvisible(pAttdef->isInvisible());

            // Translate the attribute by block reference.
            // To be really correct, the entire block
            // reference transform should be applied here.
            //
            basePoint = pAttdef->position();
            basePoint += pBlkRef->position().asVector();
            pAtt->setPosition(basePoint);

            pAtt->setHeight(pAttdef->height());
            pAtt->setRotation(pAttdef->rotation());

            pAtt->setTag("Tag");
            pAtt->setFieldLength(25);

            char *pStr = pAttdef->tag();
            pAtt->setTag(pStr);
            free(pStr);

            pAtt->setFieldLength(pAttdef->fieldLength());

            // The database column value should be displayed.
            // INSERT prompts for this.
            //
            pAtt->setTextString("Assigned Attribute Value");

            AcDbObjectId attId;

            pBlkRef->appendAttribute(attId, pAtt);
            pAtt->close();
        }
        pEnt->close(); // use pEnt... pAttdef might be NULL
    }
    delete pIterator;
    pBlockDef->close();
    pBlkRef->close();
}