Hello guys,
I successfully wrote the following codes on my won
but I faced a problem with Dynamic Block Name , so how to get the anonymous block name ?
Feel free to comment the codes cause I am on the way learning codes in C#
static public void JustAtest()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Dictionary
<string,
int> dic
= new Dictionary
<string,
int>(); TypedValue
[] val
= { new TypedValue
((int)DxfCode
.Start,
"INSERT") }; SelectionFilter ftr
= new SelectionFilter
(val
); PromptSelectionResult ss = ed.GetSelection(ftr);
if (ss.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
BlockReference ent;
foreach (ObjectId id in ss.Value.GetObjectIds())
{
ent = tr.GetObject(id, OpenMode.ForRead) as BlockReference;
string BlockName = ent.Name;
if (dic.ContainsKey(BlockName))
{
int n = 1 + dic[BlockName];
dic.Remove(BlockName);
dic.Add(BlockName, n);
}
else
{
dic.Add(BlockName, 1);
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
return;
}
}
if (dic.Count > 0)
{
ed.WriteMessage("\nBlock Name: [Quantity]");
foreach (KeyValuePair<string, int> item in dic)
{
ed.WriteMessage("\n" + item.Key + " ----- [ " + item.Value + " ]");
}
}
}
}
Thank you.