Exploding Dimensions

Exploding Dimensions

d.j.gray
Contributor Contributor
743 Views
1 Reply
Message 1 of 2

Exploding Dimensions

d.j.gray
Contributor
Contributor

Hi everyone;

 

I know exploding dimensions is a bad idea.  BUT...let me explain.

I am creating a conversion program to convert solidworks drawings to autoCAD that has to meet a clients standard.

 

The design and drawing issues have all been done by this stage and the autoCAD file is just a deliverable at the end.

 

so NO blocks/Dims/Leaders etc allowed, this i can only see is to be totally translatable to all other clients.

 

Back to the how to.

 

Can anyone help me? I have created a filter and have the dimensions selected.

 

From then on its a bit of a mystery. I loop through the DimstyleTable but then I loose the ability to explode .

 

Any help would be appreciated.

public static void ExplodeDimensions()
        {
            try
            {
                //Start code here

                //Gets the current document, editor and database
                Document acDoc = Application.DocumentManager.MdiActiveDocument;
                Editor acDocEd = acDoc.Editor;
                Database acDocDb = acDoc.Database;

                //Sets up a filter for blocks only
                var filter = new SelectionFilter(new[] { new TypedValue(0, "DIMENSION") });
                var selection = acDocEd.SelectAll(filter);

                
                //checks to see if selection set is good
                if (selection.Status != PromptStatus.OK)

                    //if selection is no good returns
                    return;

                //starts a transaction
                using (var acTrans = acDocDb.TransactionManager.StartTransaction())
                {

                    //loops through
                    foreach (var id in selection.Value.GetObjectIds())
                    {
                        //opens each object in for write
                        var acDr = (DimStyleTableRecord)acTrans.GetObject(id, OpenMode.ForWrite);
                        //explodes each object
                        acDr.e(); LOOSE THE ABILITY TO EXPLODE HERE
                        //erases each object
                        acDr.Erase();
                    }
                    //commits the transaction
                    acTrans.Commit();
                }
            }

            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                Application.ShowAlertDialog("Error in Code\n" + ex.Message);
            }
        }
0 Likes
744 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant

Hi,

It looks like you're confusing the DimstyleTableRecord type (i.e. a dimension style definition recorded in the DimstyleTable) and the Dimension type (i.e. base type for dimension entities).

By using a selection set, you can only get objects deriving from Entity.

 

                    //loops through the selected objects
                    foreach (var id in selection.Value.GetObjectIds())
                    {
                        //opens each object in for write
                        var acDr = (Dimension)acTrans.GetObject(id, OpenMode.ForWrite);
                        //explodes each object
                        acDr.e(); LOOSE THE ABILITY TO EXPLODE HERE
                        //erases each object
                        acDr.Erase();
                    }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes