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
Pete






RE: Layer Macro
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
Rob Rodriguez CSWP
www.robrodriguez.com
SW 2006 SP 2.0EV
RE: Layer Macro
RE: Layer Macro
While I do not have a full blown macro, I can get you started if you want to write your own.
CODE
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
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
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