TheSwamp

Code Red => .NET => Topic started by: David Hall on July 21, 2008, 06:28:10 PM

Title: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 21, 2008, 06:28:10 PM
Anyone interested in helping me create a auditing tool to check drawings against a corporate standard is welcome to help.  I'm thinking we should write this in C#, as its seems to be the way of the future, and you guys are making huge leaps already.

These are some of the things I'm trying to accomplish, feel free to add to the list

Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 07:58:50 AM
Attached is a skeleton/test harness for selecting bulk drawings and then running over them, loading each into memory (not graphically) and doing some sort of processing.

This is to get the project and discussions started. Once people have digested the code, please post your comments on how you would design this checker.

Some of my initial thoughts:

XML based rules file(s) maybe?
These would contain things to check and also location of DWS files for compliance checking?

Have at it lads.

Cheers,
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 08:00:36 AM
Forgot to mention. The attached project in my post above, was produced using Visual C# 2008 Express against the .NET 3.5 framework and AutoCAD 2006, although it should run on 2006 and upwards.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: HD on July 22, 2008, 09:01:16 AM
Glenn,

Very nice! Thank you for taking the time to start this program.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 09:04:06 AM
No probs Nick. Hopefully it will stimulate some interest.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 09:10:49 AM
We'll also have to agree on what output is required and in what format. I think XML with an XSLT transform to make the report pretty.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 09:11:52 AM
Anybody reading this good with XSLT transforms?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 09:12:12 AM
Oh the silence is deafening! :)
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 09:15:33 AM
I need to get caught up, going to read the code
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: vegbruiser on July 22, 2008, 09:58:02 AM
You must've read my mind CmdrDuh. I've been working on this exact problem for about 6 weeks or so (there's not much else to do at the moment, so the boss hasn't batted an eyelid)

Attached is what I've got thus far. The parts you might be interested in are where I output the information gathered from a selection of Excel and AutoCAD files to XML.

What I haven't got around to figuring out yet is how to check for viewports (scale & view location)/layers (conformance to a given standard)/ blocks (attributes filled out correctly, correct blocks used).

Unfortunately, my code is VB.NET, but I'm happy to convert it to C# if people think it might be useful.

Actually, scratch all that, I'll extract (and convert) the parts that write the XML file(s) as the rest is specific to my situation. (I'd still appreciate it if anyone does take the time to read through my code though, as I'm certainly no expert, and all constructive criticism will be gratefully accepted)

I'll post the relevant parts as soon as I've read what GlennR posted. :)
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 10:22:37 AM
I think XML is definelty the way to go for the files.  Kerry has shown me some great examples of how to put stuff in XML that makes organization easier.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 10:25:57 AM
Well have at it then laddy! Get an initial design together and post it so we can continue discussions.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 10:27:16 AM
I meant the XML btw. We may as well use some LINQage for querying the XML files whilst we're at it...
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 10:28:14 AM
So do we have the list of what we want to check finished?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 10:29:30 AM
Also, are we checking things that the Standards checker already does?  The reason I ask is your reference to the DWS files above.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 10:31:09 AM
Up to the group - in my mind, if we're making a separate program we may as well do the lot, but that's just my opinion...
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 10:33:21 AM
This is what I had in mind for the layer part.  Kerry B is the author of the first part, and I ahcked together the second
Quote
<?xml version="1.0" encoding="utf-8"?>
<LayerData>
  <Layer>
    <Description>Outlines 0.90mm</Description>
    <LayerName>ST90</LayerName>
    <Color>5</Color>
    <LineType>Hidden</LineType>
    <Alias>ST90</Alias>
  </Layer>
  <Layer>
    <LayerName>ST70</LayerName>
    <Description>Outlines 0.70mm</Description>
    <Color>3</Color>
    <LineType>Hidden2</LineType>
    <Alias>ST70</Alias>
  </Layer>

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Layers>
    <LayerName>0</LayerName>
    <Freeze>False</Freeze>
    <LayerOn>True</LayerOn>
    <Locked>False</Locked>
    <LineType>Continuous</LineType>
    <Color>7</Color>
  </Layers>
  <Layers>
    <LayerName>Defpoints</LayerName>
    <Freeze>False</Freeze>
    <LayerOn>True</LayerOn>
    <Locked>False</Locked>
    <LineType>Continuous</LineType>
    <Color>7</Color>
  </Layers>

My thoughts were to check what layers were created, turned on and color and frozen.  We always seem to get dwgs back where the layers colors have been changed, things are frozen at random it seems.  Which is always very easy to clean up, I just run my setup program which recreates all the layers w/ correct settings.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 10:50:25 AM
OK, if we're going to be using DWS's, there wouldn't be any need for Layer definitions in XML as the layers would be directly in the DWS file...correct? Agree or disagree?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 10:52:26 AM
So do we have the list of what we want to check finished?

Probably not, but we'll forge ahead anyway. I don't see any problem with revising the program to cater for new conditions later on...
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 10:55:42 AM
I was thinking of putting everything in the XML file.  Thinking that each of us would have  a XML file with our perticular settings
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 10:57:36 AM
OK, if we're going to be using DWS's, there wouldn't be any need for Layer definitions in XML as the layers would be directly in the DWS file...correct? Agree or disagree?
I totally agree we wouldn't need to put the layer info in the XML file.  Now the big question for me is how do we use a DWS file?  do we open it just like a dwg abd read the settings into memory and compare from there?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 11:00:39 AM
OK, if we're going to be using DWS's, there wouldn't be any need for Layer definitions in XML as the layers would be directly in the DWS file...correct? Agree or disagree?
I totally agree we wouldn't need to put the layer info in the XML file.  Now the big question for me is how do we use a DWS file?  do we open it just like a dwg abd read the settings into memory and compare from there?

Essentially yes. You can see how I'm opening a dwg in memory in the code (readdwg), so, thinking out loud, we'll have some sort of class that has variables for the dws files and loads them in when necessary and you do the compare.

This has the added bonus as it's dealing with acad objects, not xml or anything else in this case....use the dws for what it is - a standards file.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 11:08:39 AM
I completely agree, its just I have never done anything like this at all.  Not even in VBA, so you might end up explaining a ton of questions.  Just a forewarning
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: T.Willey on July 22, 2008, 11:09:57 AM
Sounds like fun.  I'm willing to help when/where I can, as I just got back from vacation, and some work has piled up waiting for me.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 11:14:00 AM
I completely agree, its just I have never done anything like this at all.  Not even in VBA, so you might end up explaining a ton of questions.  Just a forewarning

Well aware of that - no probs.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 11:14:39 AM
Sounds like fun.  I'm willing to help when/where I can, as I just got back from vacation, and some work has piled up waiting for me.

Ah...another victim...err volunteer. Good to see you back Tim.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Spike Wilbury on July 22, 2008, 11:15:42 AM
I been also busy, but I can bring the munchies, sodas, tacos, cerveza (beer), goodies, chilaquiles, tostadas, burritos, menudo, etc...  :mrgreen:
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: T.Willey on July 22, 2008, 11:16:20 AM
Sounds like fun.  I'm willing to help when/where I can, as I just got back from vacation, and some work has piled up waiting for me.

Ah...another victim...err volunteer. Good to see you back Tim.
Thanks Glenn.... uh I think.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 11:17:52 AM
Sounds like fun.  I'm willing to help when/where I can, as I just got back from vacation, and some work has piled up waiting for me.

Ah...another victim...err volunteer. Good to see you back Tim.
Thanks Glenn.... uh I think.

 :evil:
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 11:18:28 AM
I been also busy, but I can bring the munchies, sodas, tacos, cerveza (beer), goodies, chilaquiles, tostadas, burritos, menudo, etc...  :mrgreen:

Good to hear Luis.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: vegbruiser on July 22, 2008, 11:49:49 AM
@ Glenn R: I just built your sample code, and, although it moves through the items in the listbox with no problem, it throws the following error message to the AutoCAD 2006 editor each time it tries to open a file: -

System Exception: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Disposing of database...

Any ideas? (I'm using AutoCAD 2006 & debugging using VS 2008)  :?

(I've had a similar exception whilst debugging when using the ReadDwgFile and had to resort to opening the files directly)

EDIT: just tried the same code outside of the debugger, and it runs with no problems.  :x
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 11:58:57 AM
vege,

Had the same here. I believe it's an issue with 2006 and the later Vis Stud 2008. I think from memory, that if you run it with 2007 it will debug ok. I can't test this untill I get home, but somebody else might...

There was also some discussion about ReadWgFile recently on the adesk ng as well if memory serves...
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: vegbruiser on July 22, 2008, 12:05:48 PM
...There was also some discussion about ReadWgFile recently on the adesk ng as well if memory serves...
Really? I'll go take a look. It's quite annoying if you're trying to debug, as it means you're left with having to open every file rather than just read the database. :|

EDIT: Here's the most relevant post on the subject: http://tinyurl.com/6s5g3g seems it's a problem with a .NET service pack. And as I have no intention of uninstalling/reinstalling .NET 2.x/3.x on multiple machines (that might make use of this code) I think I'm gonna have to use AutoCAD 2009.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 12:07:42 PM
WE are using the Express versions as well. Maybe someone with the full monty have a go at it with 2006 if possible...
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: vegbruiser on July 22, 2008, 12:17:14 PM
WE are using the Express versions as well. Maybe someone with the full monty have a go at it with 2006 if possible...
Sorry, maybe I wasn't clear - I am using the full monty. (I did actually post about this myself a few weeks ago. here (http://discussion.autodesk.com/thread.jspa?threadID=633031) and it's clearly a problem that can only be overcome by reverting to an earlier .NET version. :(

Anywho, I can live with not being able to debug the code so long as someone else can do it on a pre .NET 2/3 SP1 setup.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 02:59:32 PM
Just tested it with Visual C# 2008 Express, .NET 3.5 and AutoCAD 2007 and debugging in working fine.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 02:59:56 PM
Must be a '06 problem...
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 03:18:23 PM
It worked in Autocad 08 using the debugging as well.

On a side note, Glenn, I noticed your user file was stuffed full of info, whilst mine is like 8 lines long.  Is there a necessity for the huge file, and should I edit yours or use mine?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 03:34:03 PM
Are you talking about the .csproj.user file or whatever the thing is named Duh? If so, it's a copy from a VS 2005 project that I just dump in to enable debugging in Express.

Can you post yours? The reason I ask, is if I start an Express dll project, the .user file only has a namespace in it - one line....not 8 so I'm curious
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 04:03:48 PM
Like you, I copy this from a previous project and rename it to enable debugging
Quote
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\AutoCAD 2008\acad.exe</StartProgram>
    <StartWorkingDirectory>C:\Program Files\AutoCAD 2008</StartWorkingDirectory>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\AutoCAD 2008\acad.exe</StartProgram>
    <StartWorkingDirectory>C:\Program Files\AutoCAD 2008</StartWorkingDirectory>
  </PropertyGroup>
</Project>
After reading through yours, I think I understand why their are so many lines.  The first group, I didn't know why it was there, the second and third were for if you are set to debug vs. release
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 04:05:35 PM
I cant remember who gave me this file.  It might have been Kerry or MickD, or maybe even TT.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 04:09:41 PM
yeah, that's pretty much my thinking as well. You can just take my project in it's entirety and just edit the .user file in your XML editor of choice (I use XML Notepad from Microsoft - quite liking it once you get accustomed to it) and change the AutoCAD paths to suit...which is what I do.

From memory, the first section, amongst other things, sets the 'reference file' locations...ie the location of ac*mgd.dll files....
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 04:16:25 PM
Duh, have you examined the project code I posted? If so, do you follow it or do you have questions?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 04:23:43 PM
I did, and I do follow it.  I'm full of questions, I didn't want to start bombarding you yet.  My first question would be how (in theory) are we going to use the DWS files?  I know in theory we are opening them thru ObjectDBX ( i think) and somehow storing the values we want to check against.  Layers for instance, we would create an array maybe, and check layer names against that?  Or is there a better way?    I'm trying to think in 2 separate mindsets, 1 using the DWS, and the other in XML set standards.  Also, are there more plugins to the DWS than Layers, Dims, linetypes and textstyles
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 04:40:58 PM
My first question would be how (in theory) are we going to use the DWS files?

Let's walk before we run shall we? :)

I know in theory we are opening them thru ObjectDBX

Forget the term ObjectDBX...it's actually an ARX term used to define the 'separation of concerns' as far as custom objects goes, with respect to the UI component and the dbase component. For example, if I was to create an arx app that defined a custom entity called DuhLine :), the interface would be represented by the .ARX file and the custom DataBase eXtension would be represented by the .DBX file. The DBX file is responsible for persisting the custom object in the dbase and graphical representation amongst other things.

Now before anybody goes off at me, I am simplifying this, but that is the general gist. Having said that, ObjectDBX is a common term amongst VB'ers with respect to the COM library they reference to allow in memory loading and modifications of drawings.

I will not be using the term as far as .NET goes, but what we are doing is opening a drawing in the AutoCAD editor, but not associating a graphical document window with it. Does that make sense?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 22, 2008, 04:46:09 PM
I know in theory we are opening them thru ObjectDBX ( i think) and somehow storing the values we want to check against.  Layers for instance, we would create an array maybe, and check layer names against that?  Or is there a better way?

Yes. We load the dwg file into memory and whenever we want to do something against it, we just start a transaction op against and do our thing. No need to store layers in an array and we already would be storing the whole drawing file itself, which has ALL we need.

Also, are there more plugins to the DWS than Layers, Dims, linetypes and textstyles

To date, I've never seen any and it's a pity. I think this is very powerfull and very much under-utilised. I have actually asked Kean to make a post of this and he's responded saying it's a great idea and he'll get to it 'in the coming weeks'.

Until then, we keep on keeping on.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: T.Willey on July 22, 2008, 05:24:59 PM
Here is one way to get all objects to "ByLayer" color, linetype and lineweight.  If not a good way let me know so I can learn also.   :-)

Code: [Select]
public void ChangeAllToByLayer( Database db ) {
       
    const short cColor = 256;
    const LineWeight cLw = LineWeight.ByLayer;
    const string cLtStr = "ByLayer";
    Entity Ent;
   
    using ( Transaction Trans = db.TransactionManager.StartTransaction() ) {
       
        BlockTable BlkTbl = Trans.GetObject( db.BlockTableId, OpenMode.ForRead ) as BlockTable;
        LinetypeTable LtTbl = Trans.GetObject( db.LinetypeTableId, OpenMode.ForRead ) as LinetypeTable;
        ObjectId LtId = LtTbl["ByLayer"];
       
        foreach ( ObjectId btrId in BlkTbl ) {
            BlockTableRecord btr = Trans.GetObject( btrId, OpenMode.ForRead ) as BlockTableRecord;
            if ( !btr.IsFromExternalReference ) {
                foreach ( ObjectId objId in btr ) {
                    Ent = Trans.GetObject( objId, OpenMode.ForWrite ) as Entity;
                    Ent.ColorIndex = cColor;
                    Ent.Linetype = cLtStr;
                    Ent.LinetypeId = LtId;
                    Ent.LineWeight = cLw;
                    if ( Ent is BlockReference ) {
                        BlockReference BlkRef = Ent as BlockReference;
                        AttributeCollection AttCol = BlkRef.AttributeCollection as AttributeCollection;
                        foreach ( ObjectId attId in AttCol ) {
                            Ent = Trans.GetObject( attId, OpenMode.ForWrite ) as Entity;
                            Ent.ColorIndex = cColor;
                            Ent.Linetype = cLtStr;
                            Ent.LinetypeId = LtId;
                            Ent.LineWeight = cLw;
                        }
                    }
                }
            }
        }
        Trans.Commit();
    }
}
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 06:06:29 PM
Question about the reporting piece of this excercise.  Are we wanting to fix it or report it.  TW, I am definetly going to copy that as it looks really good to me, however, are we wanting to fix the problem or report it to the insultants?  And if we report it, is their a way to flag the instance of the problem.  I'm thinking about the way Autocad Map flags problems
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: T.Willey on July 22, 2008, 06:23:05 PM
I guess if we wanted to report it, we can do it the way audit does.  If gives the handle, and the dxf name, then we can say what part of it is out of order; color, linetype or lineweight.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 06:30:03 PM
Having never used ObjectDBX, you can see where I thought that was the correct terminology.  After you have explained that better, I now see why I was incorrect in using it.  Cool, moving on.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 22, 2008, 06:30:50 PM
TW, I think we should code it both ways
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: T.Willey on July 22, 2008, 06:44:58 PM
TW, I think we should code it both ways
Almost there.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: T.Willey on July 22, 2008, 06:54:16 PM
TW, I think we should code it both ways
Almost there.
Here is a working copy of a reporting version.
Code: [Select]
public void ReportNonByLayer( Database db ) {
       
    const short cColor = 256;
    const LineWeight cLw = LineWeight.ByLayer;
    const string cLtStr = "ByLayer";
    Entity Ent;
    Editor Ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
    StringBuilder sb;
    bool HasErrors;
    RXClass rxc;
   
    using ( Transaction Trans = db.TransactionManager.StartTransaction() ) {
       
        BlockTable BlkTbl = Trans.GetObject( db.BlockTableId, OpenMode.ForRead ) as BlockTable;
        LinetypeTable LtTbl = Trans.GetObject( db.LinetypeTableId, OpenMode.ForRead ) as LinetypeTable;
        ObjectId LtId = LtTbl["ByLayer"];
       
        foreach ( ObjectId btrId in BlkTbl ) {
            BlockTableRecord btr = Trans.GetObject( btrId, OpenMode.ForRead ) as BlockTableRecord;
            if ( !btr.IsFromExternalReference ) {
                foreach ( ObjectId objId in btr ) {
                    Ent = Trans.GetObject( objId, OpenMode.ForRead ) as Entity;
                    rxc = Ent.GetRXClass();
                    sb = new StringBuilder( rxc.DxfName + "(" + Ent.Handle + ")" );
                    HasErrors = false;
                   
                    if ( Ent.ColorIndex != cColor ) {
                        sb.Append( "    Color" );
                        HasErrors = true;
                    }
                    if ( Ent.Linetype != cLtStr || Ent.LinetypeId != LtId) {
                        if ( HasErrors )
                            sb.Append( " / Linetype" );
                        else
                            sb.Append("    Linetype");
                        HasErrors = true;
                    }
                    if ( Ent.LineWeight != cLw ) {
                        if ( HasErrors )
                            sb.Append( " / Lineweight" );
                        else
                            sb.Append( "    Lineweight");
                        HasErrors = true;
                    }
                    if ( HasErrors )
                        Ed.WriteMessage( sb + " not ByLayer" + Environment.NewLine );
                   
                    if ( Ent is BlockReference ) {
                        BlockReference BlkRef = Ent as BlockReference;
                        AttributeCollection AttCol = BlkRef.AttributeCollection as AttributeCollection;
                        foreach ( ObjectId attId in AttCol ) {
                            Ent = Trans.GetObject( attId, OpenMode.ForWrite ) as Entity;
                            rxc = Ent.GetRXClass();
                            sb = new StringBuilder( rxc.DxfName + "(" + Ent.Handle + ")" );
                            HasErrors = false;
                            if ( Ent.ColorIndex != cColor ) {
                                sb.Append( "    Color" );
                                HasErrors = true;
                            }
                            if ( Ent.Linetype != cLtStr || Ent.LinetypeId != LtId) {
                                if ( HasErrors )
                                    sb.Append( " / Linetype" );
                                else
                                    sb.Append("    Linetype");
                                HasErrors = true;
                            }
                            if ( Ent.LineWeight != cLw ) {
                                if ( HasErrors )
                                    sb.Append( " / Lineweight" );
                                else
                                    sb.Append( "    Lineweight");
                                HasErrors = true;
                            }
                            if ( HasErrors )
                                Ed.WriteMessage( sb + " not ByLayer" + Environment.NewLine );
                        }
                    }
                }
            }
        }
        Trans.Commit();
    }
}
Report like
Quote
MTEXT(9DB7B)    Linetype not ByLayer
POINT(9DB7C)    Color / Linetype not ByLayer
POINT(9DB7D)    Color / Linetype not ByLayer
POINT(9DB7E)    Color / Linetype not ByLayer
LINE(9DB82)    Linetype / Lineweight not ByLayer
LINE(9DB83)    Linetype / Lineweight not ByLayer
LINE(9DB84)    Linetype / Lineweight not ByLayer
SOLID(9DB85)    Linetype not ByLayer
SOLID(9DB86)    Linetype not ByLayer
MTEXT(9DB87)    Linetype not ByLayer
POINT(9DB88)    Color / Linetype not ByLayer
POINT(9DB89)    Color / Linetype not ByLayer
POINT(9DB8A)    Color / Linetype not ByLayer
LINE(9DC3F)    Linetype / Lineweight not ByLayer
LINE(9DC40)    Linetype / Lineweight not ByLayer
LINE(9DC41)    Linetype / Lineweight not ByLayer
SOLID(9DC42)    Linetype not ByLayer
SOLID(9DC43)    Linetype not ByLayer
MTEXT(9DC44)    Linetype not ByLayer
POINT(9DC45)    Color / Linetype not ByLayer
POINT(9DC46)    Color / Linetype not ByLayer
POINT(9DC47)    Color / Linetype not ByLayer

Guess could put in a count to see how many entities were found.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: T.Willey on July 22, 2008, 07:09:30 PM
Here is a counting one, and I changed it so that it only prints one string to the command line, which I thought might speed it up, which it seems like it did a little.
Code: [Select]
public void ReportNonByLayer( Database db ) {
       
    const short cColor = 256;
    const LineWeight cLw = LineWeight.ByLayer;
    const string cLtStr = "ByLayer";
    Entity Ent;
    Editor Ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
    StringBuilder MainString = new StringBuilder();
    StringBuilder sb;
    bool HasErrors;
    RXClass rxc;
    long Count = 0;
   
    using ( Transaction Trans = db.TransactionManager.StartTransaction() ) {
       
        BlockTable BlkTbl = Trans.GetObject( db.BlockTableId, OpenMode.ForRead ) as BlockTable;
        LinetypeTable LtTbl = Trans.GetObject( db.LinetypeTableId, OpenMode.ForRead ) as LinetypeTable;
        ObjectId LtId = LtTbl["ByLayer"];
       
        foreach ( ObjectId btrId in BlkTbl ) {
            BlockTableRecord btr = Trans.GetObject( btrId, OpenMode.ForRead ) as BlockTableRecord;
            if ( !btr.IsFromExternalReference ) {
                foreach ( ObjectId objId in btr ) {
                    Ent = Trans.GetObject( objId, OpenMode.ForRead ) as Entity;
                    rxc = Ent.GetRXClass();
                    sb = new StringBuilder( rxc.DxfName + "(" + Ent.Handle + ")" );
                    HasErrors = false;
                   
                    if ( Ent.ColorIndex != cColor ) {
                        sb.Append( "    Color" );
                        HasErrors = true;
                        ++Count;
                    }
                    if ( Ent.Linetype != cLtStr || Ent.LinetypeId != LtId) {
                        if ( HasErrors )
                            sb.Append( " / Linetype" );
                        else {
                            sb.Append("    Linetype");
                            ++Count;
                        }
                        HasErrors = true;
                    }
                    if ( Ent.LineWeight != cLw ) {
                        if ( HasErrors )
                            sb.Append( " / Lineweight" );
                        else {
                            sb.Append( "    Lineweight");
                            ++Count;
                        }
                        HasErrors = true;
                    }
                    if ( HasErrors )
                        MainString.AppendLine( sb.ToString() + " not ByLayer");
                   
                    if ( Ent is BlockReference ) {
                        BlockReference BlkRef = Ent as BlockReference;
                        AttributeCollection AttCol = BlkRef.AttributeCollection as AttributeCollection;
                        foreach ( ObjectId attId in AttCol ) {
                            Ent = Trans.GetObject( attId, OpenMode.ForWrite ) as Entity;
                            rxc = Ent.GetRXClass();
                            sb = new StringBuilder( rxc.DxfName + "(" + Ent.Handle + ")" );
                            HasErrors = false;
                            if ( Ent.ColorIndex != cColor ) {
                                sb.Append( "    Color" );
                                HasErrors = true;
                                ++Count;
                            }
                            if ( Ent.Linetype != cLtStr || Ent.LinetypeId != LtId) {
                                if ( HasErrors )
                                    sb.Append( " / Linetype" );
                                else {
                                    sb.Append("    Linetype");
                                    ++Count;
                                }
                                HasErrors = true;
                            }
                            if ( Ent.LineWeight != cLw ) {
                                if ( HasErrors )
                                    sb.Append( " / Lineweight" );
                                else {
                                    sb.Append( "    Lineweight");
                                    ++Count;
                                }
                                HasErrors = true;
                            }
                            if ( HasErrors )
                                MainString.AppendLine( sb.ToString() + " not ByLayer");
                        }
                    }
                }
            }
        }
        if ( !Count.Equals( 0 ) ) {
            MainString.AppendLine( Environment.NewLine + "Found " + Count + " entities not ByLayer." );
            Ed.WriteMessage( MainString.ToString() );
        }
        Trans.Commit();
    }
}
Results like
Quote
SOLID(9DB85)    Linetype not ByLayer
SOLID(9DB86)    Linetype not ByLayer
MTEXT(9DB87)    Linetype not ByLayer
POINT(9DB88)    Color / Linetype not ByLayer
POINT(9DB89)    Color / Linetype not ByLayer
POINT(9DB8A)    Color / Linetype not ByLayer
LINE(9DC3F)    Linetype / Lineweight not ByLayer
LINE(9DC40)    Linetype / Lineweight not ByLayer
LINE(9DC41)    Linetype / Lineweight not ByLayer
SOLID(9DC42)    Linetype not ByLayer
SOLID(9DC43)    Linetype not ByLayer
MTEXT(9DC44)    Linetype not ByLayer
POINT(9DC45)    Color / Linetype not ByLayer
POINT(9DC46)    Color / Linetype not ByLayer
POINT(9DC47)    Color / Linetype not ByLayer

Found 57978 entities not ByLayer.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 23, 2008, 04:56:42 AM
Here is one way to get all objects to "ByLayer" color, linetype and lineweight.

Which might not be what a particular company wants Tim...
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 23, 2008, 04:58:29 AM
I guess if we wanted to report it, we can do it the way audit does

I would suggest the same way as the CAD Standards Checker does. This way, you can email the report to the insultant and they know what to fix. If you do it like audit, it's not very friendly.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 23, 2008, 10:35:09 AM
I think I have it worked out in my head how to check the fonts and layers, I'm going to try and code that up today.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: sinc on July 23, 2008, 10:51:38 AM
Is the goal for this project to create something that works in Vanilla Autocad only?

I'm only asking because the newer vertical products like Revit and Civil-3D use Styles to incorporate most of their standards, so the majority of standards checking in those products would involve Styles.  And because of the way Styles work, it can be difficult to analyze objects to see if they are "ByLayer", or things like that...

Maybe Styles throw too big a monkey-wrench into things...?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: vegbruiser on July 23, 2008, 10:55:22 AM
...Maybe Styles throw too big a monkey-wrench into things...?
I think maybe you've answered your own question?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: T.Willey on July 23, 2008, 10:57:13 AM
I guess if we wanted to report it, we can do it the way audit does

I would suggest the same way as the CAD Standards Checker does. This way, you can email the report to the insultant and they know what to fix. If you do it like audit, it's not very friendly.
What would that look like Glenn?  I don't have a dws file around, and have tried to set it up once, but didn't like it, so I canned that idea.

Maybe Styles throw too big a monkey-wrench into things...?
I don't have any real verticals on my machine, so I wouldn't know how to code to check styles.  Maybe that will be in the second generation of the routine.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 23, 2008, 11:03:09 AM
I guess if we wanted to report it, we can do it the way audit does

I would suggest the same way as the CAD Standards Checker does. This way, you can email the report to the insultant and they know what to fix. If you do it like audit, it's not very friendly.
What would that look like Glenn?  I don't have a dws file around

SaveAs any drawing to DWS and you magically have a standards file. Then go to Batch Standards Checker, select drawings, tell it to use the DWS file and off you go.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 23, 2008, 11:11:23 AM
I think I have it worked out in my head how to check the fonts and layers, I'm going to try and code that up today.

Duh,

I'm sorry, but I'm at a loss as to how you're going to accomplish this, when we haven't even decided what the XML config file looks like, let alone it's contents. This application config file would tell the app what to check, possible DWS files to use etc. etc...whatever we want.

Going off and doing the layers and fonts, whilst good for practice, is a bit premature I think or do you have something else in mind?

Cheers,
Glenn.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: T.Willey on July 23, 2008, 11:25:00 AM
I guess if we wanted to report it, we can do it the way audit does

I would suggest the same way as the CAD Standards Checker does. This way, you can email the report to the insultant and they know what to fix. If you do it like audit, it's not very friendly.
What would that look like Glenn?  I don't have a dws file around

SaveAs any drawing to DWS and you magically have a standards file. Then go to Batch Standards Checker, select drawings, tell it to use the DWS file and off you go.
I'm not sure how you could relate what is wrong, as far as drawn objects, like they do in the DWS checker.  I guess if the report was going to be in some text file, then it could be formatted like that.  But my question would still be how does one know which items are not in compliance?  Since the handle doesn't change, that is why I was reporting that.  Do you have an idea of what the output file is going to be?  Or how it is supposed to look?  I don't think that would be too hard to change the code once those items have been confirmed.

How else would one report which items did not meet standards?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 23, 2008, 12:23:48 PM
I'm sorry, but I'm at a loss as to how you're going to accomplish this, when we haven't even decided what the XML config file looks like, let alone it's contents.
I was going under the assumption that we would pull the valid layers, text styles, dim settings, and the other 4th item I cant seem to remember from the dws file.  I haven't figured out what I think needs to go into the XML file yet, as that seems like a huge undertaking, that could involve lots of info, which as you said, hasn't been thought up yet.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 23, 2008, 01:59:13 PM
Just to be clear, I'm referring to the XML file for app configuration (what DWS's to grab and from where for example), not the output file...
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 23, 2008, 03:03:02 PM
Well I'm glad you said that, because I was going the wrong direction.  Do we have a method of editing the XML config file from within our app?  I'm thinking that would be a "settings" button on main page that opens a form where we can browse to the DWS file, pick paths, etc.  All of that data would then be stored in XML, possibly in the same folder as our app, or would we create a subfolder for the app?
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on July 23, 2008, 03:11:16 PM
In the simplest of terms, is this kinda what we are talking about creating as the config file?  I know there is a lot missing, Im just trying to get my mind headed in the right direction
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<CadQcQaConfig>
<OutputFolder>
  <Folder>Path to Output Folder for results </Folder>
</OutputFolder>
<Source>
  <DWSFile>path to DWS File</DWSFile>
</Source>
</CadQcQaConfig>code]
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 23, 2008, 03:35:10 PM
Exactly Duh, with the exception that you wouldn't store in a sub folder...all in the same folder as you suggest.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 23, 2008, 04:52:14 PM
In the simplest of terms, is this kinda what we are talking about creating as the config file?  I know there is a lot missing, Im just trying to get my mind headed in the right direction
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<CadQcQaConfig>
<OutputFolder>
  <Folder>Path to Output Folder for results </Folder>
</OutputFolder>
<Source>
  <DWSFile>path to DWS File</DWSFile>
</Source>
</CadQcQaConfig>code]

Yep - that's the idea...now start having a good long think about it. Once you do, you'll realise there's a bit more to this than meets the eye, but it will definitely be worth it in the end me thinks.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 25, 2008, 10:37:00 AM
I've been playing  :-)
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 25, 2008, 10:37:39 AM
More later...I hope :)
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on July 29, 2008, 03:40:50 PM
Well...after a couple of days looking and transposing an old ADN sample (VB and for acad 2004) and the CircleSample ATL ObjectARX sample, I've managed to create a plugin to check circles colours.

There were a lot more hoops to jump through than I first envisaged, however, having said this, I think 'it has legs' and will be quite useful. I will post more when I sort out some other questions that have come to mind from this exercise.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on August 01, 2008, 08:53:51 AM
Ask and ye shall receive (http://through-the-interface.typepad.com/through_the_interface/2008/08/implementing-a.html).

Thanks to Kean for posting this - I'm sure it will benefit the discussions both here and there.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on August 01, 2008, 08:59:38 AM
Here is my effort cobbled together from the ADN doc Kean mentions and the ARX sample CircleStandard:

Code: [Select]
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace tcgsAcStdCircles
{
[ProgId("tcgsAcStdCircles.AcStdCirclesTest")]
[ClassInterface(ClassInterfaceType.None)]
[Guid("B26515F6-D667-467d-9F9F-E2A0B3ADD594")]
[ComVisible(true)]
public class AcStdCirclesTest : AcStMgr.IAcStPlugin2
{
#region Private field(s)

private string _name;
private string _author;
private string _description;
private string _href;
private string _version;
private string _propName;

private AcStMgr.AcStManager _manager;
private AcStdCirclesTest _plugin;
private AcStMgr.AcStError _error;

private AXDBLib.AcadDatabase _checkDb;
private AXDBLib.AcadDatabase _dwsDb;

private List<CircleCache> _circleCache;
private List<int> _idsToCheck;

private bool _useDb;

private int _currentIndex;
private int _recommendedFixIndex;
private int _fixCount;

#endregion

#region Default ctor

public AcStdCirclesTest()
{
_name = "Circles";
_author = "TCGSoftware";
_description = "Checks that properties of circles in a drawing match those in an associated standards file.";
_href = "www.tcgsoftware.com";
_version = "1.0";

_idsToCheck = new List<int>();
_circleCache = new List<CircleCache>();

_useDb = false;
}

#endregion

#region IAcStPlugin2 Members

public string Author
{
get { return _author; }
}

public void CheckSysvar(string syvarName, bool bGetAllFixes, ref bool bPassFail)
{
// Not implemented yet.
}

public void Clear()
{
_name = string.Empty;
_description = string.Empty;
_author = string.Empty;
_href = string.Empty;
_version = string.Empty;

if (_circleCache != null)
{
for (int i = 0; i < _circleCache.Count; i++)
{
if (_circleCache[i].Fix != null)
{
_circleCache[i].Fix.Reset();
_circleCache[i] = null;
}
}
_circleCache = null;
}

_plugin = null;
_manager = null;
if (_error != null)
{
_error.Reset();
_error = null;
}

_checkDb = null;
_dwsDb = null;

_idsToCheck.Clear();
_idsToCheck = null;

}

public string Description
{
get { return _description; }
}

public bool Done()
{
return (_error == null);
}

public void FixError(AcStMgr.AcStError pError, AcStMgr.AcStFix pFix, out string pFailedReason)
{
pFailedReason = "0";
if (pError != null)
{
object fixVal = null;

int badEntId = pError.BadObjectId;
AXDBLib.AcadCircle badEnt = _checkDb.ObjectIdToObject(badEntId) as AXDBLib.AcadCircle;

if (pFix == null)
{
// if the fix object is null, then attempt to get a recommended fix
AcStMgr.AcStFix tmpFix = GetRecommendedFix(pError);
if (tmpFix == null)
{
pError.ResultStatus = AcStMgr.AcStResultStatus.acStResNoRecommendedFix;
}
else
{
// Fix the naughty circle
pFix = tmpFix;
tmpFix = null;
pFix.PropertyValueGet(_propName, ref fixVal);
try
{
badEnt.color = (AXDBLib.ACAD_COLOR)fixVal;
pError.ResultStatus = AcStMgr.AcStResultStatus.acStResFixed;
}
catch
{
pError.ResultStatus = AcStMgr.AcStResultStatus.acStResFixFailed;
}
}
}
else
{
// Fix the naughty circle
pFix.PropertyValueGet(_propName, ref fixVal);
try
{
badEnt.color = (AXDBLib.ACAD_COLOR)fixVal;
pError.ResultStatus = AcStMgr.AcStResultStatus.acStResFixed;
}
catch
{
pError.ResultStatus = AcStMgr.AcStResultStatus.acStResFixFailed;
}
}
}
}

public void GetAllFixes(AcStMgr.AcStError pError, ref object fixArray, ref int recommendedFixIndex)
{
if (pError != null)
{
AcStMgr.IAcStFix[] arr = new AcStMgr.IAcStFix[_circleCache.Count];

// use our fix candidates if we have any
if (_circleCache.Count > 0)
{
for (int i = 0; i < _circleCache.Count; i++)
{
AXDBLib.ACAD_COLOR errorVal = (AXDBLib.ACAD_COLOR)pError.PropertyValueGet("Color");
if (errorVal.CompareTo(_circleCache[i].Colour) != 0)
{
arr[i] = _circleCache[i].Fix;
}
}

fixArray = arr;

GetRecommendedFix(pError);

recommendedFixIndex = _recommendedFixIndex;
}

if (recommendedFixIndex == -1)
pError.ResultStatus = AcStMgr.AcStResultStatus.acStResNoRecommendedFix;
}
}

public AcStMgr.AcStError GetError()
{
return _error;
}

public object GetObjectFilter()
{
string[] filter = { "AcDbCircle" };
return filter;
}

public void GetPropertyDiffs(AcStMgr.AcStError pError, AcStMgr.AcStFix pFix,
ref object pPropNames, ref object pErrorValues, ref object pFixValues, ref object pFixableStatuses)
{
if (pError != null)
{
List<string> propNames = new List<string>();
string propName = string.Empty;

List<string> errorValues = new List<string>();
object errorVal = null;

List<string> fixValues = new List<string>();
object fixVal = null;

List<bool> fixableStatuses = new List<bool>();

for (int i = 0; i < pError.PropertyCount; i++)
{
pError.PropertyGetAt(i, ref propName, ref errorVal);
_propName = propName;

// Retrieve corresponding Fix property value
try
{
pFix.PropertyValueGet(propName, ref fixVal);
if (((AXDBLib.ACAD_COLOR)errorVal).CompareTo((AXDBLib.ACAD_COLOR)fixVal) != 0)
{
propNames.Add(propName);
errorValues.Add(errorVal.ToString());
fixValues.Add(fixVal.ToString());
fixableStatuses.Add(true);
}
}
catch
{
// explicit catch-all here.
}
}

pPropNames = propNames.ToArray();
pErrorValues = errorValues.ToArray();
pFixValues = fixValues.ToArray();
pFixableStatuses = fixableStatuses.ToArray();

_fixCount++;
}
}

public AcStMgr.AcStFix GetRecommendedFix(AcStMgr.AcStError pError)
{
AcStMgr.AcStFix recommendedFix = new AcStMgr.AcStFix();
_recommendedFixIndex = 0;

if (_circleCache.Count == 0)
{
pError.ResultStatus = AcStMgr.AcStResultStatus.acStResNoRecommendedFix;
}
else
{
AXDBLib.AcadCircle circ = (AXDBLib.AcadCircle)_checkDb.ObjectIdToObject(pError.BadObjectId);
double diff = System.Math.Abs(circ.Radius - _circleCache[0].Radius);

for (int i = 0; i < _circleCache.Count; i++)
{
if (diff > Math.Abs(circ.Radius - _circleCache[i].Radius))
{
diff = Math.Abs(circ.Radius - _circleCache[i].Radius);
_recommendedFixIndex = i;
}
}

recommendedFix.Description = "Colour fix";
recommendedFix.StandardFileName = _circleCache[_recommendedFixIndex].StandardFileName;
recommendedFix.FixObjectName = "Color";
if (recommendedFix.PropertyCount == 0)
{
recommendedFix.PropertyValuePut("Color", _circleCache[_recommendedFixIndex].Colour);
}
}

return recommendedFix;
}

public string HRef
{
get { return _href; }
}

public int Icon
{
get { return 1; }
}

public void Initialize(AcStMgr.AcStManager pMgr)
{
_manager = pMgr;
_plugin = this;
}

public string Name
{
get { return _name; }
}

public void Next()
{
_error = null;
bool foundError = false;

if ((_idsToCheck.Count > 0) && (_circleCache.Count > 0))
{
if (_currentIndex < _idsToCheck.Count)
{
_currentIndex++;

while (_currentIndex < _idsToCheck.Count)
{
AXDBLib.AcadCircle circ = _checkDb.ObjectIdToObject(_idsToCheck[_currentIndex]) as AXDBLib.AcadCircle;

// iterate over our list of cached circle props and look for a match
foreach (CircleCache cc in _circleCache)
{
if (circ.color.CompareTo(cc.Colour) != 0)
{
foundError = true;
}
else
{
// if it matches any one standard, then we can
// stop checking immediately
foundError = false;
break;
}
}

if (foundError)
{
AcStMgr.AcStError error = new AcStMgr.AcStError();
error.Description = "Color is non-standard";
error.BadObjectId = circ.ObjectID;
error.BadObjectName = circ.color.ToString();
error.Plugin = _plugin;
error.ErrorTypeName = "Color ";
error.ResultStatus = AcStMgr.AcStResultStatus.acStResFlagsNone;

if (error.PropertyCount == 0)
{
error.PropertyValuePut("Color", circ.color);
}

_error = error;
foundError = false;
break;
}
_currentIndex++;
}
}
}
}

public void SetContext(object objIdArray, bool bUseDb)
{
_useDb = bUseDb;

if (!bUseDb && objIdArray != null)
{
int[] ids = objIdArray as int[];
_idsToCheck.AddRange(ids);
}
}

public void SetupForAudit(AXDBLib.AcadDatabase pDb, string szPathName,
object stdNameArray, object stdPathArray, object stdDbArray)
{
if (pDb != null)
{
_checkDb = pDb;

if (_checkDb != null)
{
// cache list of all circles in the drawing to check
foreach (AXDBLib.AcadEntity entToCheck in _checkDb.ModelSpace)
{
AXDBLib.AcadCircle circ = entToCheck as AXDBLib.AcadCircle;
if (circ != null)
{
_idsToCheck.Add(circ.ObjectID);
}
}
}

object[] stdDbs = stdDbArray as object[];
string[] stdNames = stdNameArray as string[];
// cache all objects in DWS files we're interested in
// in this case, circles.
for (int i = 0; i < stdDbs.Length; i++)
{
_dwsDb = (AXDBLib.AcadDatabase)stdDbs[i];
foreach (AXDBLib.AcadCircle stdCircle in _dwsDb.ModelSpace)
{
CircleCache cc = new CircleCache();
cc.Radius = stdCircle.Radius;
cc.Colour = stdCircle.color;
cc.StandardFileName = stdNames[i];
AcStMgr.AcStFix fix = new AcStMgr.AcStFix();

fix.Description = "Colour fix";
fix.StandardFileName = cc.StandardFileName;
fix.FixObjectName = "Color: " + stdCircle.color.ToString();

if (fix.PropertyCount == 0)
{
fix.PropertyValuePut("Color", stdCircle.color);
}

cc.Fix = fix;
_circleCache.Add(cc);

fix = null;
cc = null;
}
Marshal.ReleaseComObject(_dwsDb);
_dwsDb = null;
}
}
}

public void StampDatabase(AXDBLib.AcadDatabase pDb, ref bool pStampIt)
{
pStampIt = false;
if (pDb != null)
{
foreach (AXDBLib.AcadEntity dbEnt in pDb.ModelSpace)
{
AXDBLib.AcadCircle circ = dbEnt as AXDBLib.AcadCircle;
if (circ != null)
{
pStampIt = true;
return;
}
}
}
}

public void Start(AcStMgr.AcStError pStartError)
{
if (pStartError != null)
{
int badId = pStartError.BadObjectId;
if (_idsToCheck.Contains(badId))
{
_currentIndex = _idsToCheck.IndexOf(badId);
Next();
}
}
else
{
_currentIndex = -1;
Next();
}
}

public void UpdateStatus(AcStMgr.AcStError pError)
{
// Not implemented yet
}

public string Version
{
get { return _version; }
}

public void WritePluginInfo(object pPluginInfoSectionNode)
{
MSXML2.IXMLDOMNode pSectionNode;
MSXML2.IXMLDOMElement pPluginInfoElement;
MSXML2.IXMLDOMElement xmlElem;

pSectionNode = pPluginInfoSectionNode as MSXML2.IXMLDOMNode;
xmlElem = pSectionNode.ownerDocument.createElement("AcStPluginInfo");
pPluginInfoElement = (MSXML2.IXMLDOMElement)pSectionNode.appendChild(xmlElem);

pPluginInfoElement.setAttribute("PluginName", Name);
pPluginInfoElement.setAttribute("Version", Version);
pPluginInfoElement.setAttribute("Description", Description);
pPluginInfoElement.setAttribute("Author", Author);
pPluginInfoElement.setAttribute("HRef", HRef);
pPluginInfoElement.setAttribute("DWSName", "");
pPluginInfoElement.setAttribute("Status", "1");
}

#endregion
}

[ComVisible(false)]
public class CircleCache
{
public double Radius { get; set; }
public AXDBLib.ACAD_COLOR Colour { get; set; }
public string StandardFileName { get; set; }
public AcStMgr.AcStFix Fix { get; set; }
}
}

I'v done a few things slightly differently to Kean, however the basic gist is still the same.
I will tidy this up a bit once I get my head further into this.

Cheers,
Glenn.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on August 01, 2008, 09:13:28 AM
BTW, kean mentions doing this:

Code: [Select]
"regasm /codebase CircleStandard.dll"

whereas, I did this:
Code: [Select]
"regasm /codebase /regfile:FileName CircleStandard.dll"

This outputs the COM registry goo to a reg file and with a change to the codebase entry in the reg file you can park the com binary on another machine and just run the reg file. I thought this might be better for deployment on multiple computers, however I'm only guessing on this point as COM really isn't my thing.

Cheers,
Glenn.

Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: David Hall on August 01, 2008, 10:44:53 AM
WOW!!!!!!!  That was so far over my head, I cant even begin to put a sentence together.  I will have to reread that a few times.
Title: Re: Project-Auditing dwgs to a CAD Standard
Post by: Glenn R on August 01, 2008, 10:55:02 AM
:) Look at Keans post as well and run through a debugger to get an idea of how it works and what get's called and when - that's what I did.