Exploding 3D Objects in a Side Database with the Core Console.

Exploding 3D Objects in a Side Database with the Core Console.

mhillis
Advocate Advocate
1,437 Views
9 Replies
Message 1 of 10

Exploding 3D Objects in a Side Database with the Core Console.

mhillis
Advocate
Advocate

Good morning everyone,

 

I've got a question in regards to performing some specific explode commands.  You see, I'm putting together a routine that will take all the "Equipment" objects from one of our drawings, put them in indivudal DWG files and explode them.  I'm doing this so they can be imported into Revit.  This is all currently being done in the AutoCAD Core Console.

 

I've got the first two steps down.  Using the Core Console I can grab all of the Equipment objects I mentioned and then import them into their own individual DWG files, but I can't quite get the 'explode' to work. As of now, it just does nothing.  I need to explode these objects so they remove all their properties, but retain their 3D Geometry. 

 

Below is the code, it's wrapped in a foreach statement (not included), I'm currently using to try and get this to work, anyone have any suggestions/thoughts as to why it's not working? 

 

using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    // Open new Database
                    using (Database newDb = new Database(true, true))
                    {
                        // Make collection for single object.
                        ObjectIdCollection coll =
                            new ObjectIdCollection();
                        coll.Add(thisEquipItem.ObjId);
                        
                        using (Transaction newTr = newDb.TransactionManager.StartTransaction())
                        {
                            // Get BlockTable/BlockTableRecord to insert model into newDb.
                            // For these to import correctly, they need to be imported into Model Space.
                            BlockTable bt =
                                newTr.GetObject(newDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                            BlockTableRecord btr = 
                                newTr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;

                            IdMapping idMap = new IdMapping();
                            newDb.WblockCloneObjects(coll, btr.ObjectId, idMap, DuplicateRecordCloning.Ignore, false);

                            newTr.Commit();
                        }

                        // Explode the object.
                        using (Transaction exTr = newDb.TransactionManager.StartTransaction())
                        {
                            BlockTable exBt =
                                exTr.GetObject(newDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                            BlockTableRecord exBtr =
                                exTr.GetObject(exBt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                            foreach (ObjectId obj in exBtr)
                            {
                                Entity ent = exTr.GetObject(obj, OpenMode.ForWrite) as Entity;
                                DBObjectCollection entitySet = new DBObjectCollection();
                                ent.Explode(entitySet);
                            }

                            exTr.Commit();
                        }

                        dwgName = exportPath + @"\" + number + ".dwg";
                        newDb.SaveAs(dwgName, DwgVersion.Current);
                    }

                    tr.Commit();
                }
0 Likes
Accepted solutions (1)
1,438 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

did a quick look, after calling .Explode() the returned collection, needs to be added into the block table record (BTR), then you can .Erase() the solid. for example:

foreach (Entity entity in entitySet)
{
   btr.AppendEntity(entity);
   tr.AddNewlyCreatedDBObject(entity, true);
}

hth.-

0 Likes
Message 3 of 10

mhillis
Advocate
Advocate

LE3,

 

Thank you, makes sense I forgot that.  Quick bump I've hit, I'll be looking at while I'm waiting on a reply.

 

Using the following code, my entitySet class comes up empty.  I've confirmed that the entity is there in it's respective variable. Any immediate ideas as to what might be causing that? 

 

 foreach (ObjectId obj in exBtr)
                            {
                                Entity ent = exTr.GetObject(obj, OpenMode.ForWrite) as Entity;
                                DBObjectCollection entitySet = new DBObjectCollection();
                                ent.Explode(entitySet);

                                foreach (Entity e in entitySet)
                                {
                                    exBtr.AppendEntity(e);
                                    exTr.AddNewlyCreatedDBObject(e, true);
                                }

 

0 Likes
Message 4 of 10

Anonymous
Not applicable

no idea, have been a while since i used autocad for production work... are these 3d solids explodable?, maybe custom objects? or from a vertical application? -- i will try with the command: _.-EXPORTTOAUTOCAD first (in case you have autocad), and export the drawing with that first, then run your code again, and see if helps.

 

hth.-

0 Likes
Message 5 of 10

mhillis
Advocate
Advocate
They are custom objects yes, however; I can explode them using the EXPLODE command and that gets me the result I am looking for.
0 Likes
Message 6 of 10

Anonymous
Not applicable

do, you did a test with the command: -exporttoautocad?

are these custom objects in-house? or some autodesk vertical?

make the test to export them with the command above, and post a drawing sample here, i may have a chance to run a test here, or also any of the other members here, may give a try too.

hth.-

0 Likes
Message 7 of 10

mhillis
Advocate
Advocate

LE3,

 

Thanks for getting back to me.

 

Using the EXPORTTOAUTOCAD commands appears to actually work great.  This gives me an object I can actually use!  The problem is incorporating it into the AutoCAD Core Console.

 

You see, as the previous code example shows, I'm loading a doc, getting objects from that doc, and putting each object into it's own seperate database.  For the EXPORTAUTOCAD command to work, I need to run that within each database.  I can't just run it on the entireity of the original drawing, as I'm only needing to run this on specific objects.   I realize that I need to open each one of these objects as a document and then I can SendStringToExecute() from there, however; doing just that has me a little stumped.  It's my assumption the method for doing that would be to use the DocumentCollectionExtension routines to so I can add a document and import the database that way, however; that isn't available in the AutoCAD Core Console.  Unfortunately, I'm not immediately seeing another way to load my database into a document so I can run commands on it.

 

Any suggestions?

 

Thanks!

 

 

 

 

0 Likes
Message 8 of 10

mhillis
Advocate
Advocate

My duh moment for the day,

 

http://www.cadforum.cz/cadforum_en/command.asp?Core

 

As shown in the link above, the EXPORTTOAUTOCAD command is NOT available in the Core Console.

 

CONVERTTO3DSOLIDS is though.  I think that achieves the exact same effect, however;  I'm still a little stumped as to how I'm gonna take a database like this and run commands on it in the Core Console.  Easy to do in full AutoCAD, little tricky here.

0 Likes
Message 9 of 10

Anonymous
Not applicable
Accepted solution

if i recall reading it, there was a list also on Kean Walmsley great source site: http://through-the-interface.typepad.com/ - about the core console.

 

if these custom objects are in-house not autodesk verticals, maybe you can make a function to autolisp or c# side and make available the explode part of those custom objects, now i have no idea if one can run in the core console that as said previously not familiar with the core console et-al, others might provide better advice on this.

 

good luck. hth.- 

Message 10 of 10

mhillis
Advocate
Advocate

To all those interested.  I've figured this out.

 

Basically, what I have is an external application that will open a DWG (by utilizing the Core Console) and then export the equipment items out of that DWG as individual DWGs.

 

My solution has been to have my application open up each DWG after the fact and run a script on that file.  In this case,  I simply change the view of the drawing to Isometric, then run the explode command using that script.  Doing this gives me a DWG file with a piece of equipment exploded in just the fashion that I need it.

 

Thanks LE3 for the help.

 

0 Likes