Tuesday, February 01, 2005

I hate CAD standards. Part 1

Platform: AutoCAD 2004
Download: IHateCADStandards.zip

I have a confession; I hate CAD standards. It's not that I don't like following rules, I hate all the steps involved in having to add the standards.

I deal with a lot of third party drawings, about 95% or more of the drawings I work in come from a customer or consultant so having a perfect template to start from isn't a luxury I can work with. Now before anyone says “but Autodesk has given us many tools to enforce standards”, I know…but I'm very lazy when it comes to adding standards, like I mentioned, I hate them.

So, instead of complaining, I've made a single-click solution. I can now add all of my text styles, dimension styles, layers and units with a single click of a button. If you find yourself in the same situation, read on for some invaluable routines.

The first routine will add a new text style with RomanS as the font and the width specified in dblWidth:

Public Function AddTextStyle(dblWidth As Double) As Boolean
On Error GoTo ErrorHandler
Dim oTextStyle As AcadTextStyle

Set oTextStyle = ThisDrawing.TextStyles.Add("MY_ROMANS")

With oTextStyle
.fontFile = "C:/Program Files/AutoCAD 2004/Fonts/romans.shx"
.Width = dblWidth
End With

ThisDrawing.ActiveTextStyle = oTextStyle

Set oTextStyle = Nothing

AddTextStyle = True

Exit Function
Set oTextStyle = Nothing
End Function

Be sure to add in some code to confirm that "romans.shx" exists. Call the above routine with the following line:

If Not AddTextStyle(1#) Then GoTo ErrorHandler

Now that we have our required text styles added into the drawing, we can add our dimension styles. The problem with creating a dimension style is that we don't know the status of any of the variables, so we have to set EVERY variable.

Private Function createDimStyle(dblScale As Double) As Boolean
On Error GoTo ErrorHandler
' Create dimension style
Dim oDimStyle As AcadDimStyle
Dim oTextStyle As AcadTextStyle

' Set system variables
With ThisDrawing
.SetVariable "DIMCLRD", 140
.SetVariable "DIMLWD", -2
.SetVariable "DIMDLI", 0.08
.SetVariable "DIMCLRE", 140
.SetVariable "DIMLWE", -2
.SetVariable "DIMEXE", 0.08
.SetVariable "DIMEXO", 0.08
.SetVariable "DIMASZ", 0.08
.SetVariable "DIMSD1", 0
.SetVariable "DIMSD2", 0
.SetVariable "DIMSE1", 0
.SetVariable "DIMSE2", 0

.SetVariable "DIMBLK1", "."
.SetVariable "DIMBLK2", "."
.SetVariable "DIMLDRBLK", "."
.SetVariable "DIMCEN", 0

.SetVariable "DIMTIH", 1
.SetVariable "DIMTOH", 1
.SetVariable "DIMTMOVE", 0

' Confirm that my TestStyle is there before setting
For Each oTextStyle In .TextStyles
If StrComp(oTextStyle.Name, "MY_ROMANS", vbTextCompare) = 0 Then
.SetVariable "DIMTXSTY", "MY_ROMANS"
Exit For
End If

.SetVariable "DIMCLRT", 120
.SetVariable "DIMTXT", 0.08

.SetVariable "DIMATFIT", 3
.SetVariable "DIMTIX", 0
.SetVariable "DIMSOXD", 0

.SetVariable "DIMUPT", 0
.SetVariable "DIMTOFL", 0

.SetVariable "DIMTAD", 0
.SetVariable "DIMJUST", 0
.SetVariable "DIMGAP", 0.08

.SetVariable "DIMLUNIT", 2
.SetVariable "DIMTFAC", 1
.SetVariable "DIMDEC", 3
.SetVariable "DIMFRAC", 0
.SetVariable "DIMDSEP", "."
.SetVariable "DIMRND", 0
.SetVariable "DIMPOST", ""

.SetVariable "DIMLFAC", 1
.SetVariable "DIMZIN", 0

.SetVariable "DIMAUNIT", 0
.SetVariable "DIMADEC", 3
.SetVariable "DIMAZIN", 0

.SetVariable "DIMALT", 0

.SetVariable "DIMTOL", 0
.SetVariable "DIMLIM", 0
.SetVariable "DIMTDEC", 3
.SetVariable "DIMTP", 0
.SetVariable "DIMTM", 0
.SetVariable "DIMTFAC", 1
.SetVariable "DIMTOLJ", 1

.SetVariable "DIMALTTD", 2
.SetVariable "DIMALTTZ", 0

' Set scale to dblScale
.SetVariable "DIMSCALE", dblScale

' Create Descon dimstyle
Set oDimStyle = .DimStyles.Add("MyDimStyle" & CStr(CLng(dblScale)))
oDimStyle.CopyFrom ThisDrawing
.ActiveDimStyle = oDimStyle
End With

Set oDimStyle = Nothing
Set oTextStyle = Nothing

createDimStyle = True

Exit Function
Set oDimStyle = Nothing
Set oTextStyle = Nothing
End Function

Just to clarify, all we've done with the routine above is set a whole bunch of style overrides on the current dimension style and then copied our modified style into a new dimension style. Odd way of doing it, but we work with the tools we have. Call the above routine with the following line:

If Not createDimStyle(48#) Then GoTo ErrorHandler

This will create a dimension style, the way we like with a scale appropriate for a 1/4"=1'-0" PaperSpace viewport.

Check out Part 2 of this article to find out how to create layers and set the default units in your drawing.

what a lot of work! why not just Xref&Bind the source drawing into one master template and 'Saveas'? As long as nothing is named 'Standard' there shouldn't be a problem. You can then add the Paperspace as Templates. Job Done! Script it!

Steve the CADmonkey

I hate CAD standards too!
I was looking for some AutoCAD training and found this new site for
auto cad training dallas texas along with your site. Have you seen this one yet?
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

vba, acad vba, cad vba, cad, visual basic, visual basic for applications, autocad vba, acad vba, training, vba training, cad training, acad training, autocad training, autocad vba training, bom, bill of material, meta-data, meta data, metadata, property data, data, inventor properties, document management, document, management,technical support resource for users of Autodesk Mechanical CAD Software including Autodesk Inventor & Mechanical Desktop inventor, autodeskinventor, inventor 2, inventor 3, inventor 4, inventor 5, inventor 6, inventor7, inventor 8, inventor 9, inventor 10, autodesk inventor, autodesk inventor2, autodesk inventor 3, autodesk inventor 4, autodesk inventor 5, autodeskinventor 6, autodesk inventor 7, autodesk inventor 8, autodesk inventor9, autodesk inventor 10, inventor r, inventor r2, inventor r3, inventor r4, inventor r5, inventor r6, inventor r7, inventor r8, inventor r9, inventorr10, autodesk inventor, autodesk inventor r2, autodesk inventor r3, autodeskinventor r4, autodesk inventor r5, autodesk inventor r6, autodesk inventorr7, autodesk inventor r8, autodesk inventor r9, autodesk inventor r10,inventor series, autodesk inventor series, inventor series 5, inventorseries R5, autodesk inventor series 5, autodesk inventor series r5, inventorseries 6, inventor series R6, autodesk inventor series 6, autodesk inventorseries r6, inventor autodesk, autodesk inventor download, autodesk inventortutorial, autodesk inventor help, autodesk inventor faq, autodesk inventortips, autodesk inventor routines, autodesk inventor support, autodesk inventor, inventor download, inventor tutorial, inventor help, inventorfaq, inventor tips, inventor routines, inventor support, inventor, inventor help line, help for inventor, inventortraining, autodesk inventor training, mdt, mdt 4, mdt 5,mdt 6, mdt 7, mdt 8, mdt4, mdt5, mdt6, mdt7, mdt8, mdt 2000, mdt 2002,mdt r4, mdt r5, mdt r6, mdt r2000, mdt r2002, mechanical desktop, mechanicaldesktop 4, mechanical desktop 5, mechanical desktop 6, mechanical desktop7, mechanical desktop 2000, mechanical desktop 2002, autodesk, autodesk auto cad, autodesk inc,training, education, auto cad support, autocad support, mcad, autocad mechanical,mechanical, autocad mechanical 6, autocad mechanical 7, autocad mechanical8, autocad mechanical 9, autocad mechanical r6, autocad mechanical r7,autocad mechanical r8, autocad mechanical r9, support, help, tips, routines, reseller, mech, cad, acad, technical, ontario, canada, f.a.q.,faq, answers, resource, barrie, autolisp, auto lisp, autocad, auto cad, autocad desktop, auto cad desktop, autocad inventor, auto cadinventor, powerpack, MAI, desktop, cad software, autocad lt, auto cad lt,cad cam, cad design, cad job, job cad, autocad lisp, auto cad lisp, 3dcad software, 3d cad, free, free cad software, service pack, render, system, computer, aided, drafting, design, manufacturing, modeling, solidmodeling, solid modelling