- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I'm running into the problem that I can't find out what types of blockrefs (by name) are positioned where in an associative array. No matter what I seem to do, I get an anonymous blockref name. However, when I explode the block in the drawing manually, the underlying blocks all have the correct name, so the data should be somewhere. This data is needed to automatically count the number of certain blocks in a drawing with arrays.
As a workaround currently I use sourceEntities, but that has as a drawback that I have to assume that the full array consists of a single type of blockref. If one of the entities is replaced this method no longer works accurately.
It would be really great if someone can help me find out how to get the block names. To start off, I created a minimal coding examples shown below and I've also attached an example drawing with the type of array I'm looking to investigate.
Any help is more than welcome.
code:
[CommandMethod("ArrayTest")]
public static void ArrayTest()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
using (Transaction transaction = doc.Database.TransactionManager.StartTransaction())
{
TypedValue[] filterList = new TypedValue[1];
filterList[0] = new TypedValue(0, "INSERT");
SelectionFilter filter = new SelectionFilter(filterList);
PromptSelectionResult result = doc.Editor.SelectAll(filter);
if (result.Status == PromptStatus.OK)
{
foreach (ObjectId objectId in result.Value.GetObjectIds())
{
if (AssocArray.IsAssociativeArray(objectId))
{
AssocArray Array = AssocArray.GetAssociativeArray(objectId);
Autodesk.AutoCAD.DatabaseServices.Entity arrayEntity = transaction.GetObject(Array.EntityId, OpenMode.ForWrite) as Autodesk.AutoCAD.DatabaseServices.Entity;
AssocArrayPathParameters Arrayparams = Array.GetParameters() as AssocArrayPathParameters;
Curve3d arrayPath = Arrayparams.Path.Curve;
//open assocArray as blockref so you can explode
using (BlockReference assocBlockRef = objectId.GetObject(OpenMode.ForWrite) as BlockReference)
{
using (DBObjectCollection blockRefs = new DBObjectCollection())
{
assocBlockRef.Explode(blockRefs);
if (blockRefs != null && blockRefs.Count > 0)
{
foreach (BlockReference blockref in blockRefs)
{
doc.Editor.WriteMessage("\nBlockref.Name: {0}\n", blockref.Name);
}
}
}
}
}
}
}
transaction.Commit();
}
}
Solved! Go to Solution.