定义填充边界
 
 

Once the Hatch object is created, the hatch boundaries can be added. Boundaries can be any combination of lines, arcs, circles, 2D polylines, ellipses, splines, and regions.

一旦 Hatch 对象被创建,就可以添加图案填充边界。边界可以是直线、圆弧、圆、二维多段线、椭圆、样条曲线和面域的任意组合。

The first boundary added must be the outer boundary, which defines the outermost limits to be filled by the hatch. To add the outer boundary, use the AppendLoop method with the HatchLoopTypes.Outermost constant for the type of loop to append.

添加的第一个边界必须是外边界,即用于定义图案填充最外面的边界。要添加外部边界,请使用添加环的类型为 HatchLoopTypes.Outermost 常量的 AppendLoop 方法。

Once the outer boundary is defined, you can continue adding additional boundaries. Add inner boundaries using the AppendLoop method with the HatchLoopTypes.Default constant.

一旦外边界被定义,就可以继续添加另外的边界。添加内部边界请使用带 HatchLoopTypes.Default 常量的 AppendLoop 方法。

Inner boundaries define islands within the hatch. How these islands are handled by the Hatch object depends on the setting of the HatchStyle property. The HatchStyle property can be set to one of the following conditions:

内边界定义图案填充内的孤岛。Hatch 对象处理这些孤岛的方式取决于 HatchStyle 属性的设置。HatchStyle 属性可以设置为以下状态:

图案填充样式定义

HatchStyle

状态

说明

Normal

(HatchStyle.Normal)

Specifies standard style, or normal. This option hatches inward from the outermost area boundary. If AutoCAD encounters an internal boundary, it turns off hatching until it encounters another boundary. This is the default setting for the HatchStyle property.

指定标准的样式,即普通。此选项从最外面的区域边界向内进行图案填充。如果 AutoCAD 遇到内部边界,将停止填充,直到遇到另一个内部边界。这是 HatchStyle 属性的默认设置。

Outer

(HatchStyle.Outer)

Fills the outermost areas only. This style also hatches inward from the area boundary, but it turns off hatching if it encounters an internal boundary and does not turn it back on again.

仅填充最外面的区域。此样式也是从最外面的区域边界向内进行图案填充,但是遇到内部边界时会关闭图案填充并且不再打开。

Ignore

(HatchStyle.Ignore)

Ignores internal structure. This option hatches through all internal objects.

忽略内部结构。此选项使图案填充通过所有的内部对象。

When you have finished defining the hatch it must be evaluated before it can be displayed. Use the EvaluateHatch method to do this.

定义完图案填充之后,必须先对其进行计算,然后才能显示。请使用 EvaluateHatch 方法完成此任务。

创建 Hatch 对象

The following example creates an associated hatch in Model space. Once the hatch has been created, you can change the size of the circle that the hatch is associated with. The hatch will change to match the size of the circle.

本例在模型空间中创建关联的图案填充。创建图案填充后,可以修改与图案填充关联的圆的大小。图案填充将自动改变以匹配圆的当前大小。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("AddHatch")> _
Public Sub AddHatch()
  '' 获得当前文档和数据库   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 circle object for the closed boundary to hatch
      Dim acCirc As Circle = New Circle()
      acCirc.SetDatabaseDefaults()
      acCirc.Center = New Point3d(3, 3, 0)
      acCirc.Radius = 1
 
      '' 添加新的圆对象到块表记录和事务中   Add the new circle object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acCirc)
      acTrans.AddNewlyCreatedDBObject(acCirc, True)
 
      '' 添加圆到一个 ObjectID 数组中去    Adds the circle to an object id array
      Dim acObjIdColl As ObjectIdCollection = New ObjectIdCollection()
      acObjIdColl.Add(acCirc.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
      '' 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)
      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("AddHatch")]
public static void AddHatch()
{
  // 获得当前文档和数据库   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 circle object for the closed boundary to hatch
      Circle acCirc = new Circle();
      acCirc.SetDatabaseDefaults();
      acCirc.Center = new Point3d(3, 3, 0);
      acCirc.Radius = 1;
 
      // 添加新的圆对象到块表记录和事务中   Add the new circle object to the block table record and the transaction
      acBlkTblRec.AppendEntity(acCirc);
      acTrans.AddNewlyCreatedDBObject(acCirc, true);
 
      // 添加圆到一个 ObjectID 数组中去    Adds the circle to an object id array
      ObjectIdCollection acObjIdColl = new ObjectIdCollection();
      acObjIdColl.Add(acCirc.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);
      acHatch.EvaluateHatch(true);
 
      // 保存新对象到数据库中   Save the new object to the database
      acTrans.Commit();
  }
}
VBA/ActiveX 代码参考