几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 09:41 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】changing layer properties with a macro

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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】add custom properties yang686526 SolidWorks二次开发 0 2009-04-13 08:41 AM
【转帖】using custom properties in a macro yang686526 SolidWorks二次开发 0 2009-04-12 10:45 PM
【转帖】macro for adding customconfiguration properties yang686526 SolidWorks二次开发 0 2009-04-12 09:37 PM
【转帖】layer macro yang686526 SolidWorks二次开发 0 2009-04-12 09:33 PM
【转帖】copy an existent sketch into a macro yang686526 SolidWorks二次开发 0 2009-04-12 08:31 PM


所有的时间均为北京时间。 现在的时间是 12:31 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多