.NET

Reply
Active Contributor
anikakramer2006
Posts: 29
Registered: ‎03-23-2011
Message 1 of 3 (153 Views)
Accepted Solution

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

153 Views, 2 Replies
08-13-2013 10:12 PM

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 :smileysurprised:)

 

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();
            }
        }

Valued Mentor
jeff
Posts: 322
Registered: ‎05-12-2009
Message 2 of 3 (148 Views)

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

08-13-2013 10:32 PM 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
Active Contributor
anikakramer2006
Posts: 29
Registered: ‎03-23-2011
Message 3 of 3 (144 Views)

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

08-13-2013 10:49 PM 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! :smileysurprised:)

Have a nice day,

 

Anika

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community