Clean out all Civil 3d stuff from drawing

Clean out all Civil 3d stuff from drawing

JamesMaeding
Advisor Advisor
4,027 Views
17 Replies
Message 1 of 18

Clean out all Civil 3d stuff from drawing

JamesMaeding
Advisor
Advisor

If I want to delete all civil3d objects, and styles and everything specific to c3d, how would that be done?

I know the civil batch converter or -exporttoautocad and so on can do it, but I am asking how I could do it with code.

If I dele all entities of type AEC*, that would kill the drawn entities. Then deal with block definitions..

But how do I kill the invisible stuff like styles, with code?

Superpurge allows me to kill the Root NOD, but I'd like to know what I am doing more.

Might be more of a question for adesk...


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
4,028 Views
17 Replies
Replies (17)
Message 2 of 18

Jeff_M
Consultant
Consultant

The Root NOD is the Root for all of the C3D styles and non-entity objects. Delete it and they all go with it.

 

                Database db = new Database(false, true);
                bool shouldsave = false;
                db.ReadDwgFile(strPath, FileOpenMode.OpenForReadAndWriteNoShare, false, "");
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    DBDictionary NOD = db.NamedObjectsDictionaryId.GetObject(OpenMode.ForRead) as DBDictionary;
                    if (NOD.Contains("Root"))
                    {
                        NOD.UpgradeOpen();
                        NOD.Remove("Root");
                        shouldsave = true;
                    }
                    tr.Commit();
                }

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 18

JamesMaeding
Advisor
Advisor

licking my chops now, will try on a few drawings.

Thanks a bunch for commenting as there is so little info on this.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 4 of 18

JamesMaeding
Advisor
Advisor

I think I'm going to name a future grandson after you Jeff.

Its working.

I can kill the root NOD and it does not even mess up the c3d objects.

I did notice you cannot edit a surface style by right click until you audit the dwg or re-open.

But that's ok, and fixes itself.

This is THE way to clean out C3D styles! awesome!

 

Now to try on lots of dwg's to see if there are rare exceptions.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 5 of 18

Jeff_M
Consultant
Consultant

Let us know how it goes, James. I have only used that on unopened drawings that I never wanted to open in C3D again, so I never checked what occurs with drawings you want to keep in C3D.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 6 of 18

JamesMaeding
Advisor
Advisor

so the effects of killing the Root entry of the NOD are that civil3d objects become disconnected from their style.

The ones that use Standard rehook to that style when you run an audit.

Ones that do not actually become invisible.

You can rehook them up by selecting with SSX, using AEC* as entity filter, then select style in props.

They are undamaged, just kind of disembodied for a bit. Like that mind watching over the Total Perspective Vortex in The Hitchhikers Guide TTG.

 

 

Now, its interesting that I cannot seem to access or delete the Root entry via lisp.

I can see it when I inspect (namedobjdict) in the VLIDE.

It gives invalid entity when I try to expand it.

dictsearch and dictremove hit similar walls.

 

I would like to dig through it a bit to see if I can just delete portions that I do not care about, like pipe network styles.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 7 of 18

Jeff_M
Consultant
Consultant

Lisp? No, there is less and less that can be done with lisp in C3D. Although getting the ActiveX version of the Root dictionary is easy:

 

(setq dicts (vlax-get (vla-get-activedocument (vlax-get-acad-object)) 'dictionaries))

(setq root (vla-item dicts "Root"))

 

and gives the following for properties and methods:

$ (*dump root t)
; IAcadObject: The standard interface for a basic AutoCAD object
; Property values:
; Application (RO) = #<VLA-OBJECT IAcadApplication 000000014023a1d8>
; Document (RO) = #<VLA-OBJECT IAcadDocument 0000000024735fc0>
; Handle (RO) = "8B"
; HasExtensionDictionary (RO) = 0
; ObjectID (RO) = 207
; ObjectID32 (RO) = 207
; ObjectName (RO) = "AeccDbTreeNode"
; OwnerID (RO) = 208
; OwnerID32 (RO) = 208
; Methods supported:
; Delete ()
; GetExtensionDictionary ()
; GetXData (3)
; SetXData (2)

 

Then converting it to an Ename and using Entget:

 

(setq ent (vlax-vla-object->ename root))
(entget ent)

 

returns nil. So the Root was not meant to be messed with in lisp 🙂 Looks like it is it's own Custom Object (AeccDbTreeNode)

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 8 of 18

JamesMaeding
Advisor
Advisor

I use a mix these days of entget codes, com and .net.

Problem is I have a huge library of subroutines so can't transition all at once.

Can't beat VS for coding though, so nice.

 

I don't care much for having to start acad each debug in VS though....

Lisp is interesting because if you structure things right, you can simulate objects which allow large progs to be written and maintained.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 9 of 18

JamesMaeding
Advisor
Advisor

I'd sure like to hear from Autodesk how to navigate the structure of that root dictionary entry.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 10 of 18

Jeff_M
Consultant
Consultant

I don't believe 'we' can, James. At least not how I think you want to. We can access all of the items it holds via the individual Styles, Settings, etc., but we can't peruse it like a typical Dictionary since it uses it's own, custom, entity. And many of these are only accessible via the .NET API

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 11 of 18

JamesMaeding
Advisor
Advisor

hmm, I bet the string of data is gibbereish until its consumed by some other function.

I hate unhackable data.

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 12 of 18

Anonymous
Not applicable

Hi James,

 

If I understand it correctly, you are looking for an API which is equivalent of Civil 3D UI command "PURGESTYLES" to purge the unused styles. Please confirm if I am right in understanding your need. I don't see we have an API exposed yet which is equivalent to "PURGESTYLES" command and I might have to log an API wish list to work on this. Please confirm.

 

Thanks,

Partha

0 Likes
Message 13 of 18

Anonymous
Not applicable

BTW - we could use StyleBase.IsUsed  API which will tell us if a particular style is in-use.

and then decide on whether to delete a style.

 

http://adndevblog.typepad.com/infrastructure/2013/05/is-there-a-way-to-determine-if-a-specific-style...

 

Thanks,

Partha

 

 

 

0 Likes
Message 14 of 18

JamesMaeding
Advisor
Advisor

The first thing is how to determine how much space that root item is taking in the drawing.

I am making a tool that suggests purging drawings with a ton of styles.

Can that be done just by looking at the dictionary entry, even if gibberish?


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 15 of 18

Jeff_M
Consultant
Consultant
James, as a test I just opened a new drawing from my dwt and saved. Size = 832kb Used the PurgeStyles command twice which removed 449 styles, then saved. New file size = 696kb. Based on this it appears that each style uses ~ 0.30kb. Now if many of those are Point Styles with special blocks, this will allow those blocks to be purged which likely use far more kb than the actual styles.
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 16 of 18

JamesMaeding
Advisor
Advisor

I'd like to know without purging though.

I need something fast like how I can count app ids programatically without cleaning them out.

Note that several drawings I am dealing with have some kind of corrucption going on in the styles, so .net c3d style API methods are not my first choice.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 17 of 18

JamesMaeding
Advisor
Advisor

I should mention what is happening is we have drawings from 2009 with that old "reverse lookup" corruption issue with c3d styles.

I can easily open the files in 2014 and the corruption is cleaned, but not if I open in vanilla acad.

We have mostly acad seats, and other engineers keep sending contaminated files which open very slowly.

I want a way to sniff those out, and by cheking how large that root dict entry is will tell me if the drawing has problems.

Usually the size is about 1.2 mb when a drawing is contaminated.

Either way, it would be slick to be able to say how much of a drawing is c3d styles, if there is such a way to measure it.

Iv'e never measured other portions of a drawing like this, as they are not all tucked in one spot.

This one might be the same, no way to really measure.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 18 of 18

Anonymous
Not applicable

Hi James,

 

Determining if the file is corrupt or not based on the size of style objects might not be correct way and I am sure you would get inconsistent results.

I would suggest to use the route via Civil 3D 2014 atleast to open and save the files once.

 

Thanks,

0 Likes