几何尺寸与公差论坛

 找回密码
 注册
查看: 790|回复: 0

【转帖】addcomponent4 - random behaviour

[复制链接]
发表于 2009-4-12 20:08:21 | 显示全部楼层 |阅读模式
addcomponent4 - random behaviour?
hi,
i am currently creating a sub routine that inserts parts into the current open assembly (pvassembly as modeldoc2 object), below is the code. there are a few other parts that need to be implement that haven't yet so disregard them (i.e. the mateto and mateside). the problem i am having is that for the parts i am working with this works great except for one part. the part is inserted in some assemblies but not in others, the error message i get is:
"attempted to read or write protected memory. this is often an indication that other memory is corrupt."
i'm at a lost and can't figure it out, any suggestions? all other parts are implemented is a similar fashion and the part file is not corrupt.
public sub addcomponenttoassembly(byref componentname as string, byref config as string, byref mateto as string, byref mateside as string)
dim errors as long
dim model as modeldoc2
dim fileerror as long
dim filewarning as long
dim swcomp as sldworks.component2
on error goto hanndler
model = iswapp.opendoc6(componentname, swdocumenttypes_e.swdocpart, swopendocoptions_e.swopendocoptions_silent, config, fileerror, filewarning)
iswapp.documentvisible(false, swdocumenttypes_e.swdocpart)
iswapp.activatedoc2(assemblytitle, true, errors)
swcomp = pvassembly.addcomponent4(componentname, "default", 0, 0, 0)
iswapp.closedoc(componentname)
'if mateto = "" then
'else
'end if
exit sub
hanndler:
msgbox(err.description)
msgbox(pvassembly.getpathname)
msgbox(componentname)
end sub
this could be with you opening the part silently you are not seeing certain errors that are preventing the component as reporting as open correctly. i actually experience a similar issue with certain files where opendoc6 opens the doc successfully, but the ierrors reports the file was not found! even though its open in front of me and the model it sent back was perfectly fine.
try taking silent off and seeing if any errors get shown for the part.
thanks for getting back to me,
i played with the opendocoption and as you suggested and i switched to loadmodel which still didn't, i thought maybe the visiblity was important so i commented out the .documentvisible property for the assembly (in another sub that creates pvassembly) and voila it works!
does anyone know how to silent load assembly creation or modification?
thanks,
ed
swapp.visible = false will be your only other option.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 01:39 , Processed in 0.035264 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表