for info:
response from
https://forums.autodesk.com/t5/net/how-to-explode-dimstyle-with-net/m-p/12213503/thread-id/78487[CommandMethod("EXPDim")]
public void ExplodeDimensions()
{
Document doc = CadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
RXClass @
class = RXObject
.GetClass(typeof(Dimension
)); DBObjectCollection explodedObjects
= new DBObjectCollection
();
PromptEntityOptions peo
= new PromptEntityOptions
( "\nSelect a dimension to explode : ");
peo.SetRejectMessage($"Selected object is not an {@class.Name}");
peo
.AddAllowedClass(typeof(Dimension
), exactMatch
: false);
bool finished = false;
while (!finished)
{
PromptEntityResult result = ed.GetEntity(peo);
if (result.Status != PromptStatus.OK)
{
finished = true;
return;
}
using (var tr = db.TransactionManager.StartOpenCloseTransaction())
{
explodedObjects.Clear();
Entity ent = (Entity)tr.GetObject(
result.ObjectId,
OpenMode.ForRead);
ent.Explode(explodedObjects);
// optional (EraseOriginal(ed))
//
if (explodedObjects.Count > 0 )
{
ent.UpgradeOpen();
ent.Erase();
}
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(
db.CurrentSpaceId,
OpenMode.ForWrite);
foreach (DBObject obj in explodedObjects)
{
Entity explodedEntity = (Entity)obj;
if(explodedEntity
is MText
) {
// just for giggles, to visually identify dimensions processed.
explodedEntity.ColorIndex = 211;
}
btr.AppendEntity(explodedEntity);
tr.AddNewlyCreatedDBObject(explodedEntity, true);
}
tr.Commit();
}
}
}
internal bool EraseOriginal(Editor ed)
{
PromptKeywordOptions pko
= new PromptKeywordOptions
("\nErase original objects?") {
AllowNone = true
};
pko.Keywords.Add("Yes");
pko.Keywords.Add("No");
pko.Keywords.Default = "Yes";
PromptResult pkr = ed.GetKeywords(pko);
if (pkr.Status != PromptStatus.OK) return false;
return (pkr.StringResult == "Yes");
}
>>>>
Perhaps have a play with this.
The PromptEntityOptions will select anything derived from Dimension.
Will be fairly simple to modify if you want to select multiple objects at one time.
This routine has had minimal testing, so review the code and test.
Regards,
added:
I've used a single entity selection cycle for this ,
because I don't see the use-case for having a multi-select option,
Can anyone offer a use-case for exploding multiple dimensions ??
Seems to me it bashes the integrity resulting from 'conventional' associative dimensions.