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
ErrorHandler:
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
Next
.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
ErrorHandler:
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.
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
ErrorHandler:
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
Next
.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
ErrorHandler:
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.
Comments:
<< Home
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!
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
auto cad training dallas texas along with your site. Have you seen this one yet?
<< Home

