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();
}
}
Solved! Go to Solution.
Solved by jeff. Go to Solution.
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(); } }
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