Author Topic: How to update attribute inside mleader?  (Read 1774 times)

0 Members and 1 Guest are viewing this topic.

aiman

  • Mosquito
  • Posts: 3
How to update attribute inside mleader?
« on: August 05, 2012, 08:38:14 PM »
I have lots multileaders with block and attributes in my drawing.
What I want to do is to go through all objects in the drawing and then update the attribute of multileaders.
I know C# a little, here is my code, does anybody know how to do this?

Code: [Select]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

namespace Update_Mleader
{
    public class Update_Mleader
    {
        [CommandMethod("UpdateMleaderAttr")]
        public void UpdateMleader()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);

                foreach (ObjectId entId in btr)
                {
                   
                    Entity ent = tr.GetObject(entId, OpenMode.ForRead) as Entity;
                    if (ent != null)
                    {
                        if (ent.GetType() == typeof(MLeader))
                        {
                            // how to update the attribute of the mleader?
                            // example, if the attribute Tag is "XCODE"
                            // and i want to update the TextString to "100"
                        }
                    }
                }
                tr.Commit();
            }
            ed.Regen();
        }
    }
}

BlackBox

  • King Gator
  • Posts: 3770
Re: How to update attribute inside mleader?
« Reply #1 on: August 05, 2012, 11:23:36 PM »
Rather than iterating the entire Database, consider using the PromptSelectionOptions to iterate a valid selection set based on a specified section filter.

Not sure if there's a Method to handle changes globally, otherwise you'd need to iterate each entity to modify nested entities as applicable (I.e, FieldCode, attribute's TextString, etc). 

HTH
"How we think determines what we do, and what we do determines what we get."

fixo

  • Guest
Re: How to update attribute inside mleader?
« Reply #2 on: August 06, 2012, 12:31:30 AM »
I have lots multileaders with block and attributes in my drawing.
What I want to do is to go through all objects in the drawing and then update the attribute of multileaders.
I know C# a little, here is my code, does anybody know how to do this?

Quote
                            // how to update the attribute of the mleader?
                            // example, if the attribute Tag is "XCODE"
                            // and i want to update the TextString to "100"
                   

Try this code:
http://www.acadnetwork.com/topic-210.msg381.html#msg381

~'J'~