可以随时从数据库中清除未引用的命名对象。不能清除其他对象引用的命名对象。例如,字体文件可能由文本样式引用,或者图层可能由该图层上的对象引用。清除可减小保存到磁盘时图形文件的大小。 使用该方法从图形数据库中清除未参照的对象。该方法需要要以无对象形式清除的对象列表。传递到该方法中的理论对象使用可以从数据库中删除的对象进行更新。调用 之后,必须擦除返回的每个对象。PurgePurgeObjectIdCollectionObjectIdGraphObjectIdCollectionObjectIdGraphPurgePurge 清除所有未参照的图层以下示例演示如何从数据库中清除所有未引用的图层。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices <CommandMethod("PurgeUnreferencedLayers")> _ Public Sub PurgeUnreferencedLayers() '' Get the current document and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() '' Open the Layer table for read Dim acLyrTbl As LayerTable acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _ OpenMode.ForRead) '' Create an ObjectIdCollection to hold the object ids for each table record Dim acObjIdColl As ObjectIdCollection = New ObjectIdCollection() '' Step through each layer and add it to the ObjectIdCollection For Each acObjId As ObjectId In acLyrTbl acObjIdColl.Add(acObjId) Next '' Remove the layers that are in use and return the ones that can be erased acCurDb.Purge(acObjIdColl) '' Step through the returned ObjectIdCollection For Each acObjId As ObjectId In acObjIdColl Dim acSymTblRec As SymbolTableRecord acSymTblRec = acTrans.GetObject(acObjId, _ OpenMode.ForWrite) Try '' Erase the unreferenced layer acSymTblRec.Erase(True) Catch Ex As Autodesk.AutoCAD.Runtime.Exception '' Layer could not be deleted Application.ShowAlertDialog("Error:" & vbLf & Ex.Message) End Try Next '' Commit the changes and dispose of the transaction acTrans.Commit() End Using End Sub C#using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; [CommandMethod("PurgeUnreferencedLayers")] public static void PurgeUnreferencedLayers() { // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Layer table for read LayerTable acLyrTbl; acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable; // Create an ObjectIdCollection to hold the object ids for each table record ObjectIdCollection acObjIdColl = new ObjectIdCollection(); // Step through each layer and add iterator to the ObjectIdCollection foreach (ObjectId acObjId in acLyrTbl) { acObjIdColl.Add(acObjId); } // Remove the layers that are in use and return the ones that can be erased acCurDb.Purge(acObjIdColl); // Step through the returned ObjectIdCollection // and erase each unreferenced layer foreach (ObjectId acObjId in acObjIdColl) { SymbolTableRecord acSymTblRec; acSymTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite) as SymbolTableRecord; try { // Erase the unreferenced layer acSymTblRec.Erase(true); } catch (Autodesk.AutoCAD.Runtime.Exception Ex) { // Layer could not be deleted Application.ShowAlertDialog("Error:\n" + Ex.Message); } } // Commit the changes and dispose of the transaction acTrans.Commit(); } } VBA/ActiveX 交叉引用在 ActiveX 自动化库中,您将使用该方法删除所有未引用的命名对象,它将标识可以删除哪些对象。但是,使用 AutoCAD .NET API 您需要提供要清除的对象,然后该方法将哪些对象返回给您实际可以清除的对象。因此,在使用 AutoCAD .NET API 从数据库中清除所有未引用的命名对象时,需要做更多的工作。PurgeAllPurge ThisDrawing.PurgeAll |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )
GMT+8, 2024-5-19 14:26
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.