编辑填充边界
 
 

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:

若要编辑图案填充边界,请使用下列方法之一:

AppendLoop

Appends a loop to the hatch. You define the type of loop being appended with first parameter of the AppendLoop method and the constants defined by the HatchLoopTypes enum.
将一个环追加到图案填充。用户使用 AppendLoop 方法的第一个参数和 HatchLoopTypes 枚举常量定义所追加环的类型。

GetLoopAt

Gets the loop at a given index of a hatch.
获得图案填充指定索引处的环。

InsertLoopAt

Inserts a loop at a given index of a hatch.
插入一个环到图案直译的指定索引处。

RemoveLoopAt

Deletes a loop at a given index of a hatch.
从图案填充指定索引处删除一个环。

To query a hatch boundary, use one of the following methods:

若要查询填充边界,请使用下列方法之一:

LoopTypeAt

Gets the type of loop at a given index of a hatch.
获得图案填充指定索引处的环的类型。

NumberOfLoops

Gets the number of loops of a hatch.
返回图案填充的环的数量。

将内部环附加到图案填充

This example creates an associative hatch. It then creates a circle and appends the circle as an inner loop to the hatch.

本例创建一个关联的图案填充,然后创建一个圆并将该圆作为内部环附加到图案填充。

VB.NET

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

C#

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();
  }
}
VBA/ActiveX 代码参考