AutoCAD Architecture - Select Attribute nested within Multi View Block

Gepaha
Collaborator
Collaborator

AutoCAD Architecture - Select Attribute nested within Multi View Block

Gepaha
Collaborator
Collaborator

I am trying to select an attribute that is nested within a block and this (the block) is in turn nested within the multi view block.

I tried with PromptNestedEntityOptions and GetNestedEntity. I expected the block to return but, the entity returned is the multi view block itself and GetContainers always returns empty.

The code I have is minimal because I haven't been able to proceed yet.

 

 

 

var opt = new PromptNestedEntityOptions("\nSelect an attribute:");
var res = ed.GetNestedEntity(opt);
if (res.Status != PromptStatus.OK)
   return;
using (var tran = res.ObjectId.Database.TransactionManager.StartTransaction())
{
    var ent = (Entity)tran.GetObject(res.ObjectId, OpenMode.ForRead); // always return the multi view block reference
    if (entId.ObjectClass.DxfName.ToUpper() != "ATTRIB")
    {
        var ids = res.GetContainers();
        if (ids.Length > 0) // always is empty
        {                           
            // .......               
        }
    }
    tran.Commit();
}

 

 

 

 

If anyone can hel I am grateful. 😀

Reply
724 Views
2 Replies
Replies (2)

marcin.sachs
Advocate
Advocate

Hi,
Please see below method

[CommandMethod("MultiViewBlockAttributes")]
        public static void MultiViewBlockAttributes()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            var opt = new PromptSelectionOptions();
            opt.MessageForAdding = "\nSelect Multi-View Block";
            PromptSelectionResult res = ed.GetSelection(opt);
            if (res.Status == PromptStatus.OK)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    
                    foreach (SelectedObject selected in res.Value)
                    {
                        Autodesk.Aec.DatabaseServices.MultiViewBlockReference multiViewBlockRef= tr.GetObject(selected.ObjectId, OpenMode.ForRead) as Autodesk.Aec.DatabaseServices.MultiViewBlockReference;
                        if (multiViewBlockRef.HasAttributes)
                        {
                            Autodesk.Aec.DatabaseServices.MultiViewBlockViewInstanceCollection views = multiViewBlockRef.ViewInstances;

                            foreach (Autodesk.Aec.DatabaseServices.MultiViewBlockViewInstance view in views)
                            {
                                Autodesk.Aec.DatabaseServices.MultiViewBlockAttributeReferenceCollection atts = view.AttributeReferences;
                                foreach (Autodesk.Aec.DatabaseServices.MultiViewBlockAttributeReference att in atts)
                                {

                                    ed.WriteMessage("\nAttribute: " + att.Prompt + " Value: " + att.Attribute.TextString);
                                }
                            }
                        }
                    }
                    tr.Commit();
                }
            }

        }

    }

 

 

Gepaha
Collaborator
Collaborator

Thank you very much for responding.

In reality my goal is to get the attribute reference directly by clicking on the attribute by pick as it is possible to do it directly with block reference, using GetNestedEntity.

The multi view block reference has several attributes embedded in the block reference and in this case I wish the user to be able to choose the attribute.

In a way, I managed to solve this by going through the entities inside the reference block, checking the coordinate. But, I would like a better, cleaner solution, without so many contours. 

I'm glad you paid attention to my post and replied.

 

0 Likes