|
changing layer properties with a macro
through several days of scouring the internet, i can not find anything on how to do these things using a macro:
- hide a layer
- unhide a layer
- change a layer's color
the solidworks macro recorder seems not to work with recording anything that has to do with any changes to layers. i don't know why.
85% of the macros i have found on the internet didn't work correctly with solidworks 2008, so i had to go through them line by line and try to figure them out or discard them altogether.
one problem i have been trying to fix is place our companies sheet format on a drawing. (which i finally found a macro to to this) this format has two different layers. one for proprietary information and one without. i just wanted to automate the hiding of proprietary layer (a) and unhiding of non-proprietary layer (b) and vice versa (maybe with a form and buttons), but i can't find any info on how to hide/unhide a layer. i can create a form and buttons, but i don't know what coding to put on the buttons.
the second problem i have is to change the color of a layer. i have a macro to change all the dimensions to a layer, but i also want to change that layer to say blue.
if anyone could help me i would greatly appreciate it. i am new to macros and am a decent software programmer. that's how i was able to decipher some other peoples macros and tailor them to my needs. i've actually had to translate some german websites just to see the macros. i'm glad computer programing is a language all it's own and not country specific. thanks in advance for anyone's help.
joe,
i am no expert at this but i found the following code that creates a layer and gives it a coulor as well. hope it helps you get an idea of how to work with certain features.
sub main()
dim swapp as sldworks.sldworks
dim swdraw as sldworks.drawingdoc
set swapp = application.sldworks
set swdraw = swapp.activedoc
'check to see if a drawing is loaded
if swdraw is nothing then
swapp.sendmsgtouser "please open a drawing."
exit sub
end if
swdraw.clearselection
dim retval as boolean
retval = swdraw.createlayer("myredlayer", "red", rgb(255, _
0, 0), swlinestitch, swlw_thick, true)
end sub
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
edited: 10/01/2008 at 11:32 am by ben guenther
answer i got it all figured out finally. thanks ben for some help on creating layers, i can use that also. i found these other macros on a different forum, i don't know why they aren't here. to anyone that wants to take advantage and use them, here they are.
to change a color of any layer:
dim swapp as sldworks.sldworks
dim swdoc as sldworks.modeldoc2
dim swdwg as sldworks.drawingdoc
dim swlyrmgr as sldworks.layermgr
dim swlayer as sldworks.layer
sub layercolorchange()
set swapp = application.sldworks
set swdoc = swapp.activedoc
if swdocdrawing <> swdoc.gettype then
msgbox "this only works for drawings"
exit sub
end if
set swdwg = swdoc
set swlyrmgr = swdoc.getlayermanager
'copy and paste this block until you have as many as you want (change dimensions below to your layer name)
set swlayer = swlyrmgr.getlayer("dimensions") 'type the layer name here.
swlayer.color = 16711680 '(this is blue 0,0,255) type the number for the desired color here.
end sub
to turn a layer on or off:
sub layervisibility()
dim swapp as object
dim part as object
dim swlayermgr as object
dim swlayer as object
set swapp = createobject("sldworks.application")
set part = swapp.activedoc
set swlayermgr = part.getlayermanager
' change dimensions below to your layer name
set swlayer = swlayermgr.getlayer("dimensions")
' to turn layer on, change false (off) to true (on)
swlayer.visible = false
set swlayer = nothing
set swlayermgr = nothing
set part = nothing
set swapp = nothing
end sub
of course these can be cleaned up and combined with any other macro (which is what i am doing).
quick |
|