|
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. |
|