.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get all MLeaders, even in Blocks nested ones?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
anikakramer2006
499 Views, 2 Replies

How to get all MLeaders, even in Blocks nested ones?

Hello alltogether,

 

I need to EnableFrameText to all MLeaders in a drawing,

I also want to get the MLeaders who are nested in Blocks

automatically...

I started this way but It just works fine with the Mleaders in Modelspace

or if I open the Blockeditor to edit Mleaders nested in a Block...

I know I'm not going to "deep", maybe I need an other Transaction,

or thirst open each Block to edit... not right sure...

maybe I'm on a wrong way, absolutely...

can somebody help me?

 

Thank you :O)

 

my example:

 

        //Ändert leider nur die MLeader die nicht in einem Block sind....

        [CommandMethod("MLeaderIterator")]
        public static void MLeaderIterator_Method()
        {
            Database database = HostApplicationServices.WorkingDatabase;
            using (Transaction transaction = database.TransactionManager.StartTransaction())
            {
                BlockTable blkTable = (BlockTable)transaction.GetObject(database.BlockTableId, OpenMode.ForRead);
                BlockTableRecord btRecord = (BlockTableRecord)transaction.GetObject(blkTable[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                    
                foreach(ObjectId id in btRecord)
                {

                    if(id.ObjectClass.IsDerivedFrom(RXClass.GetClass(typeof(MLeader))))
                    {
                        MLeader _mLeader = (MLeader)transaction.GetObject(id, OpenMode.ForRead);
                        if (_mLeader.EnableFrameText == true)
                            _mLeader.UpgradeOpen();
                            _mLeader.EnableFrameText = false;
                            _mLeader.TextColor = Color.FromColorIndex(ColorMethod.ByColor, 240);
                            _mLeader.DowngradeOpen();
                    }
                
                }
                transaction.Commit();
            }
        }

2 REPLIES 2
Message 2 of 3
jeff
in reply to: anikakramer2006

Just iterate all BlockTableRecords in the BlockTable.

 

A 45 second refactor from previous snippet

 

       [CommandMethod("MLeaderIterator")]
       public static void MLeaderIterator_Method()
       {
           IntPtr mleaderPtr = RXClass.GetClass(typeof(MLeader)).UnmanagedObject;
           Database database = HostApplicationServices.WorkingDatabase;
           using (Transaction transaction = database.TransactionManager.StartTransaction())
           {
               BlockTable blkTable = (BlockTable)transaction.GetObject(database.BlockTableId, OpenMode.ForRead);

               foreach (ObjectId btRecordId in blkTable)
               {
                   BlockTableRecord btRecord = (BlockTableRecord)transaction.GetObject(btRecordId, OpenMode.ForRead);
                   if (!(btRecord.IsDependent || btRecord.IsFromExternalReference || btRecord.IsAProxy))
                   {
                       foreach (ObjectId id in btRecord)
                       {

                           if (id.ObjectClass.UnmanagedObject == mleaderPtr)
                           {
                               MLeader _mLeader = (MLeader)transaction.GetObject(id, OpenMode.ForRead);
                               if (_mLeader.EnableFrameText == true)
                               {
                                   _mLeader.UpgradeOpen();
                                   _mLeader.EnableFrameText = false;
                                   _mLeader.TextColor = Color.FromColorIndex(ColorMethod.ByColor, 240);
                               }
                           }
                       }
                   }
               }
               transaction.Commit();
           }
       }

 

You can also find your answers @ TheSwamp
Message 3 of 3
anikakramer2006
in reply to: jeff

Good Morning,

wow, with an blink of an eye...

it worked perfect!

The only thing I had to add on the end of the transaction was:

 

Application.DocumentManager.MdiActiveDocument.Editor.Regen();

 

so the frames of the MLeaders are all gone.

 

Thank you so much!

This example will also help me for other selections.

Big help! :O)

Have a nice day,

 

Anika

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost