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; }
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 CLayerTreeDlg::OnTvSelChanged(NMHDR* pNMHDR) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; // TODO: Add your control notification handler code here TV_ITEM tvi = pNMTreeView->itemNew; HTREEITEM hItem = tvi.hItem; if(m_tree.ItemHasChildren(hItem)) { return; } CString strLayerName = m_tree.GetItemText(hItem); Acad::ErrorStatus es = Acad::eOk; AcDbDatabase* pDB = acdbHostApplicationServices()->workingDatabase(); if (NULL == pDB) return; AcDbLayerTable *pLyTable = NULL; AcDbLayerTableRecord *pLyRcd = NULL; es = pDB->getSymbolTable(pLyTable,AcDb::kForRead); //获得当前数据库中层表指针 if ( es != Acad::eOk ) { acutPrintf("\n获取LayerTable的时候发生错误,请稍后再试。\n"); return; } if ( !pLyTable->has(strLayerName) ) { pLyTable->close(); return; } pLyTable->close(); SetCurrentLayer(strLayerName); }
void createDatabase() { // Create a new Database. AcDbDatabase *pDb = new AcDbDatabase(); // Get the BlockTable. AcDbBlockTable *pBTable = NULL; pDb->getSymbolTable(pBTable, AcDb::kForRead); // Get the ModelSpace. AcDbBlockTableRecord *pRecord = NULL; pBTable->getAt(ACDB_MODEL_SPACE, pRecord, AcDb::kForWrite); pBTable->close(); // Create a new Circle. AcDbCircle *pCircle1 = new AcDbCircle(AcGePoint3d(100,100,0), AcGeVector3d(0,0,1), 50.0); // Create another new Circle. AcDbCircle *pCircle2 = new AcDbCircle(AcGePoint3d(200,200,0), AcGeVector3d(0,0,1), 30.0); // Append Circle1 to ModelSpace pRecord->appendAcDbEntity(pCircle1); pCircle1->close(); // Append Circle2 to ModelSpace pRecord->appendAcDbEntity(pCircle2); pCircle2->close(); pRecord->close(); // Save to file // MUST append a DWG file extension. acutPrintf(_T("\nSave file to \"d:\\temp\\testfile.dwg\".")); pDb->saveAs(_T("d:\\temp\\testfile.dwg")); delete pDb; }
void createDwg() { AcDbDatabase *pDb = new AcDbDatabase(); AcDbBlockTable *pBtbl; pDb->getSymbolTable(pBtbl, AcDb::kForRead); AcDbBlockTableRecord *pBtblRcd; pBtbl->getAt(ACDB_MODEL_SPACE, pBtblRcd, AcDb::kForWrite); pBtbl->close(); AcDbCircle *pCir1 = new AcDbCircle(AcGePoint3d(1,1,1), AcGeVector3d(0,0,1), 1.0), *pCir2 = new AcDbCircle(AcGePoint3d(4,4,4), AcGeVector3d(0,0,1), 2.0); pBtblRcd->appendAcDbEntity(pCir1); pCir1->close(); pBtblRcd->appendAcDbEntity(pCir2); pCir2->close(); pBtblRcd->close(); // AcDbDatabase::saveAs() does NOT automatically // append a DWG file extension, so it // must be specified. // pDb->saveAs(_T("./test1.dwg")); delete pDb; }
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; }
//--------------------------------------------------------------------------------------- // // 功能: 路线绘制回调函数 // // 输入参数: // AeccDisplayOrientation &viewMode // IAeccAlignment *pAlign // IAcadBlock *pAnonymousBlock // // 返回值:bool // // 作 者: // // 日期: 2007/08 // // 修改记录:无 // //--------------------------------------------------------------------------------------- bool customAlignmentDraw(const AeccDisplayOrientation &viewMode, IAeccAlignment *pAlign, IAcadBlock *pAnonymousBlock ) { AcDbBlockTableRecord* blkRec; CString strName; CComBSTR bstrName; pAnonymousBlock->get_Name( &bstrName); strName = bstrName; AcDbBlockTable* blkTbl; AcDbDatabase* pDb = acdbCurDwg(); Acad::ErrorStatus es = pDb->getSymbolTable(blkTbl, AcDb::kForRead); if (es != Acad::eOk){ return false; } //// open named block es = blkTbl->getAt(strName, blkRec, AcDb::kForWrite); acutPrintf(_T("\nget block")); if (es != Acad::eOk) { blkTbl->close(); // doesn't need to be open anymore return false; } blkTbl->close(); // doesn't need to be open anymore CComQIPtr <IAeccAlignmentEntities> pAlignEntities; CComQIPtr <IAeccAlignmentEntity> pAlignEnt; CComQIPtr<IAeccAlignmentArc> pAlignArc; long iCount; pAlign->get_Entities(&pAlignEntities); if (pAlignEntities != NULL) { pAlignEntities->get_Count(&iCount); for (long i = 0; i < iCount; i++) { pAlignEnt.Release(); pAlignEntities->Item(_variant_t(i), &pAlignEnt); pAlignArc.Release(); pAlignArc = pAlignEnt; if (pAlignArc != NULL) { double radius; pAlignArc->get_Radius(&radius); //acutPrintf(_T("\nRadius: %f", radius)); if (radius < 200) { double x; double y; double dStart; double dEnd; pAlignArc->get_StartingStation(&dStart); pAlignArc->get_EndingStation(&dEnd); for (double delta = dStart; delta < dEnd; delta += 3.0) { pAlign->PointLocation(delta, 0.0, &x, &y); AcGePoint3d pt(x,y,0); AcDbCircle* cir = new AcDbCircle(pt, AcGeVector3d::kZAxis, 5.0); cir->setColorIndex (1, Adesk::kTrue); blkRec->appendAcDbEntity(cir); cir->close(); } } } } } blkRec->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); }
//----------------------------------------------------------------------------- void CLayerTreeDlg::OnNMClickLayerTree(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: 在此添加控件通知处理程序代码 *pResult = 0; UINT uFlag; CPoint pt; CString sSelLayer; HTREEITEM SelRoot,ParRoot,NexRoot; pt = CPoint(this->GetCurrentMessage()->pt); m_tree.ScreenToClient(&pt); SelRoot = m_tree.HitTest(pt,&uFlag); if (NULL == SelRoot) return; if (uFlag & TVHT_ONITEMSTATEICON) { BOOL bChecked = m_tree.GetCheck(SelRoot); //置反选中状态 SetTreeCheck(SelRoot, !bChecked); //分析是否有必要对树枝进行调整 ParRoot = m_tree.GetParentItem(SelRoot); while (ParRoot != NULL) { if (bChecked) m_tree.SetCheck(ParRoot,FALSE);//当前处在被选择状态即将被取消选择 else { int k=0;//当前处在非选择状态即将有可能处于选择状态(标志位) NexRoot=m_tree.GetNextItem(ParRoot,TVGN_CHILD); if(NexRoot!=SelRoot) { if(!m_tree.GetCheck(NexRoot)) k=1; } if(k==0) { while(TRUE) { NexRoot=m_tree.GetNextItem(NexRoot,TVGN_NEXT); if(NexRoot==NULL) break; if(NexRoot==SelRoot) continue; if(!m_tree.GetCheck(NexRoot)) { k=1; break; } } } if(k==0) m_tree.SetCheck(ParRoot); } ParRoot = m_tree.GetParentItem(ParRoot); } m_tree.SetCheck(SelRoot, bChecked); ShowLayer(SelRoot, !bChecked); // sendCommandToAutoCAD("redraw "); } else if(!m_tree.ItemHasChildren(SelRoot)) { CString strLayerName = m_tree.GetItemText(SelRoot); Acad::ErrorStatus es = Acad::eOk; AcDbDatabase* pDB = acdbHostApplicationServices()->workingDatabase(); if (NULL == pDB) return; AcDbLayerTable *pLyTable = NULL; AcDbLayerTableRecord *pLyRcd = NULL; es = pDB->getSymbolTable(pLyTable,AcDb::kForRead); //获得当前数据库中层表指针 if ( es != Acad::eOk ) { acutPrintf("\n获取LayerTable的时候发生错误,请稍后再试。\n"); return; } if ( !pLyTable->has(strLayerName) ) { pLyTable->close(); return; } pLyTable->close(); SetCurrentLayer(strLayerName); } }