bool ArxEntityHelper::SetEntitiesColor2( const AcDbObjectIdArray& objIds, const AcArray<Adesk::UInt16>& colors ) { AcTransaction* pTrans = actrTransactionManager->startTransaction(); if( pTrans == 0 ) return false; bool ret = true; // 默认返回true int len = objIds.length(); for( int i = 0; i < len; i++ ) { AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, objIds[i], AcDb::kForWrite ) ) { actrTransactionManager->abortTransaction(); ret = false; break; } AcDbEntity* pEnt = AcDbEntity::cast( pObj ); if( pEnt == 0 ) { actrTransactionManager->abortTransaction(); ret = false; break; } pEnt->setColorIndex( colors[i] ); // 恢复原先的颜色 } actrTransactionManager->endTransaction(); return ret; }
void Additional_Class::addXdata( AcDbObjectId entID, CString xdataStr, CString xdataNameStr ) { AcDbEntity * pEnt; struct resbuf * pRb; if(Acad::eOk != acdbOpenAcDbEntity(pEnt, entID, AcDb::kForWrite)) { pEnt->close(); return; } TCHAR * tempTchar = CString2TCHAR(xdataNameStr); //TCHAR strAppName[] = tempTchar; acdbRegApp(tempTchar); TCHAR * typeName = CString2TCHAR(xdataStr); struct resbuf * pTemp; pTemp = pEnt->xData(tempTchar); pRb = acutBuildList(AcDb::kDxfRegAppName, tempTchar, AcDb::kDxfXdAsciiString, typeName, RTNONE); pEnt->setXData(pRb); acutRelRb(pRb); pEnt->close(); return; }
// 查找连接点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(); }
String GetSelectedExtent() { ads_name selection; int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection); if (returnValue == RTCAN) return 0; if (returnValue != RTNORM) { return L""; } if (acedSSSetFirst(selection, NULL) != RTNORM) { acedSSFree(selection); return L""; } ads_name element; acedSSName(selection, 0, element); acedSSFree(selection); AcDbObjectId idEntity; if (acdbGetObjectId(idEntity, element) != Acad::eOk) { acedSSFree(element); return L""; } AcDbEntity * entity; if ((acdbGetObjectId(idEntity, element) != Acad::eOk) || (acdbOpenObject(entity, idEntity, AcDb::kForRead) != Acad::eOk)) { acedSSFree(element); return L""; } acedSSFree(element); if (!entity->isKindOf(AcDbPolyline::desc())) return L""; AcDbPolyline * poly = static_cast<AcDbPolyline*>(entity); if (!poly->isClosed()) return 0; String extent = L"POLYGON(("; AcGePoint2d start; AcGePoint2d current; for (int i = 0; i < poly->numVerts(); i++) { poly->getPointAt(i, current); if (i > 0) { extent += L", "; } else { start = current; } extent += Round(current.x, 0) + L" " + Round(current.y, 0); } if (!start.isEqualTo(current)) { extent += L", " + Round(start.x, 0) + L" " + Round(start.y, 0); } extent += L"))"; poly->close(); return extent; }
static void CopyBack( AcDbEntity* pSrcEnt, const AcDbObjectId& objId ) { AcDbEntity* pEnt; acdbOpenAcDbEntity( pEnt, objId, AcDb::kForWrite ); pEnt->copyFrom( pSrcEnt ); pEnt->close(); }
bool ArxEntityHelper::GetEntitiesColor( const AcDbObjectIdArray& objIds, AcArray<Adesk::UInt16>& colors ) { AcTransaction* pTrans = actrTransactionManager->startTransaction(); if( pTrans == 0 ) return false; bool ret = true; // 默认返回true int len = objIds.length(); for( int i = 0; i < len; i++ ) { AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, objIds[i], AcDb::kForRead ) ) { actrTransactionManager->abortTransaction(); ret = false; colors.removeAll(); // 清空 break; } AcDbEntity* pEnt = AcDbEntity::cast( pObj ); if( pEnt == 0 ) { actrTransactionManager->abortTransaction(); ret = false; colors.removeAll(); // 清空 break; } Adesk::UInt16 ci = pEnt->colorIndex(); colors.append( ci ); // 记录原有的颜色 } actrTransactionManager->endTransaction(); return ret; }
bool ArxEntityHelper::SetEntitiesColor( AcDbObjectIdArray& objIds, unsigned short colorIndex ) { AcTransaction* pTrans = actrTransactionManager->startTransaction(); if( pTrans == 0 ) return false; bool ret = true; // 默认返回true int len = objIds.length(); for( int i = 0; i < len; i++ ) { AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, objIds[i], AcDb::kForWrite ) ) { actrTransactionManager->abortTransaction(); ret = false; break; } AcDbEntity* pGE = AcDbEntity::cast( pObj ); if( pGE == 0 ) { actrTransactionManager->abortTransaction(); ret = false; break; } // 设置颜色 pGE->setColorIndex( colorIndex ); } actrTransactionManager->endTransaction(); return ret; }
void ArxEntityHelper::ZoomToEntity( const AcDbObjectId& objId ) { AcTransaction* pTrans = actrTransactionManager->startTransaction(); if( pTrans == 0 ) return; AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, objId, AcDb::kForRead ) ) { actrTransactionManager->abortTransaction(); return; } AcDbEntity* pEnt = AcDbEntity::cast( pObj ); if( pEnt == 0 ) { actrTransactionManager->abortTransaction(); return; } AcDbExtents extents; bool ret = ( Acad::eOk == pEnt->getGeomExtents( extents ) ); actrTransactionManager->endTransaction(); if( ret && IsValidExtent( extents ) ) { ZoomEntity_Helper( extents.minPoint(), extents.maxPoint() ); } }
void ArxEntityHelper::ZoomToEntities( const AcDbObjectIdArray& objIds ) { AcTransaction* pTrans = actrTransactionManager->startTransaction(); if( pTrans == 0 ) return; AcDbExtents exts; int len = objIds.length(); for( int i = 0; i < len; i++ ) { AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, objIds[i], AcDb::kForRead ) ) continue; AcDbEntity* pEnt = AcDbEntity::cast( pObj ); if( pEnt == 0 ) continue; AcDbExtents extents; if( Acad::eOk != pEnt->getGeomExtents( extents ) ) continue; exts.addPoint( extents.minPoint() ); exts.addPoint( extents.maxPoint() ); } actrTransactionManager->endTransaction(); AcGePoint3d minPt = exts.minPoint(); AcGePoint3d maxPt = exts.maxPoint(); if( minPt.x <= maxPt.x && minPt.y <= maxPt.y && minPt.z <= maxPt.z ) { ZoomEntity_Helper( minPt, maxPt ); } }
void frgExtractTopologicalEntsFromLinesAlgm::_extract_from_seg(Vertex2dsOnSegment2d &stru) { // - 获取相关的线段(相交、重合) AcDbObjectIdArray ids; _search_related_segs(ids, stru.seg); // - 分为两类进行处理:相交和重叠 // -- 增加起点和终点 rlVertex2d *v = NULL; stru.vertex2ds.insert(std::make_pair(0.0, v)); stru.vertex2ds.insert(std::make_pair(1.0, v)); // -- 处理每一个线段 AcDbEntity *entity = NULL; for (int i = 0; i < ids.length(); i++) { acdbOpenAcDbEntity(entity, ids[i], AcDb::kForRead); if (entity == NULL) continue; if (entity->isA() != AcDbLine::desc()) { entity->close(); continue; } AcDbLine *_line = (AcDbLine *)entity; AcGeLineSeg2d _seg(AcGePoint2d(_line->startPoint().x, _line->startPoint().y), AcGePoint2d(_line->endPoint().x, _line->endPoint().y)); _line->close(); _extract_vertices(stru, _seg); } }
void frgExtractTopologicalEntsFromLinesAlgm::_extract_vertices_from_lines(std::vector<Vertex2dsOnSegment2d> &seg_pnts_pairs, const AcDbObjectIdArray &ids) { AcDbEntity *entity = NULL; acedSetStatusBarProgressMeter(_T("正在提取每根线段上的节点..."), 0, ids.length()); for (int i = 0; i < ids.length(); i++) { acdbOpenAcDbEntity(entity, ids[i], AcDb::kForRead); if (entity == NULL) continue; if (entity->isA() != AcDbLine::desc()) { entity->close(); continue; } AcDbLine *line = (AcDbLine *)entity; Vertex2dsOnSegment2d stru; stru.seg.set(AcGePoint2d(line->startPoint().x, line->startPoint().y), AcGePoint2d(line->endPoint().x, line->endPoint().y)); entity->close(); _extract_from_seg(stru); seg_pnts_pairs.push_back(stru); acedSetStatusBarProgressMeterPos(i); } acedRestoreStatusBar(); }
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 CDetailShow::OnInitDialog() { CAcUiDialog::OnInitDialog(); // TODO: 在此添加额外的初始化 long len = m_objIds.length(); //取得选择集的长度 //遍历选择集中的实体,将其打开并修改其颜色为红色 for (int i =0;i<len;i++) { ads_name entres; AcDbObjectId objId; AcDbEntity *obj; Acad::ErrorStatus es; es = acdbOpenAcDbEntity(obj, m_objIds[i], AcDb::kForRead, true); if (es == Acad::eOk) { LPCTSTR str; str = obj->isA()->name(); m_listBox.AddString(str); obj->close(); } } return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE }
// 使用常规的Open/Close机制 static void UpdateEntity2( const AcDbObjectId& objId ) { AcDbEntity* pEnt; if( Acad::eOk != acdbOpenObject( pEnt, objId, AcDb::kForWrite ) ) return; pEnt->recordGraphicsModified( true ); // 标签图元状态已修改,需要更新图形 pEnt->close(); }
// ----- AsdkSelectionFilterUI.SubentSel command (do not rename) static void AsdkSelectionFilterUI_SubentSel(void) { // we have to allow duplicates; otherwise, the xref would be selectable // only once (because the main entity is the one that counts). setAllowDuplicateSelection(curDoc(), true); ads_name sset, eName; AcDbObjectId id; // "_:n" gives us nested entities // if (RTNORM == acedSSGet("_:n", NULL, NULL, NULL, sset)) { acutPrintf("\n"); long len = 0; acedSSLength(sset, &len); for (long i = 0; i < len; i++)// For each entity in sset { resbuf *rb = NULL; // We use ssnamex() here, because the regular ssname() // would give only the main entity (the xref) // if (RTNORM == acedSSNameX(&rb, sset, i))//Get the sub entity { resbuf *rbWalk = rb; while (NULL != rbWalk) { if (RTENAME == rbWalk->restype) { eName[0] = rbWalk->resval.rlname[0]; eName[1] = rbWalk->resval.rlname[1]; if(Acad::eOk == acdbGetObjectId(id, eName)) { acutPrintf("Entity %d: <%x>", i, id.asOldId()); AcDbEntity *pEnt; if (Acad::eOk == acdbOpenObject(pEnt, id, AcDb::kForRead)) { acutPrintf("(%s)\n", pEnt->isA()->name()); pEnt->close(); } else acutPrintf("\nCouldn't open object"); } rbWalk = NULL; //force quit out of loop } else rbWalk = rbWalk->rbnext; } acutRelRb(rb); } } acedSSFree(sset); } setAllowDuplicateSelection(curDoc(), false); }
CCadEntity * CCadEntityFactory::GetCadEntity(AcDbObjectId & idEntity) { AcDbEntity * entity = 0; if (acdbOpenObject(entity, idEntity, AcDb::kForRead) != Acad::eOk) return 0; CCadEntity * cadEntity = CCadEntityFactory::GetCadEntity(entity); entity->close(); return cadEntity; }
bool MySSGetFilter::canBeSelected(AcDbObjectId id) const { bool ans = true; AcDbEntity * pEnt; if (acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead) == Acad::eOk) { ans = canBeSelected(pEnt); pEnt->close(); } return ans; }
//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(); }
static AcDbEntity* CloneEntity( const AcDbObjectId& objId ) { AcDbEntity* pEnt; acdbOpenObject( pEnt, objId, AcDb::kForRead ); AcDbEntity* pClone = AcDbEntity::cast( pEnt->clone() ); pEnt->close(); return pClone; }
void Jig3d::apply() throw(CmdException) { m_xform = m_xformTemp*m_xform; AcDbEntity* pE; if (acdbOpenObject(pE,m_int.m_idEntity,AcDb::kForWrite)==Acad::eOk) { Acad::ErrorStatus es; if ((es=pE->transformBy(m_xform))!=Acad::eOk) throw CmdException(es,"Transformation cannot be applied to object"); pE->close(); } }
bool ArxDbgUtils::isOnLockedLayer(AcDbObjectId& id, bool printMsg) { AcDbEntity* ent; Acad::ErrorStatus es = acdbOpenAcDbEntity(ent, id, AcDb::kForRead); if (es == Acad::eOk) { bool result = isOnLockedLayer(ent, printMsg); ent->close(); return result; } return true; // by default we "lock" data }
void ZcEntityReactor::openedForModify(const AcDbObject* dbObj) { if (!dbObj->isKindOf(AcDbEntity::desc())) { acutPrintf(_T("\nObject is not a valid Entity!")); return; } AcDbEntity* pEnt = AcDbEntity::cast(dbObj); CString strLayer; strLayer.Format(_T("\nCurrent Entity:%s .The layerName:%s ."), pEnt->isA()->name(), pEnt->layer()); acutPrintf(strLayer); }
void ZcEntityReactor::modified(const AcDbObject* dbObj) { if (!dbObj->isKindOf(AcDbEntity::desc())) { acutPrintf(_T("\nObject is not a valid Entity!")); return; } AcDbEntity* pEnt = AcDbEntity::cast(dbObj); CString strLayer; strLayer.Format(_T("\nEntity:%s has been modified.The layerName:%s.\n"), pEnt->isA()->name(), pEnt->layer()); acutPrintf(strLayer); }
void ArxEntityHelper::TransformEntities2( const AcDbObjectIdArray& objIds, const AcGeMatrix3d& xform ) { if( objIds.isEmpty() ) return; int len = objIds.length(); for( int i = 0; i < len; i++ ) { AcDbEntity* pEnt; if( Acad::eOk == acdbOpenAcDbEntity( pEnt, objIds[i], AcDb::kForWrite ) ) { pEnt->transformBy( xform ); pEnt->close(); } } }
bool GetInsertPoint( const AcDbObjectId& objId, AcGePoint3d& pt ) { AcDbEntity* pEnt; if( Acad::eOk != acdbOpenObject( pEnt, objId, AcDb::kForRead ) ) return false; GasGeologyGE* pGE = GasGeologyGE::cast( pEnt ); bool ret = ( pGE != 0 ); if( ret ) { pt = pGE->getInsertPt(); } pEnt->close(); return ret; }
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; }
CString Additional_Class::Get_Xdata(AcDbObjectId EntID, CString Xdata_Ref ) { AcDbEntity *pEnt; acdbOpenAcDbEntity(pEnt, EntID, AcDb::kForRead); struct resbuf *pRb; pRb = pEnt->xData(Xdata_Ref); if (pRb != NULL) { struct resbuf *pTemp; pTemp = pRb; pTemp = pTemp->rbnext; pEnt->close(); return pTemp->resval.rstring; } acutRelRb(pRb); pEnt->close(); return ""; }
static void DrawBlockEnts( AcGiWorldDraw* mode, AcGeVoidPointerArray& ents ) { int n = ents.length(); for( int i = 0; i < n; i++ ) { AcDbEntity* pEnt = ( AcDbEntity* )ents[i]; pEnt->worldDraw( mode ); } }
void asdktest3 () { //----- Create a line and a circle (memory only) AcDbLine *pLine =new AcDbLine (AcGePoint3d (), AcGePoint3d (100, 100, -100)) ; AcDbCircle *pCircle =new AcDbCircle (AcGePoint3d (50, 50, 0), AcGeVector3d (0, 0, 1) , 25.0) ; //----- Create a region from the circle AcDbVoidPtrArray arr1, arr2 ; arr1.append (pCircle) ; AcDbRegion::createFromCurves (arr1, arr2) ; AcDbRegion *pRegion =(AcDbRegion *)arr2.at (0) ; delete pCircle ; //----- Add the line and the region objects to the collector //----- NB: Remember those object are memory objects only AsdkHlrCollector collector ; collector.setDeleteState (true) ; collector.addEntity (pLine) ; collector.addEntity (pRegion) ; //----- Process hidden line removal AsdkHlrEngine hlr (AcGePoint3d (50, 50,0), AcGeVector3d (0, 0, 1), kEntity | kBlock | kShowAll | kProject | kHonorInternals) ; hlr.run (collector) ; //----- To easily see the result, we do append resulting entities to the current database //----- and use the color convention used in command 'TEST1' int n =collector.mOutputData.logicalLength () ; for ( int i =0 ; i < n ; i++ ) { AsdkHlrData *p =collector.mOutputData [i] ; AcDbEntity *pEnt =p->getResultEntity () ; AsdkHlrData::Visibility vis =p->getVisibility () ; if ( vis == AsdkHlrData::kVisible ) pEnt->setColorIndex (1) ; else pEnt->setColorIndex (5) ; AcDbObjectId id ; if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) { acutPrintf (_T("Failed to add entity to current space.\n")) ; break ; } //----- Entity originator path AcDbObjectIdArray ids =p->getObjectIds () ; if ( ids.logicalLength () > 0 ) { acutPrintf (ACRX_T("\n%ld, "), pEnt->objectId ().asOldId ()) ; for ( int j =0 ; j < ids.logicalLength () ; j++ ) { acutPrintf (ACRX_T("%ld, "), ids.at (j).asOldId ()) ; } } pEnt->close () ; } }
// This function has the user select an entity and then // calls the reflectedEnergy() function in the protocol // extension class attached to that entity's class. // void energy() { AcDbEntity *pEnt; AcDbObjectId pEntId; ads_name en; ads_point pt; if (acedEntSel("\nSelect an Entity: ", en, pt) != RTNORM) { acutPrintf("Nothing Selected\n"); return; } acdbGetObjectId(pEntId, en); acdbOpenObject(pEnt, pEntId, AcDb::kForRead); // call the protocol extension class's method // double eTemp = ACRX_X_CALL(pEnt, AsdkEntTemperature)->reflectedEnergy(pEnt); acutPrintf("\nEnergy == %f\n", eTemp); pEnt->close(); }