|
error 13 when i modify the sw document
hi!
when i change manually the sw assembly like change mates values and then run the macro i have error 13 because vchildcomp=nothing.
vchildcomp = swcomp.getchildren
for j = 0 to ubound(vchildcomp)'error 13
but if i run again the macro works well. why?
thanks!
you have not declared the data type so it is dynamically casting it first run, then staying in memory as that type, and second run it doesnt have that problem. change to:
dim vchildcomp as variant
vchildcomp = swcomp.getchildren
for j = 0 to ubound(vchildcomp)
sorry, i had not copy all the code. i have like you say.
sub components(swcomp as sldworks.component2, assy as sldworks.assemblydoc)
dim swchildcomp as sldworks.component2
dim vchildcomp as variant
dim j as integer
vchildcomp = swcomp.getchildren
for j = 0 to ubound(vchildcomp)
set swchildcomp = vchildcomp(j)
.....
change it to this and see if error happens in the 2nd line or 4th line
dim j as integer, k as integer
k = ubound(vchildcomp)
vchildcomp = swcomp.getchildren
for j = 0 to k
set swchildcomp = vchildcomp(j)
.....
error 13 in line k = ubound(vchildcomp) because k=0
sorry lines mixed up in order...
dim j as integer, k as integer
vchildcomp = swcomp.getchildren
k = ubound(vchildcomp)
for j = 0 to k
set swchildcomp = vchildcomp(j)
.....
the error is in the same line k = ubound(vchildcomp). vchildcomp=empty and k=0.
it means that either your swcomp is invalid or the getchildren is failing to return any children meaning it doesnt have any, so the problem will lie in the code before the function itself is called i would say. perhaps posting your macro or emailing it to me so i can take a better look
code:
option explicit
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
sub main()
dim swassy as sldworks.assemblydoc
dim swconf as sldworks.configuration
dim swchildcomp as sldworks.component2
set swapp = createobject("sldworks.application")
set swmodel = swapp.activedoc
set swassy = swmodel
set swconf = swassy.getactiveconfiguration
set swchildcomp = swconf.getrootcomponent
change 'sub that change modeldoc configuration
child swchildcomp, swassy 'call child sub
end sub
sub change()
swmodel.showconfiguration ("default")
end sub
sub child(swcomp as sldworks.component2, assy as sldworks.assemblydoc)
dim swchildcomp as sldworks.component2
dim vchildcomp as variant
dim j as integer
dim boolstatus as boolean
dim c as sldworks.modeldoc2
dim retval as long, info as long
vchildcomp = swcomp.getchildren 'error 13 because vchildcomp=empty
for j = 0 to ubound(vchildcomp)
set swchildcomp = vchildcomp(j)
boolstatus = swchildcomp.select3(false, nothing)
set c = swchildcomp.getmodeldoc
if c.gettype = 1 then
retval = assy.editpart2(true, false, info)
else
assy.editassembly
end if
assy.editassembly
child swchildcomp, assy 'call to child sub again
next j
end sub
i think that the problem is in sub change. in the sub main i have defined swassy because i need in sub child. but in sub change i use swmodel... to change modeldoc's configuration. how can i do to change an assembly configuration? i don´t know where i have to define the swassy. help, please!
edited: 03/18/2009 at 06:10 am by marian ruiz
sub main()
dim swassy as sldworks.assemblydoc
dim swconf as sldworks.configuration
dim swchildcomp as sldworks.component2
set swapp = createobject("sldworks.application")
set swmodel = swapp.activedoc
set swassy = swmodel
change
set swconf = swassy.getactiveconfiguration
set swchildcomp = swconf.getrootcomponent
'sub that change modeldoc configuration
child swchildcomp, swassy 'call child sub
end sub
edited: 03/18/2009 at 06:19 am by ivana kolin
is your model fully resolved? |
|