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; }
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 ; }
void CMyDlg::OnCreateLine() { // TODO: Add your control notification handler code here acDocManager->lockDocument(curDoc()); int i; int m, n; char *buf = (char*)malloc(20); AcDbObjectId LineId; AcDbLine *pLine = NULL; //块表 AcDbBlockTable *pTb = NULL; //块表记录 AcDbBlockTableRecord *pTbr = NULL; //层表 AcDbLayerTable *pLyr = NULL; //层表记录 AcDbLayerTableRecord* pLyrr = NULL; //图形数据库 AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); Acad::ErrorStatus es; CListCtrl *pListCtr = (CListCtrl *)GetDlgItem( IDC_LIST1 ); //设置随机数种子 srand(time(NULL)); //更新数据 UpdateData(TRUE); m_VecSize += m_Edit5; m_xVec.resize(m_VecSize); m_yVec.resize(m_VecSize); //acutPrintf("%d\n", m_Edit1); es = pDb->getLayerTable(pLyr, AcDb::kForWrite); //以写的方式打开层表 es = pDb->getBlockTable(pTb, AcDb::kForRead); //以读的方式打开块表 es = pTb->getAt(ACDB_MODEL_SPACE, pTbr, AcDb::kForWrite);//以写的方式打开块表记录 //创建图层GalLineTest if (!pLyr->has("GalLineTest")) { pLyrr = new AcDbLayerTableRecord; //创建层记录 pLyrr->setName("GalLineTest"); //设置名字 //pLyrr->setColor(color); //设置颜色 //pLyrr->setLineWeight(lnWt); //设置线宽 if (Acad::eOk != pLyr->add(pLyrr)) //添加该层记录到层表 { //添加失败 delete pLyrr; //释放内存 pLyr->close(); //关闭层表 } //关闭层表记录 pLyrr->close(); } //关闭层表 pLyr->close(); //生成点坐标 for (i = 0; i < m_Edit5; ++i) { if ((m_Edit2 != 0) && (m_Edit4 != 0)) { m_xVec[i] = rand() % m_Edit2 + m_Edit1; m_yVec[i] = rand() % m_Edit4 + m_Edit3; } else { m_xVec[i] = 0; m_yVec[i] = 0; } } //遍历点坐标 for (m = 0; m < m_Edit5; ++m) { for (n = (m+1); n < m_Edit5; ++n) { if ((m_xVec[m] != m_xVec[n]) && (m_yVec[m] != m_yVec[n])) { AcGePoint3d ptStart(m_xVec[m], m_yVec[m], 0); AcGePoint3d ptEnd(m_xVec[n], m_yVec[n], 0); pLine = new AcDbLine(ptStart, ptEnd); //pLine->setColor(); pLine->setLayer("GalLineTest"); //创建线段 es = pTbr->appendAcDbEntity(LineId, pLine); if (Acad::eOk == es) { ++m_lLineCnt; } //acutPrintf("%d\n", LineId); sprintf(buf, "%d", LineId); m_ListCtr.InsertItem(m_Row, buf); buf = itoa(pLine->colorIndex(), buf, 10); m_ListCtr.SetItemText(m_Row, 1, buf); buf = itoa(LineLength(m_xVec[m], m_yVec[m], m_xVec[n], m_yVec[n]), buf, 10); m_ListCtr.SetItemText(m_Row, 2, buf); ++m_Row; pLine->close(); //关闭实体 } } } pTbr->close(); //关闭块表记录 pTb->close(); //关闭块表 acDocManager->unlockDocument(curDoc()); free(buf); }
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; }
Acad::ErrorStatus ArxDbgDbEntity::deepClone(AcDbObject* pOwner, AcDbObject*& pClonedObject, AcDbIdMapping& idMap, Adesk::Boolean isPrimary) const { // You should always pass back pClonedObject == NULL // if, for any reason, you do not actually clone it // during this call. The caller should pass it in // as NULL, but to be safe, we set it here as well. pClonedObject = NULL; if (ArxDbgOptions::m_instance.m_showDeepCloneDetails) { CString titleStr, tmpStr; titleStr.Format(_T("Beginning -- deepClone: %s"), ArxDbgUtils::objToClassAndHandleStr(const_cast<ArxDbgDbEntity*>(this), tmpStr)); ArxDbgUiTdmIdMap dbox(&idMap, acedGetAcadDwgView(), titleStr); dbox.DoModal(); } AcDb::DeepCloneType type = idMap.deepCloneContext(); // if we know everything will be cloned for us, just let // the base class do everything for us. if ((type == AcDb::kDcInsert) || (type == AcDb::kDcInsertCopy) || (type == AcDb::kDcExplode)) return AcDbEntity::deepClone(pOwner, pClonedObject, idMap, isPrimary); // following case happens when doing a AcDbDatabase::deepCloneObjects() // and the owner happens to be the same... then its really like a // kDcCopy, otherwise deepCloneObjects() is like a kDcBlock if (type == AcDb::kDcObjects) { if (ownerId() == pOwner->objectId()) type = AcDb::kDcCopy; else type = AcDb::kDcBlock; } // now ask derived classes what references they want cloned for them AcDbObjectIdArray refEntIds; AcDbIntArray refTypes; getCloneReferences(type, refEntIds, refTypes); ASSERT(refEntIds.length() == refTypes.length()); // if derived class doesn't have any references to take care of, then // we will just let the AcDbEntity::deepClone() take care of things. if (refEntIds.isEmpty()) return AcDbEntity::deepClone(pOwner, pClonedObject, idMap, isPrimary); // If this object is in the idMap and is already // cloned, then return. bool tmpIsPrimary = isPrimary ? true : false; // get around compiler performance warning AcDbIdPair idPair(objectId(), AcDbObjectId::kNull, false, tmpIsPrimary); if (idMap.compute(idPair) && (idPair.value() != NULL)) return Acad::eOk; // STEP 1: // Create the clone // AcDbObject *pClone = (AcDbObject*)isA()->create(); if (pClone != NULL) pClonedObject = pClone; // set the return value else return Acad::eOutOfMemory; // STEP 2: // Append the clone to its new owner. In this example, // we know that we are derived from AcDbEntity, so we // can expect our owner to be an AcDbBlockTableRecord, // unless we have set up an ownership relationship with // another of our objects. In that case, we need to // establish how we connect to that owner in our own // way. This sample shows a generic method using // setOwnerId(). // AcDbBlockTableRecord *pBTR = AcDbBlockTableRecord::cast(pOwner); if (pBTR != NULL) { AcDbEntity* ent = AcDbEntity::cast(pClone); pBTR->appendAcDbEntity(ent); } else { if (isPrimary) return Acad::eInvalidOwnerObject; // Some form of this code is only necessary if // anyone has set up an ownership for our object // other than with an AcDbBlockTableRecord. // pOwner->database()->addAcDbObject(pClone); pClone->setOwnerId(pOwner->objectId()); } // STEP 3: // Now we copy our contents to the clone. This is done // using an AcDbDeepCloneFiler. This filer keeps a // list of all AcDbHardOwnershipIds and // AcDbSoftOwnershipIds we, and any classes we derive // from, have. This list is then used to know what // additional, "owned" objects need to be cloned below. // AcDbDeepCloneFiler filer; dwgOut(&filer); // STEP 4: // Rewind the filer and read the data into the clone. // filer.seek(0L, AcDb::kSeekFromStart); pClone->dwgIn(&filer); // STEP 5: // This must be called for all newly created objects // in deepClone. It is turned off by endDeepClone() // after it has translated the references to their // new values. // pClone->setAcDbObjectIdsInFlux(); // STEP 6: // Add the new information to the idMap. We can use // the idPair started above. // idPair.setValue(pClonedObject->objectId()); idPair.setIsCloned(Adesk::kTrue); idMap.assign(idPair); // STEP 7: // Using the filer list created above, find and clone // any owned objects. // AcDbObject *pSubObject; AcDbObject *pClonedSubObject; AcDbObjectId id; Acad::ErrorStatus es; while (filer.getNextOwnedObject(id)) { // Open the object and clone it. Note that we now // set "isPrimary" to kFalse here because the object // is being cloned, not as part of the primary set, // but because it is owned by something in the // primary set. es = acdbOpenAcDbObject(pSubObject, id, AcDb::kForRead); if (es != Acad::eOk) continue; // could have been NULL or erased pClonedSubObject = NULL; pSubObject->deepClone(pClonedObject, pClonedSubObject, idMap, Adesk::kFalse); // If this is a kDcInsert context, the objects // may be "cheapCloned". In this case, they are // "moved" instead of cloned. The result is that // pSubObject and pClonedSubObject will point to // the same object. So, we only want to close // pSubObject if it really is a different object // than its clone. if (pSubObject != pClonedSubObject) pSubObject->close(); // The pSubObject may either already have been // cloned, or for some reason has chosen not to be // cloned. In that case, the returned pointer will // be NULL. Otherwise, since we have no immediate // use for it now, we can close the clone. if (pClonedSubObject != NULL) pClonedSubObject->close(); } // clone the referenced entities AcDbObject* ent; int len = refEntIds.length(); for (int i=0; i<len; i++) { if (refTypes[i] == kClone) { es = acdbOpenAcDbObject(ent, refEntIds[i], AcDb::kForRead); if (es == Acad::eOk) { pClonedSubObject = NULL; es = ent->deepClone(pOwner, pClonedSubObject, idMap, Adesk::kTrue); if (es == Acad::eOk) { // see comment above about cheap clone if (ent != pClonedSubObject) ent->close(); if (pClonedSubObject != NULL) pClonedSubObject->close(); } } } // this case is needed for RefEdit so we can pass its validation // test when editing a blockReference. We don't actually clone it // but we add it to the map so it thinks it got cloned and is therefore // a valid "Closed Set" of objects. else if (refTypes[i] == kFakeClone) { AcDbIdPair idPair(refEntIds[i], refEntIds[i], false, false, true); idMap.assign(idPair); } } if (ArxDbgOptions::m_instance.m_showDeepCloneDetails) { CString titleStr, tmpStr; titleStr.Format(_T("End -- deepClone: %s"), ArxDbgUtils::objToClassAndHandleStr(const_cast<ArxDbgDbEntity*>(this), tmpStr)); ArxDbgUiTdmIdMap dbox(&idMap, acedGetAcadDwgView(), titleStr); dbox.DoModal(); } // Leave pClonedObject open for the caller return Acad::eOk; }
void InteriorPointsConstructor::printInteriorPoints(int color, bool flag) { int i = 0; while (i < _contourArray->length()/2 + 1) { int j = 0; AcGePoint3dArray ptArr; if ((flag)|| (_interiorArray[i].length() <2)) ptArr.setLogicalLength(_interiorArray[i].length()); else ptArr.setLogicalLength(_interiorArray[i].length()-1); if ((flag)|| (_interiorArray[i].length() < 2)) while (j < _interiorArray[i].length()) { ptArr[j].set(_interiorArray[i][j].x, _interiorArray[i][j].y, _interiorArray[i][j].z); j++; } else { while (j < _interiorArray[i].length()-2) { ptArr[j].set(_interiorArray[i][j].x, _interiorArray[i][j].y, _interiorArray[i][j].z); if (sqrt(_interiorArray[i][j].x*_interiorArray[i][j].x + _interiorArray[i][j].y*_interiorArray[i][j].y + _interiorArray[i][j].z*_interiorArray[i][j].z) < 100) acutPrintf(_T("The shitty: %d, %d\n"), i, j); j++; } j++; ptArr[j].set(_interiorArray[i][j].x, _interiorArray[i][j].y, _interiorArray[i][j].z); } //if (i == 10){ 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; i++; } }
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); }
//--------------------------------------------------------------------------------------- // // 功能: 路线绘制回调函数 // // 输入参数: // 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) ; }
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(); }
void generateInventarTable(std::map<std::wstring, AcGePoint3d>& m_points, double textHeight) { Acad::ErrorStatus es; AcGePoint3d insertionPoint; AcDbObjectId objectID; AcDbTable* pTable = nullptr; AcDbDictionary* pDic = nullptr; AcDbBlockTable* pBT = nullptr; AcDbBlockTableRecord* pBTR = nullptr; AcDbDatabase*pDb = nullptr; u_int nrRows = m_points.size() + 2; double headerHeight = textHeight + ((textHeight * HEADERPERCENT) / 100); double titleHeight = textHeight + ((textHeight * TITLEPERCENT) / 100); double nrpctWidth = 0.0; int ret = acedGetPoint(NULL, _T("\nSelecteaza punctul de insertie al tabelului "), asDblArray(insertionPoint)); AcDbObjectId textID = Utils::NewTextStyle(_T("TableStyle"), titleHeight); pDb = acdbHostApplicationServices()->workingDatabase(); pBTR = new AcDbBlockTableRecord; pDb->getSymbolTable(pBT, AcDb::kForRead); pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite); pBT->close(); es = pDb->getTableStyleDictionary(pDic, AcDb::kForWrite); es = pDic->getAt(_T("Standard"), objectID); es = pDic->close(); pTable = new AcDbTable; pTable->setTableStyle(objectID); pTable->setSize(nrRows, NUM_COL); pTable->setAlignment(AcDb::kMiddleCenter); pTable->setTextHeight( titleHeight,AcDb::kTitleRow); pTable->setTextHeight(headerHeight, AcDb::kHeaderRow); pTable->setTextHeight(textHeight, AcDb::kDataRow); //pTable->setTextStyle(objectID); pTable->setTextStyle(0, 0, textID); pTable->setTextString(0, 0, _T("Inventar de coordonate")); double tableWidth = Utils::GetTextWidth(_T("Inventar@de@coordonate"), _T("TableStyle")); pTable->setWidth(tableWidth + (tableWidth * 15) / 100); pTable->setTextString(1, 0, _T("Nr.\npct.")); pTable->setTextStyle(1,0, textID); nrpctWidth = Utils::GetTextWidth(_T("NRPCT"), _T("TableStyle")); pTable->setColumnWidth(0,nrpctWidth); pTable->setTextStyle(1, 1, textID); pTable->setTextString(1, 1, _T("X[m]")); pTable->setTextStyle(1, 2, textID); pTable->setTextString(1, 2, _T("Y[m]")); std::map<std::wstring, AcGePoint3d>::iterator it = m_points.begin(); for (u_int row = 0; row < nrRows; row++) { //double tempWidth = Utils::GetTextWidth(Utils::int_To_wstring(row + 1).c_str(),_T("TableStyle")); //if (tempWidth > nrpctWidth) //{ // nrpctWidth = tempWidth; // pTable->setColumnWidth(0, nrpctWidth); //} pTable->setTextStyle(row + 2, 0, textID); pTable->setTextString(row + 2, 0, Utils::int_To_wstring(row+1).c_str()); //nr. curent pTable->setTextStyle(row + 2, 1, textID); pTable->setTextString(row + 2, 1, Utils::real_To_wstring(it->second.y).c_str()); // valoare X pTable->setTextStyle(row + 2, 2, textID); pTable->setTextString(row + 2, 2, Utils::real_To_wstring(it->second.x).c_str()); // valoare Y it++; } pTable->generateLayout(); pTable->setPosition(insertionPoint); pBTR->appendAcDbEntity(pTable); pBTR->close(); pTable->close(); }
void defineBlockWithAttributes( AcDbObjectId& blockId, // This is a returned value. const AcGePoint3d& basePoint, double textHeight, double textAngle) { int retCode = 0; AcDbBlockTable *pBlockTable = NULL; AcDbBlockTableRecord* pBlockRecord = new AcDbBlockTableRecord; AcDbObjectId entityId; // Step 1: Set the block name and base point of the block definition // pBlockRecord->setName("ASDK-BLOCK-WITH-ATTR"); pBlockRecord->setOrigin(basePoint); // Open the block table for write. // acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForWrite); // Step 2: Add the block table record to block table. // pBlockTable->add(blockId, pBlockRecord); // Step 3: Create a circle entity. // AcDbCircle *pCircle = new AcDbCircle; pCircle->setCenter(basePoint); pCircle->setRadius(textHeight * 4.0); pCircle->setColorIndex(3); // Append the circle entity to the block record. // pBlockRecord->appendAcDbEntity(entityId, pCircle); pCircle->close(); // Step 4: Create an attribute definition entity. // AcDbAttributeDefinition *pAttdef = new AcDbAttributeDefinition; // Set the attribute definition values. // pAttdef->setPosition(basePoint); pAttdef->setHeight(textHeight); pAttdef->setRotation(textAngle); pAttdef->setHorizontalMode(AcDb::kTextLeft); pAttdef->setVerticalMode(AcDb::kTextBase); pAttdef->setPrompt("Prompt"); pAttdef->setTextString("DEFAULT"); pAttdef->setTag("Tag"); pAttdef->setInvisible(Adesk::kFalse); pAttdef->setVerifiable(Adesk::kFalse); pAttdef->setPreset(Adesk::kFalse); pAttdef->setConstant(Adesk::kFalse); pAttdef->setFieldLength(25); // Append the attribute definition to the block. // pBlockRecord->appendAcDbEntity(entityId, pAttdef); // The second attribute definition is a little easier // because we are cloning the first one. // AcDbAttributeDefinition *pAttdef2 = AcDbAttributeDefinition::cast(pAttdef->clone()); // Set the values which are specific to the // second attribute definition. // AcGePoint3d tempPt(basePoint); tempPt.y -= pAttdef2->height(); pAttdef2->setPosition(tempPt); pAttdef2->setColorIndex(1); // Red pAttdef2->setConstant(Adesk::kTrue); // Append the second attribute definition to the block. // pBlockRecord->appendAcDbEntity(entityId, pAttdef2); pAttdef->close(); pAttdef2->close(); pBlockRecord->close(); pBlockTable->close(); return; }
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"); }
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(); }