创建 Hatch 对象后,可以添加填充边界。边界可以是直线、圆弧、圆、二维折线、椭圆、样条和区域的任意组合。 添加的第一个边界必须是外部边界,该边界定义了要由填充填充的最外层限制。若要添加外部边界,请使用带有常量的方法,作为要追加的循环类型。AppendLoopHatchLoopTypes.Outermost 定义外部边界后,可以继续添加其他边界。使用带有常量的方法添加内部边界。AppendLoopHatchLoopTypes.Default 内部边界定义了舱口内的岛屿。Hatch 对象如何处理这些岛屿取决于属性的设置。该属性可以设置为下列条件之一:HatchStyleHatchStyle
完成填充定义后,必须先对其进行评估,然后才能显示它。使用该方法执行此操作。EvaluateHatch 创建 Hatch 对象以下示例在模型空间中创建关联的填充线。创建填充后,可以更改与填充关联的圆的大小。填充将更改以匹配圆的大小。 VB.NETImports 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
Using acCirc As Circle = New Circle()
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)
'' 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
Using 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.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31")
acHatch.Associative = True
acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl)
acHatch.EvaluateHatch(True)
End Using
End Using
'' 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
using (Circle acCirc = new Circle())
{
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);
// 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
using (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.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 代码参考Sub AddHatch()
Dim hatchObj As AcadHatch
Dim patternName As String
Dim PatternType As Long
Dim bAssociativity As Boolean
' Define the hatch
patternName = "ANSI31"
PatternType = 0
bAssociativity = True
' Create the associative Hatch object
Set hatchObj = ThisDrawing.ModelSpace.AddHatch _
(PatternType, patternName, bAssociativity)
' Create the outer boundary for the hatch. (a circle)
Dim outerLoop(0 To 0) As AcadEntity
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 3: center(1) = 3: center(2) = 0
radius = 1
Set outerLoop(0) = ThisDrawing.ModelSpace. _
AddCircle(center, radius)
' Append the outerboundary to the hatch
' object, and display the hatch
hatchObj.AppendOuterLoop (outerLoop)
hatchObj.Evaluate
ThisDrawing.Regen True
End Sub
相关概念父主题: | |||||||||||||||
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 09:48
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.