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

Purging and Auditing files

5 REPLIES 5
Reply
Message 1 of 6
docsaintly
2372 Views, 5 Replies

Purging and Auditing files

I've done a few searches around the forum (and google) and found a few cryptic posts about auditing files.

 

I'm hoping for a straight answer to this question: Is it possible to audit a drawing with the current .Net API for AutoCAD?

 

If so, does it require the editor, or can it be run in the background to enable a lot of drawings to be audited very quickly.

 

As for purging - i've seen a few posts and articles that talk about purging a very specific thing (i.e. materials, line types, etc.).

 

Has anyone written a .Net utility that is similar to the Purge command in AutoCAD? By this I mean, one that will purge all unused objects in the drawing. I have started looking for all the tables that contain the IDs of all the object types that the Purge command looks for, but was also hoping that someone with more experience and time than myself had already tackled this problem.

 

Thanks for your time.

5 REPLIES 5
Message 2 of 6
Dale.Bartlett
in reply to: docsaintly

Here is the Purge All I use, open to comments. However I cannot find an Audit process, did you?

Dale

<code>

public static bool purgeItems(Database db, ObjectIdCollection tableIds, bool silent)
            {
                Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
                bool itemsPurged = false;

                using(Transaction tr = db.TransactionManager.StartTransaction())
                {
                    ObjectIdCollection purgeableIds = new ObjectIdCollection();
                    foreach(ObjectId tableId in tableIds)
                    {
                        SymbolTable table = (SymbolTable)tr.GetObject(tableId, OpenMode.ForRead, false);
                        foreach(ObjectId recordId in table)
                            purgeableIds.Add(recordId);
                    }

                    db.Purge(purgeableIds);

                    if(purgeableIds.Count != 0)
                    {
                        itemsPurged = true;
                        foreach(ObjectId id in purgeableIds)
                        {
                            SymbolTableRecord record = (SymbolTableRecord)tr.GetObject(id, OpenMode.ForWrite);
                            string recordName = record.Name;
                            if(!silent)
                            {
                                if(!recordName.Contains("|"))
                                {
                                    ed.WriteMessage("\nPurging " +
                                        record.GetType().Name + " " + recordName);
                                }
                            }
                            record.Erase();
                        }
                    }
                    tr.Commit();
                }

                return itemsPurged;
            }

<code>




______________
Yes, I'm Satoshi.
Message 3 of 6

I am trying to write a command to purge all items but i am not very experienced.

Your code is written in C# right?

How do i write it in visual basic language?

Tags (1)
Message 4 of 6
SENL1362
in reply to: docsaintly

that's where WBLOCK is written for in the early days of AutoCAD and to my opinion still is used for.

 

http://through-the-interface.typepad.com/through_the_interface/2011/01/combining-autocad-blocks-in-s...

 

 

Message 5 of 6
artc2
in reply to: docsaintly

The following .NET API function was added in AutoCAD 2015:

 

public static void DatabaseExtension.Audit(this Database db, bool bFixErrors, bool bCmdLnEcho)

db            Database to audit
bFixErrors    bool indicating whether or not to fix any errors found
bCmdLnEcho    bool indicating whether or not to echo audit information to
            the command line as the AUDIT command does.

This function audits the db Database.

Message 6 of 6
Dale.Bartlett
in reply to: artc2

Convert to and from VB.NET and C#

http://www.developerfusion.com/tools/convert/vb-to-csharp/

http://converter.telerik.com/

I've had good results with both. Some cleanup/debuging is obviously needed.

Dale

 




______________
Yes, I'm Satoshi.

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