You can change the angle or spacing of an existing hatch pattern or replace it with a solid-fill, gradient fill, or one of the predefined patterns that AutoCAD offers. The Pattern option in the Boundary Hatch dialog box displays a list of these patterns. To reduce file size, the hatch is defined in the drawing as a single graphic object.
用户可以修改现有填充图案的角度或间距,也可以将其替换为实体填充、斜线填充图案或 AutoCAD 提供的预定义图案。“边界图案填充”对话框中的“图案”选项显示了这些图案的列表。为了缩小文件的大小,图案填充在图形中被定义为单一的图形对象。
Use the following properties and methods to edit the hatch patterns:
使用以下特性和方法来编辑填充图案:
This example creates a hatch. It then adds two to the current pattern spacing for the hatch.
本例创建一个图案填充,然后将该图案填充的当前图案间距增加 2。
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
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[CommandMethod("EditHatchPatternScale")]
public static void EditHatchPatternScale()
{
// 获得当前文档和数据库 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 boundary of the hatch
Circle acCirc = 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
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);
// Evaluate the hatch
acHatch.EvaluateHatch(true);
// 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();
}
}