几何尺寸与公差论坛------致力于产品几何量公差标准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-12, 09:33 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】layer macro

layer macro
good morning all,
i found this sample in the api help. i would like to use this macro but i cannot get it to work. could someone please lead me in the right direction for it to work.
option explicit
public enum swlinestyles_e
swlinecontinuous = 0
swlinehidden = 1
swlinephantom = 2
swlinechain = 3
swlinecenter = 4
swlinestitch = 5
swlinechainthick = 6
end enum
public enum swlineweights_e
swlw_none = -1
swlw_thin = 0
swlw_normal = 1
swlw_thick = 2
swlw_thick2 = 3
swlw_thick3 = 4
swlw_thick4 = 5
swlw_thick5 = 6
swlw_thick6 = 7
swlw_number = 8
swlw_layer = 9
end enum
private sub changecomponentlayer _
( _
swapp as sldworks.sldworks, _
swdraw as sldworks.drawingdoc, _
swdrawcomp as sldworks.drawingcomponent, _
slayername as string _
)
dim bret as boolean
' form a legal layer name by replacing backslash (/) and at sign (@) symbols
' with underscores
slayername = replace(slayername, "/", "_")
slayername = replace(slayername, "@", "_")
bret = swdraw.createlayer( _
slayername, _
"layer for " & slayername, _
0, swlinecontinuous, swlw_normal, true): debug.assert bret
swdrawcomp.layer = slayername
end sub
sub processdrawingcomponent _
( _
swapp as sldworks.sldworks, _
swdraw as sldworks.drawingdoc, _
swdrawcomp as sldworks.drawingcomponent, _
spadstr as string _
)
dim vdrawcompchildarr as variant
dim vdrawcompchild as variant
dim swdrawcompchild as sldworks.drawingcomponent
debug.print spadstr & swdrawcomp.name
changecomponentlayer swapp, swdraw, swdrawcomp, swdrawcomp.name
vdrawcompchildarr = swdrawcomp.getchildren
if not isempty(vdrawcompchildarr) then
for each vdrawcompchild in vdrawcompchildarr
set swdrawcompchild = vdrawcompchild
processdrawingcomponent swapp, swdraw, swdrawcompchild, spadstr + " "
next
end if
end sub
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim swdraw as sldworks.drawingdoc
dim swselmgr as sldworks.selectionmgr
dim swview as sldworks.view
dim swdrawcomp as sldworks.drawingcomponent
dim bret as boolean
set swapp = application.sldworks
set swmodel = swapp.activedoc
set swdraw = swmodel
set swselmgr = swmodel.selectionmanager
set swview = swselmgr.getselectedobject5(1)
set swdrawcomp = swview.rootdrawingcomponent
debug.print "file = " & swmodel.getpathname
debug.print " " & swview.name & " [" & swview.type & "]"
processdrawingcomponent swapp, swdraw, swdrawcomp, " "
end sub
'-------------------
tony hayes
product/tool designer
grass america inc.
.grassusa.com
sw 2008 sp5.0
dell t3400
windows vista business 64-bit
intel core2 quad q9550 2.83 ghz, 4gb ram
nvidia quadro fx 3700 512mb
101.96 punch holder rebuild
click for full image
what exactly is the problem you are having?
thanks for the quick response.
first i know very little about api but i am tring to learn it. i plan on buying your book in the next couple of weeks. how much is your book in us dollers from your website?
i was thinking that i could copy that code from the help into the api, is that correct? after i copied it then i try to run i get this error.
tony hayes
product/tool designer
grass america inc.
.grassusa.com
sw 2008 sp5.0
dell t3400
windows vista business 64-bit
intel core2 quad q9550 2.83 ghz, 4gb ram
nvidia quadro fx 3700 512mb
101.96 punch holder rebuild
click for full image
if you select the view on your drawing this program work's.
marc
public enum swlinestyles_e
swlinecontinuous = 0
swlinehidden = 1
swlinephantom = 2
swlinechain = 3
swlinecenter = 4
swlinestitch = 5
swlinechainthick = 6
end enum
public enum swlineweights_e
swlw_none = -1
swlw_thin = 0
swlw_normal = 1
swlw_thick = 2
swlw_thick2 = 3
swlw_thick3 = 4
swlw_thick4 = 5
swlw_thick5 = 6
swlw_thick6 = 7
swlw_number = 8
swlw_layer = 9
end enum
private sub changecomponentlayer(swapp as sldworks.sldworks, swdraw as sldworks.drawingdoc, swdrawcomp as sldworks.drawingcomponent, slayername as string)
dim bret as boolean
slayername = replace(slayername, "/", "_")
slayername = replace(slayername, "@", "_")
bret = swdraw.createlayer(slayername, "layer for " & slayername, 0, swlinecontinuous, swlw_normal, true): debug.assert bret
swdrawcomp.layer = slayername
end sub
sub processdrawingcomponent(swapp as sldworks.sldworks, swdraw as sldworks.drawingdoc, swdrawcomp as sldworks.drawingcomponent, spadstr as string)
dim vdrawcompchildarr as variant
dim vdrawcompchild as variant
dim swdrawcompchild as sldworks.drawingcomponent
debug.print spadstr & swdrawcomp.name
changecomponentlayer swapp, swdraw, swdrawcomp, swdrawcomp.name
vdrawcompchildarr = swdrawcomp.getchildren
if not isempty(vdrawcompchildarr) then
for each vdrawcompchild in vdrawcompchildarr
set swdrawcompchild = vdrawcompchild
processdrawingcomponent swapp, swdraw, swdrawcompchild, spadstr + " "
next
end if
end sub
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim swdraw as sldworks.drawingdoc
dim swselmgr as sldworks.selectionmgr
dim swview as sldworks.view
dim swdrawcomp as sldworks.drawingcomponent
dim bret as boolean
set swapp = application.sldworks
set swmodel = swapp.activedoc
set swdraw = swmodel
set swselmgr = swmodel.selectionmanager
set swview = swselmgr.getselectedobject5(1)
set swdrawcomp = swview.rootdrawingcomponent
debug.print "file = " & swmodel.getpathname
debug.print " " & swview.name & " [" & swview.type & "]"
processdrawingcomponent swapp, swdraw, swdrawcomp, " "
end sub
thank you marc,
tony hayes
product/tool designer
grass america inc.
.grassusa.com
sw 2008 sp5.0
dell t3400
windows vista business 64-bit
intel core2 quad q9550 2.83 ghz, 4gb ram
nvidia quadro fx 3700 512mb
101.96 punch holder rebuild
be careful sometimes from copying examples and pasting them into vba as some add extra line breaks which cause errors.
on top of that the examples are never brilliant for copy/pasting, really you should just read them to get the information you need from then and create your macro from there.
the book is £36 including shipping.
thank you the help and warnings marc and luke.
luke is that us doller? seems that i seen $36 gbp on your website, just worry about exchange ratio.
tony hayes
product/tool designer
grass america inc.
.grassusa.com
sw 2008 sp5.0
dell t3400
windows vista business 64-bit
intel core2 quad q9550 2.83 ghz, 4gb ram
nvidia quadro fx 3700 512mb
101.96 punch holder rebuild
sorry typo yes £gbp, so $53.35 atm

edited: 11/13/2008 at 11:12 am by luke malpass
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】how do i slow a macro down yang686526 SolidWorks二次开发 0 2009-04-12 09:10 PM
【转帖】copy an existent sketch into a macro yang686526 SolidWorks二次开发 0 2009-04-12 08:31 PM
【转帖】batch w user input macro yang686526 SolidWorks二次开发 0 2009-04-12 08:17 PM


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


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