Author Topic: Project-Auditing dwgs to a CAD Standard  (Read 30976 times)

0 Members and 1 Guest are viewing this topic.

Glenn R

  • Guest
Re: Project-Auditing dwgs to a CAD Standard
« Reply #45 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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Project-Auditing dwgs to a CAD Standard
« Reply #46 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();
    }
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4072
Re: Project-Auditing dwgs to a CAD Standard
« Reply #47 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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Project-Auditing dwgs to a CAD Standard
« Reply #48 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4072
Re: Project-Auditing dwgs to a CAD Standard
« Reply #49 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.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4072
Re: Project-Auditing dwgs to a CAD Standard
« Reply #50 on: July 22, 2008, 06:30:50 PM »
TW, I think we should code it both ways
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Project-Auditing dwgs to a CAD Standard
« Reply #51 on: July 22, 2008, 06:44:58 PM »
TW, I think we should code it both ways
Almost there.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Project-Auditing dwgs to a CAD Standard
« Reply #52 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Project-Auditing dwgs to a CAD Standard
« Reply #53 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: Project-Auditing dwgs to a CAD Standard
« Reply #54 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...

Glenn R

  • Guest
Re: Project-Auditing dwgs to a CAD Standard
« Reply #55 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.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4072
Re: Project-Auditing dwgs to a CAD Standard
« Reply #56 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.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

sinc

  • Guest
Re: Project-Auditing dwgs to a CAD Standard
« Reply #57 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...?

vegbruiser

  • Guest
Re: Project-Auditing dwgs to a CAD Standard
« Reply #58 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?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Project-Auditing dwgs to a CAD Standard
« Reply #59 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.