×
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

Layer Macro

Layer Macro

Layer Macro

(OP)
     Does anyone have a macro, or know where to find a macro that would reset layer colors on a drawing to a pre-determined color.  We have older drawings that have different colored layers than the newer ones.  We want to have the newer layer colors, but don't want to have to manually update the layer colors for each drawing.  A macro that sets layer colors automatically would be nice.  Anyone?

Pete

RE: Layer Macro

pdybeck,

I don't know of a macro for that but, at the risk of hi-jacking this thread, can you explain to me what purpose layers serve in a SolidWorks drawing? It sounds like your company actively uses them. To me layers have always seemed to be an accomodation to imported .DWG's and I have never used them.

RE: Layer Macro

We use layers so we have the ability to easily hide certain elements of a drawing (balloons, hatching, etc.)

Rob Rodriguez CSWP
www.robrodriguez.com
SW 2006 SP 2.0EV

RE: Layer Macro

(OP)
same as rockguy.

RE: Layer Macro

pdybeck,

While I do not have a full blown macro, I can get you started if you want to write your own.

CODE

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swLayMgr As SldWorks.LayerMgr
Dim swLayer As SldWorks.Layer

Dim LayerNames As Variant
Dim layerName As Variant

Sub main()

    Set swApp = Application.SldWorks
    
    Set swModel = swApp.ActiveDoc
    
    Set swLayMgr = swModel.GetLayerManager
    
    LayerNames = swLayMgr.GetLayerList
    
    For Each layerName In LayerNames
    
        Set swLayer = Nothing
        
        Set swLayer = swLayMgr.GetLayer(layerName)
        
        Debug.Print layerName & " color = " & swLayer.Color
        
    Next
    
End Sub

Sub SetLayerColor()

    Set swApp = Application.SldWorks
    
    Set swModel = swApp.ActiveDoc
    
    Set swLayMgr = swModel.GetLayerManager
    
    Set swLayer = swLayMgr.GetLayer(YourLayerName)
    
    swLayer.Color = YourColorNumber

End Sub

The code in Sub main will get you what the existing color numbers are (displayed in the immediate window in the VBA editor).  The code in Sub SetLayerColor will set the a layer to the color you desire.  To do mulitple layers you cand just copy the last two lines and change the layer name and layer color.  Remember, in the VBA editor menu, to go to Tools, References and check SldWorks 2005 Type Library and SolidWorks 2005 Constant type library.  Otherwise the code will not run.  If you are using SW2006 pick the libraries with 2006 in them.

Regards,

Regg

RE: Layer Macro

(OP)
Regg,

   Thanks for your help.  I will look at modifying this to get what I need.  I tried recording a macro while changing a layer color to get a peak at the calls, but nothing ended up recording.  I closed down, re-started, tried it again, and saw the same result.  Don't know why its not recording my actions.  Are there some things that don't get recorded?  If there are, how would I know what doesn't get recorded?  Thanks for the start.

Pete

RE: Layer Macro

pdybeck,

As a general rule, anything outside of the graphics display window does not get recorded (not always the case).  This is especially true of menu picks or stand-alone dialog boxes (which is what the layer box is).  As to how to know what does not get recorded, do exactly what you did; look at what got recorded.

Regards,

Regg

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