获取动态块名
大家好,我成功地在我的WIN上编写了以下代码,但我遇到了动态块名的问题,所以如何获得匿名块名
请随意评论代码,因为我正在学习C#
中的代码
{
Document doc=Application.DocumentManager.MdiActiveDocument
数据库db=doc.Database
编辑器ed=doc.Editor
字典
dic=newdictionary
()
TypedValue[]val={newtypedvalue((int)DxfCode.Start,“INSERT”)}
SelectionFilter-ftr=新的selectionfiller(val)
PromptSelectionResult ss=ed.GetSelection(ftr)
如果(ss.Status==PromptStatus.OK)
{
使用(Transaction tr=db.TransactionManager.StartTransaction())
{
试试
{
blockent
foreach(ss.Value.getObjectId()中的ObjectId)
{
ent=tr.GetObject(id,OpenMode.ForRead)作为BlockReference
字符串BlockName=ent.Name
if(dic.ContainsKey(BlockName))
{
int n=1+dic
dic.Remove(BlockName)
dic。添加(BlockName,n)
}
其他
{
dic。添加(BlockName,1)
}
}
}
捕获(System.Exception.ex)
{
ed.WriteMessage(例如Message)
返回
}
}
如果(dic.Count>0)
{
ed.WriteMessage(“\n块名:[数量]”)
foreach(dic中的KeyValuePair
项)
{
ed.WriteMessage(“\n”+item.Key+”------[“+item.Value+”])
}
}
}
}
谢谢。
**** Hidden Message ***** 嗨,公共静态字符串GeteffectiveName(Block参考源)。
{。
如果(source.IsDynamicBlock)。
返回((BlockTableRecords)source.DynamicBlockTableRecord.GetObject(OpenMode.ForRead)),名称;。
返回source.Name;。
}。
很好,
非常感谢gile。
页:
[1]