用户可以编辑图案填充边界和填充图案。如果编辑关联图案填充的边界,只要编辑的结果是有效的边界,图案就会被更新。即使关联图案填充位于已关闭的图层上,仍将对其进行更新。用户可以修改填充图案或为现有的图案填充选择新的图案,但是只能在创建图案填充时设置关联性。可以使用 Associative 特性查看 Hatch 对象是否具有关联性。

必须使用 EvaluateHatch 方法重新计算图案填充才能看到任何图案填充的编辑效果。

编辑填充边界

可以向图案填充边界附加、插入或移除环。关联图案填充随其边界的改变而更新,非关联图案填充则不会更新。

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

  • AppendLoop
  • 将一个环追加到图案填充。用户使用 AppendLoop 方法的第一个参数和 HatchLoopTypes 枚举常量定义所追加环的类型。

  • GetLoopAt
  • 获得图案填充指定索引处的环。

  • InsertLoopAt
  • 插入一个环到图案直译的指定索引处。

  • RemoveLoopAt
  • 从图案填充指定索引处删除一个环。

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

  • LoopTypeAt
  • 获得图案填充指定索引处的环的类型。

  • NumberOfLoops
  • 返回图案填充的环的数量。

将内部环附加到图案填充

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

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

编辑填充图案

用户可以修改现有填充图案的角度或间距,也可以将其替换为实体填充、斜线填充图案或 AutoCAD 提供的预定义图案。“边界图案填充”对话框中的“图案”选项显示了这些图案的列表。为了缩小文件的大小,图案填充在图形中被定义为单一的图形对象。

使用以下特性和方法来编辑填充图案:


  • GardientAngle
  • 指定填充图案的角度。

  • GardientName
  • 指定填充倾斜的名称。

  • GardientShift
  • 指定填充倾斜间距

  • GardientType
  • 返回填充的倾斜类型

  • PatternAngle
  • 指定填充图案的角度

  • PatternDouble
  • 指定用户定义的图案填充是否双向填充。

  • PatternName
  • 返回填充的填充图案的名称(使用 SetHatchPattern 方法使用填充图案的名称和图案的类型)。

  • PatternScale
  • 指定填充图案的缩放比例

  • PatternSpace
  • 指定用户定义的填充图案间距。

  • PatternType
  • 返回填充的填充图案类型。(使用 SetHatchPattern 方法设置填充的填充图案名称和类型。)

  • SetGradient
  • 设置图案的倾斜类型和名称。

  • SetHatchPattern
  • 设置填充的图案类型和名称。

修改填充的图案间距

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("EditHatchPatternScale")> _
Public Sub EditHatchPatternScale()
  '' 获得当前文档和数据库   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 boundary of the hatch
      Dim acCirc As Circle = New Circle()
      acCirc.SetDatabaseDefaults()
      acCirc.Center = New Point3d(5, 3, 0)
      acCirc.Radius = 3
 
      acBlkTblRec.AppendEntity(acCirc)
      acTrans.AddNewlyCreatedDBObject(acCirc, True)
 
      '' 添加圆弧和直线到对象编号集合中去  Adds the arc and line to an object id collection
      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)
 
      '' 设置Hatch 对象的属性  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)
 
      ''计算填充   Evaluate the hatch
      acHatch.EvaluateHatch(True)
 
      ''图案比例增加2 并重算图案   Increase the pattern scale by 2 and re-evaluate the hatch
      acHatch.PatternScale = acHatch.PatternScale + 2
      acHatch.SetHatchPattern(acHatch.PatternType, acHatch.PatternName)
      acHatch.EvaluateHatch(True)
 
      '' 保存新对象到数据库中   Save the new object to the database
      acTrans.Commit()
  End Using
End Sub