ハッチング オブジェクトを作成したら、ハッチング境界線を追加することができます。境界線は、線分、円弧、円、2D ポリライン、楕円、スプライン、およびリージョンを組み合わせて構成できます。
追加する最初の境界線は、ハッチングで塗り潰される最も外側の境界を定義する外側境界線です。外側境界線を追加するには、追加するループのタイプの HatchLoopTypes 定数を指定して AppendLoop メソッドを使用します。
外側境界線を定義したら、続いて境界線を追加できます。HatchLoopTypes.Default 定数を指定して AppendLoop メソッドを使用して、内側境界線を追加します。
内側境界線は、ハッチング内の島を定義します。これらの島をハッチング オブジェクトが処理する方法は、HatchStyle プロパティの設定によって異なります。HatchStyle プロパティは、次のいずれかの条件に設定できます。
|
ハッチング スタイルの定義 |
||
|---|---|---|
|
ハッチング スタイル |
条件 |
説 明 |
|
|
標準 (HatchStyle.Normal) |
標準スタイルを指定します。このオプションは、外側境界線の内側をハッチングします。AutoCAD は内側にある境界に達すると、さらに内側の境界を見つけるまでハッチングをオフにします。これは、HatchStyle プロパティの既定の設定です。 |
|
|
外側のみ (HatchStyle.Outer) |
外側領域のみを塗り潰します。このスタイルは、領域境界線から内側もハッチングしますが、内部境界線を検出するとハッチングをオフにし、再びオンにすることはありません。 |
|
|
内側含む (HatchStyle.Ignore) |
内部構造を無視します。このオプションはすべての内部オブジェクトをハッチングします。 |
ハッチングは、定義後に評価しないと表示できません。評価するには EvaluateHatch メソッドを使います。
次の例は、モデル空間に関連付けられたハッチングを作成します。作成後は、ハッチングが結合されている円の大きさを変更できます。ハッチングは円のサイズに合わせて変更されます。
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
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
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();
}
}
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