[求助]查看当前模型空间是否存在指定名称的块,必须是当前空间
本帖最后由 作者 于 2010-4-13 14:11:36 编辑 <br /><br /> <table cellspacing="0" cellpadding="0"><tbody><tr><td class="t_msgfont" id="postmessage_19012">查看当前模型空间是否存在指定名称(如“01”)的块,必须是当前空间。并记录块的基点坐标。怎么实现啊?请高手解答下</td></tr></tbody></table>public static void Test()
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = Application.DocumentManager.GetDocument(db);
Editor ed = doc.Editor;
PromptResult resName = ed.GetString("\n请输入块名:");
if (resName.Status != PromptStatus.OK)
return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = db.CurrentSpaceId.GetObject(OpenMode.ForRead) as BlockTableRecord;
Layout layout = btr.LayoutId.GetObject(OpenMode.ForRead) as Layout;
SelectionFilter filter =
new SelectionFilter
(
new TypedValue[]
{
new TypedValue(0, "Insert"),
new TypedValue(2, resName.StringResult),
new TypedValue(410, layout.LayoutName),
}
);
var resSel = ed.SelectAll(filter);
if (resSel.Status != PromptStatus.OK)
return;
int i = 0;
foreach (ObjectId id in resSel.Value.GetObjectIds())
{
BlockReference blkref = id.GetObject(OpenMode.ForRead) as BlockReference;
ed.WriteMessage("\n找到第{0}个,基点:{1}", ++i, blkref.Position);
}
}
}
<p>不错``分享`了``</p><p></p><p></p><p></p><p></p><p></p><p></p><p></p><p>http://xy2.netease.com/images/default/sigline.gif<br/>酒神酒神 阴阳冕禁血红莲邪龙道邪龙道仙葫步步生莲猎国猎国傲剑凌云武神阳神斗铠九鼎记斗破苍穹傲剑凌云武神阳神斗铠九鼎记斗破苍穹御医寂灭天骄冠军传奇天下无双十方天士长生界凡人修仙传全文阅读禁血红莲步步生莲御医寂灭天骄天才医生天下无双十方天士长生界凡人修仙传吧仙葫异世邪君</p> <p>收到</p><p></p>
页:
[1]