- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("DOinBlock")]
public static void RunMyCommand()
{
Document dwg = Application.DocumentManager.MdiActiveDocument;
Editor ed = dwg.Editor;
//Ask user to select a block. In real world, I use code
//to select all targeting blocks by its name, so that
//user does not have to select block manually
PromptEntityOptions opt = new PromptEntityOptions(
"nSelect a block:");
opt.SetRejectMessage("\nInvalid: not a block.");
opt.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult res = ed.GetEntity(opt);
if (res.Status == PromptStatus.OK)
{
SetDrawOrderInBlock(dwg, res.ObjectId);
ed.Regen();
}
else
{
ed.WriteMessage("\n*Cancel*");
}
Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt();
}
private static void SetDrawOrderInBlock(Document dwg, ObjectId blkId)
{
using (Transaction tran = dwg.TransactionManager.StartTransaction())
{
BlockReference bref = (BlockReference)tran.GetObject(blkId, OpenMode.ForRead);
BlockTableRecord bdef = (BlockTableRecord)tran.GetObject(bref.BlockTableRecord, OpenMode.ForWrite);
DrawOrderTable doTbl = (DrawOrderTable)tran.GetObject(bdef.DrawOrderTableId, OpenMode.ForWrite);
ObjectIdCollection col = new ObjectIdCollection();
foreach (ObjectId id in bdef)
{
if (id.ObjectClass.DxfName.ToUpper() == "HATCH")
{
col.Add(id);
}
}
if (col.Count > 0)
{
doTbl.MoveToBottom(col);
}
tran.Commit();
}
}
|
|