既存のハッチング パターンの角度や間隔は変更でき、それを塗り潰しやグラデーション塗り潰し、または AutoCAD が提供する定義済みパターンの 1 つに置き換えることができます。[境界ハッチング]ダイアログ ボックスの[パターン]オプションまたはリボンの[パターン]ギャラリーには、これらのパターンのリストが表示されます。ファイル サイズを小さくするために、図面中でハッチングは 1 つのグラフィックス オブジェクトとして定義されます。
ハッチング パターンを変更するには、次のプロパティとメソッドを使用します。
ハッチングのグラデーション角度を指定します。
ハッチングのグラデーション名を返します。
ハッチングのグラデーション シフトを指定します。
ハッチングのグラデーション タイプを返します。
ハッチング パターンの角度(ラジアン単位)を指定します。
ユーザ定義ハッチングがダブル ハッチングかどうかを指定します。
ハッチングのハッチング パターン名を返します(ハッチングのハッチング パターンの名前とタイプを設定するには、SetHatchPattern メソッドを使用します)。
ハッチング パターンの尺度を指定します。
ユーザ定義ハッチング パターンの間隔を指定します。
ハッチングのハッチング パターン タイプを返します(ハッチングのハッチング パターンの名前とタイプを設定するには、SetHatchPattern メソッドを使用します)。
ハッチングのグラデーション タイプと名前を設定します。
ハッチングのパターン タイプと名前を設定します。
次の例は、ハッチングを作成します。次に、ハッチングの現在のパターン間隔に 2 を追加します。
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
using (Circle acCirc = new Circle())
{
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
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);
// 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();
}
}