使用智能指针 获得当前所有图层的ID
以下是二段代码:功能是获得当前所有图层的ID
int CLayerOperate::GetAllLayerIds() { LayerIds.removeAll(); AcDbLayerTable *pLT; acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLT,AcDb::kForRead); AcDbLayerTableIterator *pLTI; AcDbObjectId idTemp; pLT->newIterator(pLTI); for (pLTI->start(); !pLTI->done(); pLTI->step()) { pLTI->getRecordId(idTemp); LayerIds.append(idTemp); } delete pLTI; pLT->close(); return LayerIds.length();
以下是使用智能指针,好处就是不用删指针,安全。
int LayerCommon::GetAllLayerIds(AcDbObjectIdArray& idLayerArr) { // 得到当前图形的层块 游天居士到此一游 AcDbLayerTablePointer pLayerTbl(acdbCurDwg(),AcDb::kForRead); if (pLayerTbl.openStatus() != eOk) { return NULL; } AcDbLayerTableIterator* pLTI = NULL; pLayerTbl->newIterator(pLTI); AcDbObjectId idTemp; for (pLTI->start(); !pLTI->done(); pLTI->step()) { if (Acad::eOk == pLTI->getRecordId(idTemp)) { idLayerArr.append(idTemp); } } delete pLTI; return idLayerArr.length(); }
// DESCRIPTION
//
// The template classes defined in this header file provide
// simplified "management" (i.e., opening, closing, creating,
// deleting) of AcDbObject's upon construction and destruction.
// The constructor provides the necessary arguments to open the
// object and the destructor closes the object. During the
// lifetime of the object, clients use operator->() to
// manipulate the opened object. These classes also simplify
// creating and deletion of objects.
//
// One base class, AcDbObjectPointerBase provides the basic
// services of opening and closing objects. Derived classes
// provide the real interface to open objects of various types
// derived from AcDbObject. They usually provide additional
// constructors that know about the particular ways of opening
// an object. The following template classes are defined in
// this header file.
//
// AcDbObjectPointerBase<T_OBJECT>
//
// This class provides the basic services and defines the
// basic contracts for using the smart pointers derived
// from it. You normally don't use this class directly,
// but may use it to define a derived class to add
// constructors that know how to open an object derived
// from AcDbObject in alternate forms.
//
// AcDbObjectPointer<T_OBJECT>
//
// This class allows you to access any AcDbObject-based
// object given its object ID. The following pre-defined
// typedefs are available.
//
// AcDbDictionaryPointer
// AcDbEntityPointer
//
// AcDbSymbolTablePointer<T_OBJECT>
//
// This class allows you to access the symbol tables
// associated with every AcDbDatabase. You can specify
// an object ID or a particular database. The following
// pre-defined typedefs are available for individual
// symbol-table types.
//
// AcDbBlockTablePointer
// AcDbDimStyleTablePointer
// AcDbLayerTablePointer
// AcDbLinetypeTablePointer
// AcDbRegAppTablePointer
// AcDbTextStyleTablePointer
// AcDbUCSTablePointer
// AcDbViewTablePointer
// AcDbViewportTablePointer
//
// Note that to open a "plain" symbol table, you may use
// AcDbObjectPointer<AcDbSymbolTable>.
//
// AcDbSymbolTableRecordPointer<T_OBJECT>
//
// This class allow you to access symbol-table records by
// object ID or by name. The following pre-defined
// typedefs are available for individual symbol-table
// record types.
//
// AcDbBlockTableRecordPointer
// AcDbDimStyleTableRecordPointer
// AcDbLayerTableRecordPointer
// AcDbLinetypeTableRecordPointer
// AcDbRegAppTableRecordPointer
// AcDbTextStyleTableRecordPointer
// AcDbUCSTableRecordPointer
// AcDbViewTableRecordPointer
// AcDbViewportTableRecordPointer
//
// Note that to open a "plain" symbol record, you may use
// AcDbObjectPointer<AcDbSymbolTableRecord>.
//
// These classes are designed to be type-safe replacements for
// explicitly using acdbOpenObject(), acdbOpenAcDbObject(), and
// acdbOpenAcDbEntity(). Using these classes incur opening and
// close objects, which, under certain circumstances, may be
// better managed using transactions.
typedef AcDbSymbolTablePointer<AcDbBlockTable> AcDbBlockTablePointer;
typedef AcDbSymbolTablePointer<AcDbDimStyleTable> AcDbDimStyleTablePointer;
typedef AcDbSymbolTablePointer<AcDbLayerTable> AcDbLayerTablePointer;
typedef AcDbSymbolTablePointer<AcDbLinetypeTable> AcDbLinetypeTablePointer;
typedef AcDbSymbolTablePointer<AcDbRegAppTable> AcDbRegAppTablePointer;
typedef AcDbSymbolTablePointer<AcDbTextStyleTable> AcDbTextStyleTablePointer;
typedef AcDbSymbolTablePointer<AcDbUCSTable> AcDbUCSTablePointer;
typedef AcDbSymbolTablePointer<AcDbViewTable> AcDbViewTablePointer;
typedef AcDbSymbolTablePointer<AcDbViewportTable> AcDbViewportTablePointer;