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

How to Explode DimStyle with .Net

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
ootsuka109
307 Views, 5 Replies

How to Explode DimStyle with .Net

I'm trying to make software that uses .NET(c#) to explode dimension objects only.

 but I can't think of a good idea.

Is there anyone help me?

 

5 REPLIES 5
Message 2 of 6
kdub_nz
in reply to: ootsuka109

public abstract class Dimension : Entity

 

10 Dimension types are derived from Dimension.

Entity is explodable

public void Explode(DBObjectCollection entitySet)
{ }



Have you tried Explode ??

 

I haven't tried it, but you should . . . because someone will ask for sure 🙂

 

Regards,


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 3 of 6
kdub_nz
in reply to: ootsuka109

This is worth a read.
https://www.keanw.com/2011/02/exploding-autocad-objects-using-net.html


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 4 of 6
kdub_nz
in reply to: ootsuka109

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.

 

 

 

 

[CommandMethod("EXPDim")]

public void ExplodeDimensions()
{
   Document doc = CadApp.DocumentManager.MdiActiveDocument;
   Database db = doc.Database;
   Editor ed = doc.Editor;

   RXClass rxClass = RXObject.GetClass(typeof(Dimension));
   DBObjectCollection explodedObjects = new DBObjectCollection();

   PromptEntityOptions peo = new PromptEntityOptions(
      "\nSelect a dimension to explode : ");
   peo.SetRejectMessage($"Selected object is not an {rxClass.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");
}

 

 

 

modified note 20230904:

changed variable name @class to rxClass because the post software here didn't display @class

 

This routine has had minimal testing, so review the code and test.

Regards,

 


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 5 of 6
ootsuka109
in reply to: kdub_nz

Thank you  for your help.

According your adivise , I could make a code.

I'm sorry for not being able to convey my thanks properly because I'm not good at English.

Message 6 of 6
kdub_nz
in reply to: ootsuka109

 

Pleased I could help . . and I learnt something new, so we're both happy.

 

Regards,


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

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