You can append, insert, or remove loops from the boundaries of a Hatch object. Associative hatches are updated to match any changes made to their boundaries. Non-associative hatches are not updated.
可以向图案填充边界附加、插入或移除环。关联图案填充随其边界的改变而更新,非关联图案填充则不会更新。
To edit a hatch boundary, use one of the following methods:
若要编辑图案填充边界,请使用下列方法之一:
To query a hatch boundary, use one of the following methods:
若要查询填充边界,请使用下列方法之一:
This example creates an associative hatch. It then creates a circle and appends the circle as an inner loop to the hatch.
本例创建一个关联的图案填充,然后创建一个圆并将该圆作为内部环附加到图案填充。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
<CommandMethod("EditHatchAppendLoop")> _
Public Sub EditHatchAppendLoop()
'' 获得当前文档和数据库 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 an arc object for the closed boundary to hatch
Dim acArc As Arc = New Arc(New Point3d(5, 3, 0), 3, 0, 3.141592)
acArc.SetDatabaseDefaults()
acBlkTblRec.AppendEntity(acArc)
acTrans.AddNewlyCreatedDBObject(acArc, True)
''创建一个直线对象作为图案填充的闭合边界 Create an line object for the closed boundary to hatch
Dim acLine As Line = New Line(acArc.StartPoint, acArc.EndPoint)
acLine.SetDatabaseDefaults()
acBlkTblRec.AppendEntity(acLine)
acTrans.AddNewlyCreatedDBObject(acLine, True)
''添加圆弧和直线到一个对象编号集合中 Adds the arc and line to an object id collection
Dim acObjIdColl As ObjectIdCollection = New ObjectIdCollection()
acObjIdColl.Add(acArc.ObjectId)
acObjIdColl.Add(acLine.ObjectId)
'' 创建图案填充对象并添加到块表记录中 Create the hatch object and append it to the block table record
Dim acHatch As Hatch = New Hatch()
acBlkTblRec.AppendEntity(acHatch)
acTrans.AddNewlyCreatedDBObject(acHatch, True)
'' 设置图案填充对象的属性 Set the properties of the hatch object
'' 关联性必须在 Hatch 对象追加到块表记录中后,AppendLoop 方法使用之前设置 '' Associative must be set after the hatch object is appended to the
'' block table record and before AppendLoop
acHatch.SetDatabaseDefaults()
acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
acHatch.Associative = True
acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl)
'' 创建一个圆对象作为填充的内部边界 Create a circle object for the inner boundary of the hatch
Dim acCirc As Circle = New Circle()
acCirc.SetDatabaseDefaults()
acCirc.Center = New Point3d(5, 4.5, 0)
acCirc.Radius = 1
acBlkTblRec.AppendEntity(acCirc)
acTrans.AddNewlyCreatedDBObject(acCirc, True)
'' 添加圆到对象编号集合中去 Adds the circle to an object id collection
acObjIdColl.Clear()
acObjIdColl.Add(acCirc.ObjectId)
'' 追加圆作为填充的内部环并计算它 Append the circle as the inner loop of the hatch and evaluate it
acHatch.AppendLoop(HatchLoopTypes.Default, acObjIdColl)
acHatch.EvaluateHatch(True)
'' 保存新对象到数据库中 Save the new object 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("EditHatchAppendLoop")]
public static void EditHatchAppendLoop()
{
// 获得当前文档和数据库 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 an arc object for the closed boundary to hatch
Arc acArc = new Arc(new Point3d(5, 3, 0), 3, 0, 3.141592);
acArc.SetDatabaseDefaults();
acBlkTblRec.AppendEntity(acArc);
acTrans.AddNewlyCreatedDBObject(acArc, true);
// Create an line object for the closed boundary to hatch
Line acLine = new Line(acArc.StartPoint, acArc.EndPoint);
acLine.SetDatabaseDefaults();
acBlkTblRec.AppendEntity(acLine);
acTrans.AddNewlyCreatedDBObject(acLine, true);
// Adds the arc and line to an object id collection
ObjectIdCollection acObjIdColl = new ObjectIdCollection();
acObjIdColl.Add(acArc.ObjectId);
acObjIdColl.Add(acLine.ObjectId);
// 创建图案填充对象并添加到块表记录中 Create the hatch object and append it to the block table record
Hatch acHatch = new Hatch();
acBlkTblRec.AppendEntity(acHatch);
acTrans.AddNewlyCreatedDBObject(acHatch, true);
// Set the properties of the hatch object
// Associative must be set after the hatch object is appended to the
// block table record and before AppendLoop
acHatch.SetDatabaseDefaults();
acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
acHatch.Associative = true;
acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
// Create a circle object for the inner boundary of the hatch
Circle acCirc = new Circle();
acCirc.SetDatabaseDefaults();
acCirc.Center = new Point3d(5, 4.5, 0);
acCirc.Radius = 1;
acBlkTblRec.AppendEntity(acCirc);
acTrans.AddNewlyCreatedDBObject(acCirc, true);
// Adds the circle to an object id collection
acObjIdColl.Clear();
acObjIdColl.Add(acCirc.ObjectId);
// Append the circle as the inner loop of the hatch and evaluate it
acHatch.AppendLoop(HatchLoopTypes.Default, acObjIdColl);
acHatch.EvaluateHatch(true);
// 保存新对象到数据库中 Save the new object to the database
acTrans.Commit();
}
}