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

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


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
there are three terrible questions on SW translator as below huangyhg SolidWorks二次开发 3 2007-09-04 01:38 PM
How to start SW 2007 or SW 20006 via SW API? If I have two different versions of SW yogy SolidWorks二次开发 1 2007-05-21 09:19 AM


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


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