- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("CreateAssocHatch","cash", CommandFlags.UsePickSet)]
public void testCreateAssocHatch()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId objId;
Entity ent;
PromptEntityResult per = ed.GetEntity(new PromptEntityOptions("\nSelect an entity to be hatched: "));
if (per.Status != PromptStatus.OK) return;
objId = per.ObjectId;
try
{
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
ent = tr.GetObject(objId, OpenMode.ForRead) as Entity;
if (ent == null) return;
Hatch hat = new Hatch();
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);
// to set associative add hatch first
btr.AppendEntity(hat);
tr.AddNewlyCreatedDBObject(hat, true);
hat.PatternAngle = 0.0;
hat.PatternScale = 10.0;
hat.Associative = true;
hat.SetHatchPattern(HatchPatternType.PreDefined, "ANSI32");
// append loop to hatch
ObjectIdCollection dbObjIds = new ObjectIdCollection();
dbObjIds.Add(objId);
hat.AppendLoop(HatchLoopTypes.External, dbObjIds);
hat.Layer = ent.Layer;
hat.ColorIndex = 256;//bylayer, may use as per entity colorindex
hat.HatchStyle = HatchStyle.Normal;
hat.EvaluateHatch(true);
tr.Commit();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage("Error: {0}", ex.ToString());
}
} |
|