Acad::ErrorStatus createCircle(AcDbObjectId & idCircle) { CLogger::Print(L"*Call: createCircle()"); Acad::ErrorStatus es, esTmp; AcDbBlockTable* pBlockTable = NULL; es = acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); if (Acad::eOk != es) { CLogger::Print(L"*Exit: createCircle() - Fail to get the BlockTable."); return es; } AcDbBlockTableRecord* pModelSpace = NULL; es = pBlockTable->getAt(ACDB_MODEL_SPACE, pModelSpace, AcDb::kForWrite); if (Acad::eOk != (esTmp = pBlockTable->close())) { CLogger::Print(L"Warn: Fail to close the BlockTable!"); acrx_abort(ACRX_T("\nThere is an error occured when close the BlockTable. Message: %s") , acadErrorStatusText(esTmp)); } if (Acad::eOk != es) { CLogger::Print(L"*Exit: createCircle() - Fail to get the Model Space! Error: %s", acadErrorStatusText(es)); return es; } idCircle = AcDbObjectId::kNull; AcGePoint3d pt3Center(9.0, 3.0, 0.0); AcGeVector3d vt3Normal(0.0, 0.0, 1.0); AcDbCircle* pCircle = new AcDbCircle(pt3Center, vt3Normal, 10.0); if (!pCircle) { if (Acad::eOk != (esTmp = pModelSpace->close())) { CLogger::Print(L"Warn: Fail to create new circle object!"); acrx_abort(ACRX_T("\nThere is an error occured. Error: %s") , acadErrorStatusText(esTmp)); } return Acad::eOutOfMemory; } es = pModelSpace->appendAcDbEntity(idCircle, pCircle); if (Acad::eOk != (esTmp = pModelSpace->close())) { CLogger::Print(L"Warn: Fail to close the Model Space!"); acrx_abort(ACRX_T("\nThere is an error occured when close the Model Space! Error: %s") , acadErrorStatusText(esTmp)); } if (Acad::eOk != es) { CLogger::Print(L"*Exit: createCircle() - Fail to append new circle in to Model Space!"); delete pCircle; return es; } if (Acad::eOk != (esTmp = pCircle->close())) { CLogger::Print(L"Warn: Fail to close the circle object."); acrx_abort(ACRX_T("\nFail to close the circle entity!, Error: %s") , acadErrorStatusText(esTmp)); } CLogger::Print(L"*Exit: createCircle()"); return Acad::eOk; }
// 查找连接点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(); }
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; }
AcDbObjectId Additional_Class::Creat_Table(AcGePoint3d TablePoint, vector<CString> Title, double ColWidth, double RowHeight, double TextHeight) { AcDbTable *pTable = new AcDbTable(); AcDbObjectId TableID; pTable->setNumColumns(Title.size()); pTable->setNumRows(1); pTable->setColumnWidth(ColWidth); pTable->setRowHeight(RowHeight); pTable->setDirection(AcGeVector3d(1,0,0)); pTable->setNormal(AcGeVector3d(0,0,1)); pTable->setPosition(TablePoint); AcDbBlockTable *pBlockTable; AcDbBlockTableRecord *pBlockTableRecord; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); pBlockTableRecord->appendAcDbEntity(TableID, pTable); //pBlockTable->close(); pBlockTableRecord->close(); //pTable->setTextString(0,0, "桩 号"); //pTable->setTextHeight(0,0,10); //pTable->setTextString(0,1, "X坐标值"); //pTable->setTextHeight(0,1,10); //pTable->setTextString(0,2, "Y坐标值"); //pTable->setTextHeight(0,2,10); //pTable->setTextString(0,3, "特性值"); //pTable->setTextHeight(0,3,10); //pTable->setTextString(0,4, "长 度"); //pTable->setTextHeight(0,4,10); pTable->close(); return TableID; }
Acad::ErrorStatus postToDatabase (/*[in]*/AcDbDatabase *pDb /*=NULL*/, AcDbEntity *pEnt, AcDbObjectId &idObj) { //----- Purpose: //----- Adds an entity to the MODEL_SPACE of the database given in argument. //----- * pDb: pointer to the databse where to add the entity, //----- if NULL, then the curretn database is used. //----- * pEnt: pointer to an entity instance. //----- * idObj: it will contain the assign ID to the object if successfully added to the database. //----- Note: //----- The entity object is closed while we return from that function. Only the idObj can be used after. assert ( pEnt != NULL ) ; if ( pDb == NULL ) pDb =acdbHostApplicationServices ()->workingDatabase () ; //----- Get a pointer to the current drawing //----- and get the drawing's block table. Open it for read. Acad::ErrorStatus es ; AcDbBlockTable *pBlockTable ; if ( (es =pDb->getBlockTable (pBlockTable, AcDb::kForRead)) == Acad::eOk ) { //----- Get the Model Space record and open it for write. This will be the owner of the new line. AcDbBlockTableRecord *pSpaceRecord ; if ( (es =pBlockTable->getAt (ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite)) == Acad::eOk ) { //----- Append pEnt to Model Space, then close it and the Model Space record. if ( (es =pSpaceRecord->appendAcDbEntity (idObj, pEnt)) == Acad::eOk ) pEnt->close () ; pSpaceRecord->close () ; } pBlockTable->close () ; } //----- It is good programming practice to return an error status return (es) ; }
Acad::ErrorStatus ArxDbgUtils::defineNewAnonymousBlock(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; newBlkRec = new AcDbBlockTableRecord; newBlkRec->setPathName(AcadString::nullStr); // constructor doesn't do it properly es = newBlkRec->setName(_T("*U")); if (es == Acad::eOk) es = blkTbl->add(newBlkRecId, newBlkRec); if (es != Acad::eOk) { // make sure everything went ok ArxDbgUtils::rxErrorMsg(es); delete newBlkRec; newBlkRec = NULL; // don't let caller get bad value } blkTbl->close(); // doesn't need to be open anymore return es; }
Acad::ErrorStatus postToDatabase(/*[in]*/AcDbEntity* pEnt,/*[out]*/AcDbObjectId& idObj) //Purpose: // Adds an entity to the MODEL_SPACE of the CURRENT database. //Note: // It could be generalized to add it to any block table record of // any database, but why complicate it... // { Acad::ErrorStatus es; AcDbBlockTable* pBlockTable; AcDbBlockTableRecord* pSpaceRecord; AcDbDatabase *pCurDwg = acdbHostApplicationServices()->workingDatabase(); if (pCurDwg==NULL) return Acad::eNoDatabase; //Get a pointer to the current drawing //and get the drawing's block table. Open it for read. if ((es = pCurDwg->getBlockTable(pBlockTable, AcDb::kForRead))==Acad::eOk){ //Get the Model Space record and open it for write. This will be the owner of the new line. if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite))==Acad::eOk){ //Append pEnt to Model Space, then close it and the Model Space record. if ((es = pSpaceRecord->appendAcDbEntity(idObj, pEnt))==Acad::eOk) pEnt->close(); pSpaceRecord->close(); } pBlockTable->close(); } //it is good programming practice to return an error status return es; }
void makeABlock() { // Create and name a new block table record. // AcDbBlockTableRecord *pBlockTableRec = new AcDbBlockTableRecord(); pBlockTableRec->setName("ASDK-NO-ATTR"); // Get the block table. // AcDbBlockTable *pBlockTable = NULL; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForWrite); // Add the new block table record to the block table. // AcDbObjectId blockTableRecordId; pBlockTable->add(blockTableRecordId, pBlockTableRec); pBlockTable->close(); // Create and add a line entity to the component's // block record. // AcDbLine *pLine = new AcDbLine(); AcDbObjectId lineId; pLine->setStartPoint(AcGePoint3d(3, 3, 0)); pLine->setEndPoint(AcGePoint3d(6, 6, 0)); pLine->setColorIndex(3); pBlockTableRec->appendAcDbEntity(lineId, pLine); pLine->close(); pBlockTableRec->close(); }
void BlockDraw_ConfigDlg::fillBlockList() { // 清空 m_blockList.ResetContent(); // 填充块列表 AcDbBlockTable* pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable( pBlockTable, AcDb::kForRead ); // Iterate through the block table and disaply the names in the list box. AcString name; AcDbBlockTableIterator* pBTItr; if ( pBlockTable->newIterator( pBTItr ) == Acad::eOk ) { while ( !pBTItr->done() ) { AcDbBlockTableRecord* pRecord; if ( pBTItr->getRecord( pRecord, AcDb::kForRead ) == Acad::eOk ) { pRecord->getName( name ); // 排除默认的2个块定义(模型空间和图纸空间) if( name.find( ACDB_MODEL_SPACE ) < 0 && name.find( ACDB_PAPER_SPACE ) < 0 ) { m_blockList.AddString( name.kACharPtr() ); } pRecord->close(); } pBTItr->step(); } } pBlockTable->close(); }
Acad::ErrorStatus postToDb(AcDbEntity* ent, AcDbObjectId& objId) { Acad::ErrorStatus es; AcDbBlockTable* pBlockTable; AcDbBlockTableRecord* pSpaceRecord; if ((es = acdbHostApplicationServices()->workingDatabase()-> getSymbolTable(pBlockTable, AcDb::kForRead)) != Acad::eOk) { return es; } if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite)) != Acad::eOk) { return es; } if ((es = pBlockTable->close()) != Acad::eOk) { return es; } if ((es = pSpaceRecord->appendAcDbEntity(objId, ent)) != Acad::eOk) { return es; } if ((es = pSpaceRecord->close()) != Acad::eOk) { return es; } return ent->close(); }
//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(); }
AcDbBlockTableRecord* CArxHelper::GetBlockTableRecord(AcDbDatabase* pDatabase, BOOL OpenWrite) { AcDbBlockTable* pBlockTable = NULL; pDatabase->getBlockTable(pBlockTable,AcDb::kForRead); AcDbBlockTableRecord* pBTR = NULL; if (pBlockTable) { pBlockTable->getAt(ACDB_MODEL_SPACE, pBTR, OpenWrite ? AcDb::kForWrite : AcDb::kForRead); pBlockTable->close(); } return pBTR; }
void InteriorPointsConstructor::printFirstInteriorPoints(int color, bool flag) { int i = 1; int j = 0; AcGePoint3dArray ptArr; ptArr.setLogicalLength(_interiorArray[i].length()+1); while (j < _interiorArray[i].length()) { ptArr[j].set(_interiorArray[i][j].x, _interiorArray[i][j].y, _interiorArray[i][j].z); j++; } ptArr[j].set(_interiorArray[0][0].x, _interiorArray[0][0].y, _interiorArray[0][0].z); AcDb3dPolyline *pNewPline = new AcDb3dPolyline(AcDb::k3dSimplePoly , ptArr, Adesk::kFalse); pNewPline->setColorIndex(color); AcDbBlockTable *pBlockTable; AcDbBlockTableRecord *pBlockTableRecord; acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead); pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); AcDbObjectId plineObjId; pBlockTableRecord->appendAcDbEntity(plineObjId, pNewPline); pBlockTable->close(); pBlockTableRecord->close(); //pNewPline->setLayer(_T("0")); //pNewPline->setClosed(Adesk::kFalse); pNewPline->close(); //} //delete pNewPline; }
void createPolyline() { // Set four vertex locations for the pline. // AcGePoint3dArray ptArr; ptArr.setLogicalLength(4); for (int i = 0; i < 4; i++) { ptArr[i].set((double)(i/2), (double)(i%2), 0.0); } // Dynamically allocate an AcDb2dPolyline object, // given four vertex elements whose locations are supplied // in ptArr. The polyline has no elevation, and is // explicitly set as closed. The polyline is simple; // that is, not curve fit or a spline. By default, the // widths are all 0.0 and there are no bulge factors. // AcDb2dPolyline *pNewPline = new AcDb2dPolyline( AcDb::k2dSimplePoly, ptArr, 0.0, Adesk::kTrue); pNewPline->setColorIndex(3); // Get a pointer to a Block Table object. // AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); // Get a pointer to the MODEL_SPACE BlockTableRecord. // AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close(); // Append the pline object to the database and // obtain its Object ID. // AcDbObjectId plineObjId; pBlockTableRecord->appendAcDbEntity(plineObjId, pNewPline); pBlockTableRecord->close(); // Make the pline object reside on layer "0". // pNewPline->setLayer("0"); pNewPline->close(); }
Acad::ErrorStatus ArxDbgUtils::collectBlockIds(SdStrObjIdList& list, bool excludeMsPs, bool excludeXref, bool excludeAnonymous, AcDbDatabase* db) { ASSERT(db != NULL); Acad::ErrorStatus retCode = Acad::eInvalidInput; AcDbBlockTable* blkTbl; Acad::ErrorStatus es = db->getSymbolTable(blkTbl, AcDb::kForRead); if (es == Acad::eOk) { // get an iterator over this symbol Table AcDbBlockTableIterator* tblIter; es = blkTbl->newIterator(tblIter); ASSERT(tblIter != NULL); if (es == Acad::eOk) { // walk table and just collect all the objIds // of the entries AcDbObjectId tblRecId; for (; !tblIter->done(); tblIter->step()) { AcDbBlockTableRecord* blkRec; es = tblIter->getRecord(blkRec, AcDb::kForRead); if (es == Acad::eOk) { if (excludeMsPs && blkRec->isLayout()) { ; // do nothing } else if ((excludeXref) && ((blkRec->isFromExternalReference()) || (blkRec->isFromOverlayReference()))) { ; // do nothing } else if (excludeAnonymous && blkRec->isAnonymous()) { ; // do nothing } else { const TCHAR* name; blkRec->getName(name); list.AddAlpha(name, blkRec->objectId()); } blkRec->close(); } } delete tblIter; retCode = Acad::eOk; } blkTbl->close(); } return retCode; }
static AcDbObjectId GetModelSpaceBlockID (void) { AcDbObjectId ObjectId; AcDbBlockTable * pBlockTable; Acad::ErrorStatus status; status = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); if (status != Acad::eOk) return false; status = pBlockTable->getAt(ACDB_MODEL_SPACE, ObjectId); pBlockTable->close(); return ObjectId; }
AcDbObjectId CArxHelper::GetBlockId(const CString& strName) { AcDbBlockTable* pBlockTable = NULL; acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForRead); AcDbBlockTableRecord* pBTR = NULL; AcDbObjectId blockId = AcDbObjectId::kNull; if (pBlockTable) { pBlockTable->getAt(strName, blockId, AcDb::kForRead); pBlockTable->close(); } return blockId; }
bool Additional_Class::BlkHasRef( CString RefName ) { // 判断该名称的块定义是否存在 AcDbBlockTable *pBlkTbl; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForWrite); CString strBlkDef; strBlkDef.Format(_T("%s"), RefName); if (pBlkTbl->has(strBlkDef) == true) { pBlkTbl->close(); return true; } pBlkTbl->close(); return false; }
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; }
AcDbObjectId Additional_Class::Draw_Text( CString InputText, AcGePoint3d InsertPoint, double TextHeight, double TextAngle ) { AcDbBlockTable *pBlockTable; AcDbBlockTableRecord *pBlockTableRecord; AcDbText *text_Up = new AcDbText(InsertPoint, InputText, AcDbObjectId::kNull, TextHeight, TextAngle); acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //this->Open_BlockTable(pBlockTable, NREADMODE); pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); //this->Open_ModelTableRecord(pBlockTableRecord, pBlockTable, NWRITEMODE); AcDbObjectId TextID; pBlockTableRecord->appendAcDbEntity(TextID, text_Up); text_Up->close(); pBlockTable->close(); pBlockTableRecord->close(); return TextID; }
bool insertPoints(std::map<std::wstring,AcGePoint3d>& m_Points, Adesk::Int16 pointStyle, double pointSize, double textHeight) { AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase(); AcCmColor pointColor; AcGePoint3d temp; AcDbPoint* tmp_point = nullptr; AcDbText* tmp_txt = nullptr; AcDbBlockTable* pBT = nullptr; AcDbBlockTableRecord* pBTR = nullptr; ACHAR* nrPct = nullptr; /*****************************************************************/ pointColor.setColorIndex(7); Layer::Create(_T("pctContur"), pointColor, false, false, false); Layer::Create(_T("nrPct"), pointColor, false, false, false); Acad::ErrorStatus es = Acad::eOk; es = acdbHostApplicationServices()->workingDatabase()->setPdmode(pointStyle); es = acdbHostApplicationServices()->workingDatabase()->setPdsize(pointSize); /*****************************************************************/ pDb->getSymbolTable(pBT, AcDb::kForRead); pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite); pBT->close(); std::map<std::wstring, AcGePoint3d>::iterator it; for (it = m_Points.begin(); it != m_Points.end();it++) { const wchar_t* key = it->first.c_str(); tmp_point = new AcDbPoint; tmp_point->setPosition(it->second); tmp_point->setLayer(_T("pctContur")); tmp_txt = new AcDbText(it->second, key, AcDbObjectId::kNull, textHeight, 0); tmp_txt->setLayer(_T("nrPct")); pBTR->appendAcDbEntity(tmp_point); pBTR->appendAcDbEntity(tmp_txt); tmp_point->close(); tmp_txt->close(); } pBTR->close(); return true; }
void AppendEnt(AcDbEntity *pEnt) { AcDbBlockTable *pBT; AcDbBlockTableRecord *pBTR; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBT,AcDb::kForRead); pBT->getAt(ACDB_MODEL_SPACE,pBTR,AcDb::kForWrite); pBT->close(); Acad::ErrorStatus es; //add entity to model space es = pBTR->appendAcDbEntity(pEnt); pBTR->close(); }
AcDbObjectId Additional_Class::Draw_Circle( AcGePoint3d ptCircle, double Radius ) { AcGeVector3d norm(0,0,1); AcDbCircle *pCircle = new AcDbCircle(ptCircle, norm, Radius); AcDbBlockTable *pBlockTable; AcDbBlockTableRecord *pBlockTableRecord; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //Open_BlockTable(pBlockTable, NREADMODE); //Open_ModelTableRecord(pBlockTableRecord, pBlockTable, NWRITEMODE); pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); AcDbObjectId CircleId; pBlockTableRecord->appendAcDbEntity(CircleId, pCircle); pCircle->close(); pBlockTable->close(); pBlockTableRecord->close(); return CircleId; }
// 根据块名称获取块定义id static AcDbObjectId GetBlockDefinitionByName( const CString& blockName ) { AcDbBlockTable* pBlockTable; acdbHostApplicationServices()->workingDatabase()->getSymbolTable( pBlockTable, AcDb::kForRead ); AcDbBlockTableRecord* pBlockTableRecord; Acad::ErrorStatus es = pBlockTable->getAt( blockName, pBlockTableRecord, AcDb::kForRead ); pBlockTable->close(); AcDbObjectId objId; if( es == Acad::eOk ) { objId = pBlockTableRecord->objectId(); pBlockTableRecord->close(); } return objId; }
void AsdkWblockReactor::otherWblock(AcDbDatabase* pDestDb, AcDbIdMapping& idMap, AcDbDatabase* pSrcDb) { // To find the destination Model Space, you must look // it up in the ID map: AcDbBlockTable *pSrcBlockTable; pSrcDb->getSymbolTable(pSrcBlockTable, AcDb::kForRead); AcDbObjectId srcModelSpaceId; pSrcBlockTable->getAt(ACDB_MODEL_SPACE, srcModelSpaceId); pSrcBlockTable->close(); AcDbIdPair idPair; idPair.setKey(srcModelSpaceId); idMap.compute(idPair); AcDbBlockTableRecord *pDestBTR; acdbOpenAcDbObject((AcDbObject*&)pDestBTR, idPair.value(), AcDb::kForRead, Adesk::kTrue); // END CODE APPEARING IN SDK DOCUMENT. acutPrintf("\nCorrect destination BTR's ObjectId is:\t\t%Ld", pDestBTR->objectId().asOldId()); pDestBTR->close(); // Incorrect way done here so that the wrong value can be // compared to the correct value // AcDbBlockTable *pDestBlockTable; pDestDb->getSymbolTable(pDestBlockTable, AcDb::kForRead); pDestBlockTable->getAt(ACDB_MODEL_SPACE, pDestBTR, AcDb::kForRead); pDestBlockTable->close(); acutPrintf("\nIncorrect destination BTR's ObjectId is \t\t%Ld", pDestBTR->objectId().asOldId()); pDestBTR->close(); // source database Model Space BTR's ObjectId is shown to // demonstrate that this is what the incorrect method gets // pSrcDb->getSymbolTable(pSrcBlockTable, AcDb::kForRead); pSrcBlockTable->getAt(ACDB_MODEL_SPACE, srcModelSpaceId); pSrcBlockTable->close(); acutPrintf("\nSource Database's Model Space BTR's ObjectId is \t%Ld", srcModelSpaceId.asOldId()); }
// Add the given entity to the current Database Acad::ErrorStatus addToDatabase(AcDbEntity* pEnt, AcDbObjectId& objId) { Acad::ErrorStatus acadReturnValue = Acad::eOk; AcDbBlockTable* pBlockTable; AcDbBlockTableRecord* pSpaceRecord; AcDbDatabase *pCurDwg = acdbHostApplicationServices()->workingDatabase(); if (pCurDwg==NULL) return Acad::eNoDatabase; if ((acadReturnValue = pCurDwg->getBlockTable(pBlockTable, AcDb::kForRead)) != Acad::eOk) { acutPrintf(ACRX_T("\n acdbCurDwg()->getBlockTable() failed")); return acadReturnValue; } if ((acadReturnValue = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite)) != Acad::eOk) { acutPrintf(ACRX_T("\n AcDbBlockTable::getAt() failed")); return acadReturnValue; } // close the block table object if ((acadReturnValue = pBlockTable->close()) != Acad::eOk) { acutPrintf(ACRX_T("\n AcDbBlockTable::close() failed")); return acadReturnValue; } // append the entity to the display list if ((acadReturnValue = pSpaceRecord->appendAcDbEntity(objId, pEnt)) != Acad::eOk) { acutPrintf(ACRX_T("\n AcDbBlockTableRecord::appendAcDbEntity() failed")); return acadReturnValue; } // close the block table record object if ((acadReturnValue = pSpaceRecord->close()) != Acad::eOk) { acutPrintf(ACRX_T("\n AcDbBlockTableRecord::close() failed")); return acadReturnValue; } return acadReturnValue; }
AcDbObjectId Additional_Class::Draw_Line(AcGePoint3d stPoint, AcGePoint3d enPoint) { AcDbLine *pLineTemp = new AcDbLine(); pLineTemp->setStartPoint(stPoint); pLineTemp->setEndPoint(enPoint); AcDbBlockTable *pBlockTable = NULL; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //this->Open_BlockTable(pBlockTable, NREADMODE); AcDbBlockTableRecord *pBlockTableRecord = NULL; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); //acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //this->Open_ModelTableRecord(pBlockTableRecord, pBlockTable, NWRITEMODE); AcDbObjectId TempLineID; pBlockTableRecord->appendAcDbEntity(TempLineID, pLineTemp); pLineTemp->close(); pBlockTable->close(); pBlockTableRecord->close(); return TempLineID; }
AcDbObjectId PostToModelSpace(AcDbEntity* pEnt) { AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getBlockTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); AcDbObjectId entId; pBlockTableRecord->appendAcDbEntity(entId, pEnt); pBlockTable->close(); pBlockTableRecord->close(); pEnt->close(); return entId; }
void addAsdkTextStyleSampObject() { AsdkTextStyleSamp *pNewObj = new AsdkTextStyleSamp; AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlock; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlock, AcDb::kForWrite); AcDbObjectId objId; pBlock->appendAcDbEntity(objId, pNewObj); pBlockTable->close(); pBlock->close(); pNewObj->close(); }
AcDbObjectId Additional_Class::Draw_Rectangle( AcGePoint2d stPt, double length, double height ) { AcDbPolyline *pPolyline = new AcDbPolyline(4); AcGePoint2d stPt1, stPt2, stPt3, stPt4; stPt1 = stPt; pPolyline->addVertexAt(0, stPt1, 0, 0, 0); stPt2.x = stPt.x +length; stPt2.y = stPt.y; pPolyline->addVertexAt(1, stPt2, 0, 0, 0); stPt3.x = stPt2.x; stPt3.y = stPt2.y + height; pPolyline->addVertexAt(2, stPt3, 0, 0, 0); stPt4.x = stPt3.x - length; stPt4.y = stPt3.y; pPolyline->addVertexAt(3, stPt4, 0, 0, 0); pPolyline->setClosed(Adesk::kTrue); AcDbBlockTable *pBlockTable = NULL; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //this->Open_BlockTable(pBlockTable, NREADMODE); AcDbBlockTableRecord *pBlockTableRecord = NULL; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); //acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //this->Open_ModelTableRecord(pBlockTableRecord, pBlockTable, NWRITEMODE); AcDbObjectId TempLineID; pBlockTableRecord->appendAcDbEntity(TempLineID, pPolyline); pPolyline->close(); pBlockTable->close(); pBlockTableRecord->close(); return TempLineID; }