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; }
void ArxDbgUiTdcInsert::OnAddExternalDwg() { CString fname; Acad::ErrorStatus es; es = ArxDbgUtils::getFileNameForRead(_T("Drawing File"), NULL, _T("dwg"), fname, false, false); if (es == Acad::eOk) { if (hasDwgFile(m_extDwgNames, fname)) ArxDbgUtils::alertBox(_T("That DWG file is already in the list.")); else { AcDbDatabase* db = new AcDbDatabase(false, true); es = db->readDwgFile(fname); if (es == Acad::eOk) { m_dbPtrs.append(db); m_extDwgNames.Add(fname); CString str; ArxDbgUtils::dbToStr(db, str); m_lbSourceDb.AddString(str); m_lbDestDb.AddString(str); } else { CString str; str.Format(_T("ERROR: could not read DWG file: %s"), ArxDbgUtils::rxErrorStr(es)); ArxDbgUtils::alertBox(str); } } } }
void CZhfPalette::AddControls() { acDocManager->lockDocument(curDoc(), AcAp::kWrite, NULL, NULL, true) ; CRect rect ; GetClientRect(&rect) ; int iWidth = rect.Width() ; int iHeight = rect.Height() ; CFont * pFont = new CFont; pFont->CreateFont(14, // nHeight 0, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL , // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily _T("Arial")); // lpszFac int iIndex = 0 ; int iCount = m_strArrayFile.GetCount() ; for (int i=0; i<iCount; i++) { CString strFile = m_strArrayFile.GetAt(i) ; CGsPreviewCtrl* pCtrl = new CGsPreviewCtrl() ; pCtrl->m_iIndex = iIndex ; pCtrl->m_strDwgFile = strFile ; m_pArrayPreviewCtrl.Add(pCtrl) ; pCtrl->Create(_T(""), WS_CHILD|WS_VISIBLE|SS_CENTER|SS_SUNKEN, CRect(10, 10, 110, 110), this) ; AcDbDatabase* pDbSrc = new AcDbDatabase(false) ; if(Acad::eOk==pDbSrc->readDwgFile(strFile)) { AcDbDatabase* pDbTo = new AcDbDatabase() ; this->Wblock(pDbSrc, pDbTo) ; this->FilterDb(pDbTo, m_nArrayFilterMode.GetAt(i)) ; pCtrl->SetDatabase(pDbTo); } delete pDbSrc ; CStatic* pCtrlStatic = new CStatic() ; CString strFileName ; strFileName.Format(_T("%s"), m_strArrayFileName.GetAt(i)) ; m_pArrayStatic.Add(pCtrlStatic) ; pCtrlStatic->Create(strFileName, WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(10, 10, 40, 110), this) ; pCtrlStatic->SetFont(pFont) ; iIndex++ ; } acDocManager->unlockDocument(curDoc()) ; this->OnSize(0, iWidth, iHeight) ; }
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; }
void LSS06() { CLogger::Print(_T("-------------| START LOGGING LESSONS 06 |--------------")); //------------ // Get the current DENKI project pointer, and number of files of project. if (!DenkiIsOpenProject()) { acutPrintf(ACRX_T("Denki project has not been opened yet!")); return; } ACHAR szMsg[256] = ACRX_T("\0"); DenkiDwgProject* pCurProj = DenkiDwgProject::getCurrent(); int nFileCount = pCurProj->count(); if (nFileCount < 1) { CLogger::Print(_T("*Exit: There is no file within current project!")); return; } //------------ // Get the 'Duplication Check Level' option of DENKI project. DenkiDuplicationCheckLevel CheckLvl = DenkiGetDuplicationCheckLevel(_T("NAME")); bool bChkInstNo = (CheckLvl == dclAsInstNumber) ? true : false; bool bChkBanNo = (CheckLvl == dclAsBanNumber) ? true : false; if (bChkInstNo) { bChkBanNo = true; } CLogger::Print(_T("> INS_NO: %s - BAN_NO: %s") , (bChkInstNo ? _T("Checked") : _T("Unchecked")) , (bChkBanNo ? _T("Checked") : _T("Unchecked"))); //------------ // Require to input BAN_NO, INST_NO, NAME keywords to search. ACHAR szNeedBanNo[256] = ACRX_T("\0"); ACHAR szNeedInstNo[256] = ACRX_T("\0"); ACHAR szNeedName[256] = ACRX_T("\0"); if (bChkBanNo) { ::LoadString(_hdllInstance, IDS_ASK_BANNO, szMsg, sizeof(szMsg)/sizeof(ACHAR)); if (RTNORM != acedGetString(1, szMsg, szNeedBanNo)) { CLogger::Print(_T("*Exit: Fail to get the BAN_NO keyword.")); return; } } if (bChkInstNo) { ::LoadString(_hdllInstance, IDS_ASK_INSTNO, szMsg, sizeof(szMsg)/sizeof(ACHAR)); if (RTNORM != acedGetString(1, szMsg, szNeedInstNo)) { CLogger::Print(_T("*Exit: Fail to get the INST_NO keyword.")); return; } } ::LoadString(_hdllInstance, IDS_ASK_NAME, szMsg, sizeof(szMsg)/sizeof(ACHAR)); if (RTNORM != acedGetString(1, szMsg, szNeedName)) { CLogger::Print(_T("*Exit: Fail to get the NAME keyword.")); return; } //------------ // Steps through DENKI project's files. for (int nIndex = 0; nIndex < nFileCount; nIndex++) { CLogger::Print(_T("---- Index = %d ----"), nIndex); DenkiDwgProjectFile& file = pCurProj->getDwgAt(nIndex); if (!file.hasZuwaku()) { CLogger::Print(_T("Warn: File has not ZUWAKU. > Ignore")); continue; } // Get file path, and file name LPCASTR pszFileName = NULL; file.getFilePath(pszFileName); CLogger::Print(_T("> %s"), pszFileName); // Check whether or not file has got DENKI_ZUWAKU. DWORD dwFlags = 0; if (!file.getZuwakuFlags(dwFlags)) { CLogger::Print(_T("Warn: Fail to get the ZUWAKU flags > Ignore")); continue; } if (!(dwFlags & DENKI_ZUWAKU)) { CLogger::Print(_T("Warn: File has not DENKI_ZUWAKU. > Ignore")); continue; } // Get the current working database (Just to store). AcDbDatabase* pCurDb = acdbHostApplicationServices()->workingDatabase(); Acad::ErrorStatus esResult; AcApDocument* pDoc = NULL; AcDbDatabase* pDb = NULL; bool bFromProject = false; bool bReadMyseft = false; // Look up the required database from managed documents. if (pDoc = findDocument(pszFileName)) { CLogger::Print(_T("Inform: found out the database from managed documents.")); pDb = pDoc->database(); } if (!pDb) { // Look up the required database from current opening DENKI project! if (!DCMG::IsCacheRunning()) { CLogger::Print(_T("Inform: cache is not running > try to get database object.")); if (pDb = DenkiGetProjectAcDbDatabase(pszFileName)) { CLogger::Print(_T("Inform: Database is got from DENKI project.")); } } if (!pDb && DCMG::IsCacheRunning()) { CLogger::Print(_T("Inform: cache is running > try to open DWG file into DENKI project.")); if (pDb = DenkiOpenProjectAcDbDatabase(pszFileName)) { CLogger::Print(_T("Inform: DWG file is opened into DENKI project. (Need to close it)")); bFromProject = true; } } // Open DWG file into an empty database object! if (!pDb) { pDb = new AcDbDatabase(false, true); esResult = pDb->readDwgFile(pszFileName, _SH_DENYNO); if (Acad::eOk == esResult) { CLogger::Print(_T("Inform: DWG file has been opened into an empty database object! (Need to delete it)")); bReadMyseft = true; } else { delete pDb; pDb = NULL; } } if (!pDb) { CLogger::Print(_T("Warn: Cannot open dwg file name: '%s' > Ignore"), pszFileName); acutPrintf(ACRX_T("Cannot open dwg file name: %s"), pszFileName); acdbHostApplicationServices()->setWorkingDatabase(pCurDb); continue; } } //------------ // We have got the database pointer now! // Get all of its BlockReferences. Then steps through them. AcDbObjectIdArray idaAll; int nBlkRefCount = getBlockRefAll(pDb, idaAll); CLogger::Print(_T("Inform: Browse all of file's block reference! - Number: %d"), nBlkRefCount); for (int nIdx = 0; nIdx < nBlkRefCount; nIdx++) { // Get the BlockReference's information! DenkiSymbolSnapshot dss; if (!dss.open(idaAll[nIdx], ACRX_T("NAME, NAME#*, BAN_NO, INST_NO"))) { CLogger::Print(_T("Warn: Fail to open DenkSymbolSnapshot object. > Ignore")); continue; } LPASTR pszBanNo = NULL, pszInstNo = NULL, pszName = NULL; // Compare BlockReference's information with the required Keywords. switch (1) { case 1: if (bChkBanNo) { if (!dss.getBanNo(pszBanNo)) { CLogger::Print(_T("Warn: %d. Fail to get BAN_NO value!"), nIdx); break; } if (!acutWcMatchEx(pszBanNo, szNeedBanNo, true)) { break; } } if (bChkInstNo) { if (!dss.getInstNo(pszInstNo)) { CLogger::Print(_T("Warn: %d. Fail to get INST_NO value!"), nIdx); break; } if (!acutWcMatchEx(pszInstNo, szNeedInstNo, true)) { break; } } if (!dss.getExpandedValue(ACRX_T("NAME"), pszName)) { CLogger::Print(_T("Warn: %d. Fail to get NAME value!"), nIdx); break; } if (!acutWcMatchEx(pszName, szNeedName, true)) { break; } default: // Found out the match BlockReference. acutPrintf(ACRX_T("Found out %d. NAME = '%s', BAN_NO = '%s', INST_NO = '%s'") , nIdx, szNeedName, (bChkBanNo ? szNeedBanNo : L""), (bChkInstNo ? szNeedInstNo : L"")); CLogger::Print(_T("Inform: Found out %d. NAME = '%s', BAN_NO = '%s', INST_NO = '%s'") , nIdx, szNeedName, (bChkBanNo ? szNeedBanNo : L""), (bChkInstNo ? szNeedInstNo : L"")); } // Release BlockReference's information. if (pszBanNo) dss.freeString(pszBanNo); if (pszInstNo) dss.freeString(pszInstNo); if (pszName) dss.freeString(pszName); dss.close(); } // Free memory to exit. if (bReadMyseft) { CLogger::Print(_T("Inform: DWG file has been opened into an empty database object!")); delete pDb; } if (bFromProject) { CLogger::Print(_T("Inform: DWG file has been opened into an DENKI project!")); DenkiCloseProjectAcDbDatabase(pDb); } acdbHostApplicationServices()->setWorkingDatabase(pCurDb); CLogger::Print(_T("*EXit")); } }
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); }