![]() |
【转帖】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 |
所有的时间均为北京时间。 现在的时间是 05:48 PM. |