×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Dimension color macro

Dimension color macro

Dimension color macro

(OP)
I haven't found a particular thread on this, but there are some that are close.  We purchased a couple of Konica Minolta Bizhub C250'S color laser printers and now print dimensions on one layer.  BOM's, notes, balloons on another layer.

From "Macro for layer color change?" thread
http://www.eng-tips.com/viewthread.cfm?qid=166199&page=2
I know the colors for the 2 layers.

I also read "How to find OVERRIDE Dimensions in a drawing?"
http://www.eng-tips.com/viewthread.cfm?qid=165835&page=1
Which gave me the idea for this macro.

Objective
  • Automatically find dimensions and place them on existing "Dims" layer.
  • Automatically find BOM's, Leaders, Notes and place them on existing "Text layer.
2 existing layers:
Dims layer color = 771752142
text layer color = 10944512

If BOM's, notes, baloons would be too much trouble, I would settle for help on just getting the dims on there own layer.

SW06 SP5.0

Flores

RE: Dimension color macro

The color override macro iterates through all the display dimensions in a drawing.  However, dimensions are just a type of annotation.  You can iterate through all the annotations in almost the exact same manner.  The types of annotations are:

swCThread

swDatumTag

swDatumTargetSym

swDisplayDimension

swGTol

swNote

swSFSymbol

swWeldSymbol

swCustomSymbol

swDowelSym

swLeader

swCenterMarkSym

swCenterLine

swDatumOrigin

swWeldBeadSymbol

Which annotations to you want moved to which layers?  I assume swDisplayDimension goes to the "Dims" layer, but I'm guessing you don't want every one of these anotations on the "Text" layer.

RE: Dimension color macro

Oops, looks like my help file's not up to date.  Here is the full list of annotation types (alphabetical, not numerical order!):

swBlock
swCenterLine
swCenterMarkSym
swCThread
swCustomSymbol
swDatumOrigin
swDatumTag
swDatumTargetSym
swDisplayDimension
swDowelSym
swGTol
swLeader
swNote
swSFSymbol
swTableAnnotation
swWeldBeadSymbol
swWeldSymbol

You should be able to add/switch etc these to the code below:

CODE

Const COLORQUERY As Boolean = False
Const TEXTLAYERCOLOR As Long = 10944512
Const DIMSLAYERCOLOR As Long = 771752142

Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swAnnot As SldWorks.Annotation
Dim sMsg As String
Dim swLyrMgr As SldWorks.LayerMgr
Dim swLayer As SldWorks.Layer


Sub MoveDimsAndTablesToLayers()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc

If swDoc.GetType <> swDocDRAWING Then
    MsgBox "This macro only works for drawing files."
    Exit Sub
End If

Set swDwg = swDoc

Set swLyrMgr = swDoc.GetLayerManager

If COLORQUERY Then
    Set swLayer = swLyrMgr.GetLayer(swLyrMgr.GetCurrentLayer)
    MsgBox "The color of layer " & swLayer.Name & " is " & swLayer.Color
    Exit Sub
End If

Set swLayer = swLyrMgr.GetLayer("Text")
swLayer.Color = TEXTLAYERCOLOR
Set swLayer = swLyrMgr.GetLayer("Dims")
swLayer.Color = DIMSLAYERCOLOR

Set swView = swDwg.GetFirstView
While Not (swView Is Nothing)
    Set swAnnot = swView.GetFirstAnnotation3
    While Not swAnnot Is Nothing
        If swAnnot.GetType = swDisplayDimension Then
            swAnnot.Layer = "Dims"
        ElseIf swAnnot.GetType = swNote Then
            swAnnot.Layer = "Text"
        ElseIf swAnnot.GetType = swTableAnnotation Then
            swAnnot.Layer = "Text"
        End If
        Set swAnnot = swAnnot.GetNext3
    Wend
    Set swView = swView.GetNextView
Wend

Set swLayer = Nothing
Set swLyrMgr = Nothing
Set swAnnot = Nothing
Set swView = Nothing
Set swDwg = Nothing
Set swDoc = Nothing
Set swApp = Nothing

End Sub

RE: Dimension color macro

(OP)
Thanks handleman! That worked like a charm.2thumbsup

SW06 SP5.0

Flores

RE: Dimension color macro

(OP)
handleman, I hope I'm not being greedy, but I have 1 more request.  We have some text "-NOT FOR PRODUCTION-" on a layer called "Not for Production" that we have on our drawing templates.  We keep this layer visible while our projects are in the prototype stage.  After all tweaks are made and a purchase order is cut, then we turn the "Not for Production" layer off.

Is there anyway to either skip this layer or skip that text?  

SW06 SP5.0

Flores

RE: Dimension color macro

Sure... just add another "If" block to check the current layer of the active annotation.  Like so:

CODE

Const COLORQUERY As Boolean = False
Const TEXTLAYERCOLOR As Long = 10944512
Const DIMSLAYERCOLOR As Long = 771752142

Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swAnnot As SldWorks.Annotation
Dim sMsg As String
Dim swLyrMgr As SldWorks.LayerMgr
Dim swLayer As SldWorks.Layer


Sub MoveDimsAndTablesToLayers()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc

If swDoc.GetType <> swDocDRAWING Then
    MsgBox "This macro only works for drawing files."
    Exit Sub
End If

Set swDwg = swDoc

Set swLyrMgr = swDoc.GetLayerManager

If COLORQUERY Then
    Set swLayer = swLyrMgr.GetLayer(swLyrMgr.GetCurrentLayer)
    MsgBox "The color of layer " & swLayer.Name & " is " & swLayer.Color
    Exit Sub
End If

Set swLayer = swLyrMgr.GetLayer("Text")
swLayer.Color = TEXTLAYERCOLOR
Set swLayer = swLyrMgr.GetLayer("Dims")
swLayer.Color = DIMSLAYERCOLOR

Set swView = swDwg.GetFirstView
While Not (swView Is Nothing)
    Set swAnnot = swView.GetFirstAnnotation3
    While Not swAnnot Is Nothing
        If swAnnot.Layer = "Not For Production" Then
            'Skip this annotation
        ElseIf swAnnot.GetType = swDisplayDimension Then
            swAnnot.Layer = "Dims"
        ElseIf swAnnot.GetType = swNote Then
            swAnnot.Layer = "Text"
        ElseIf swAnnot.GetType = swTableAnnotation Then
            swAnnot.Layer = "Text"
        End If
        Set swAnnot = swAnnot.GetNext3
    Wend
    Set swView = swView.GetNextView
Wend

Set swLayer = Nothing
Set swLyrMgr = Nothing
Set swAnnot = Nothing
Set swView = Nothing
Set swDwg = Nothing
Set swDoc = Nothing
Set swApp = Nothing

End Sub

RE: Dimension color macro

(OP)
CBL, that worked, but our older drawings already have the "Not for Production" layer on them and by improving this macro, adding the block will not be required.

handleman, for some odd reason the text for "-NOT FOR PRODUCTION-" was still put on the text layer and turned to the text layer color.  I fiddled with it and added:

Const PRODUCTIONLAYERCOLOR As Long = 771752142

and

Set swLayer = swLyrMgr.GetLayer("Not for Production")
swLayer.Color = PRODUCTIONLAYERCOLOR
and it is working now.

CODE

Const COLORQUERY As Boolean = False
Const TEXTLAYERCOLOR As Long = 10944512
Const DIMSLAYERCOLOR As Long = 771752142
Const PRODUCTIONLAYERCOLOR As Long = 771752142

Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swAnnot As SldWorks.Annotation
Dim sMsg As String
Dim swLyrMgr As SldWorks.LayerMgr
Dim swLayer As SldWorks.Layer


Sub MoveDimsAndTablesToLayers()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc

If swDoc.GetType <> swDocDRAWING Then
    MsgBox "This macro only works for drawing files."
    Exit Sub
End If

Set swDwg = swDoc

Set swLyrMgr = swDoc.GetLayerManager

If COLORQUERY Then
    Set swLayer = swLyrMgr.GetLayer(swLyrMgr.GetCurrentLayer)
    MsgBox "The color of layer " & swLayer.Name & " is " & swLayer.Color
    Exit Sub
End If

Set swLayer = swLyrMgr.GetLayer("Text")
swLayer.Color = TEXTLAYERCOLOR
Set swLayer = swLyrMgr.GetLayer("Dims")
swLayer.Color = DIMSLAYERCOLOR
Set swLayer = swLyrMgr.GetLayer("Not for Production")
swLayer.Color = PRODUCTIONLAYERCOLOR

Set swView = swDwg.GetFirstView
While Not (swView Is Nothing)
    Set swAnnot = swView.GetFirstAnnotation3
    While Not swAnnot Is Nothing
        If swAnnot.Layer = "Not for Production" Then
            'Skip this annotation
        ElseIf swAnnot.GetType = swDisplayDimension Then
            swAnnot.Layer = "Dims"
        ElseIf swAnnot.GetType = swNote Then
            swAnnot.Layer = "Text"
        ElseIf swAnnot.GetType = swTableAnnotation Then
            swAnnot.Layer = "Text"
        End If
        Set swAnnot = swAnnot.GetNext3
    Wend
    Set swView = swView.GetNextView
Wend

Set swLayer = Nothing
Set swLyrMgr = Nothing
Set swAnnot = Nothing
Set swView = Nothing
Set swDwg = Nothing
Set swDoc = Nothing
Set swApp = Nothing

End Sub

SW06 SP5.0

Flores

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources