Exploding an object converts the single object to its constituent parts. You use the Explode function to explode an object, and it requires a DBObjectCollection object in which is used to return the resulting objects. For example, exploding a polyline can result in the creation of an object collection that contains multiple lines and arcs.
分解对象将对象从单一对象转换为构成该对象的组件。用户可以使用 例如 Explode 函数来分解对象,它需要一个 DBObjectCollection 类型的对象用于接收返回的结果对象。例如,分解一条多段线可能导致产生一个由包含多个直线和圆弧构成的对象集合。
If a block is exploded, the object collection returned holds the graphical objects in which define the block. After an object is exploded, the original object is left unaltered. If you want the returned objects to replace the original object, the original object must be erased and then the returned objects must be added to a block table record.
如果一个块被分解了,一个对象集合将会被返回,它保存了定语块的图形对象。对象被分解后,原始对象将不会被改变。如果你想用返回的对象代替原始对象,原始对象必须被删除并且返回的对象必须添加到块表记录中去。
For more information about exploding objects, see “Disassociate Compound Objects (Explode)” in the AutoCAD User's Guide.
更多关于分解对象的详细信息,请参见《AutoCAD 用户手册》中的“解除复合对象的关联(分解)”。
This example creates a lightweight polyline object and then explodes the polyline into its simplest objects. After the polyline is exploded, it is disposed of and the returned objects are added to Model space.
本例创建一个优化多段线对象,然后这条分解多段线成简单对象。多段线被分解后,原多段线将被销毁掉,而返回的对象将添加到模型空间中去。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("ExplodeObject")> _
Public Sub ExplodeObject()
'' 获得当前文档和数据库 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 Block table for read
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _
OpenMode.ForRead)
'' 以写方式打开模型空间块表记录 Open the Block table record Model space for write
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
OpenMode.ForWrite)
'' 创建一条轻量多段线 Create a lightweight polyline
Using acPoly As Polyline = New Polyline()
acPoly.SetDatabaseDefaults()
acPoly.AddVertexAt(0, New Point2d(1, 1), 0, 0, 0)
acPoly.AddVertexAt(1, New Point2d(1, 2), 0, 0, 0)
acPoly.AddVertexAt(2, New Point2d(2, 2), 0, 0, 0)
acPoly.AddVertexAt(3, New Point2d(3, 2), 0, 0, 0)
acPoly.AddVertexAt(4, New Point2d(4, 4), 0, 0, 0)
acPoly.AddVertexAt(5, New Point2d(4, 1), 0, 0, 0)
'' 设置索引为3的点的凸度 Sets the bulge at index 3
acPoly.SetBulgeAt(3, -0.5)
'' 分解多段线 Explodes the polyline
Dim acDBObjColl As DBObjectCollection = New DBObjectCollection()
acPoly.Explode(acDBObjColl)
For Each acEnt As Entity In acDBObjColl
'' 添加新对象到块表记录和事务中 Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acEnt)
acTrans.AddNewlyCreatedDBObject(acEnt, True)
Next
'' 销毁内存中的多段线 Dispose of the in memory polyline
End Using
'' 保存新对象到数据库中 Save the new objects to the database
acTrans.Commit()
End Using
End Sub
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("ExplodeObject")]
public static void ExplodeObject()
{
// 获得当前文档和数据库 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 Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// 以写方式打开模型空间块表记录 Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
// 创建一条轻量多段线 Create a lightweight polyline
using (Polyline acPoly = new Polyline())
{
acPoly.SetDatabaseDefaults();
acPoly.AddVertexAt(0, new Point2d(1, 1), 0, 0, 0);
acPoly.AddVertexAt(1, new Point2d(1, 2), 0, 0, 0);
acPoly.AddVertexAt(2, new Point2d(2, 2), 0, 0, 0);
acPoly.AddVertexAt(3, new Point2d(3, 2), 0, 0, 0);
acPoly.AddVertexAt(4, new Point2d(4, 4), 0, 0, 0);
acPoly.AddVertexAt(5, new Point2d(4, 1), 0, 0, 0);
// Sets the bulge at index 3
acPoly.SetBulgeAt(3, -0.5);
// Explodes the polyline
DBObjectCollection acDBObjColl = new DBObjectCollection();
acPoly.Explode(acDBObjColl);
foreach (Entity acEnt in acDBObjColl)
{
// 添加新对象到块表记录和事务中 Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acEnt);
acTrans.AddNewlyCreatedDBObject(acEnt, true);
}
// Dispose of the in memory polyline
}
// 保存新对象到数据库中 Save the new objects to the database
acTrans.Commit();
}
}