|
macro help
i downloaded this macor that opens all part and drawings from an assembly. but, i just want to open all the parts.
can any of you api wizards tell me which part of the code to take out to do this? i know what to take out if i wanted just the drawings to open, but i can't figure out how to open just the parts.
thanks...rob
sub showallopenfiles()
dim swdoc as sldworks.modeldoc2
dim swalldocs as enumdocuments2
dim firstdoc as sldworks.modeldoc2
dim dummy as boolean
dim numdocsreturned as long
dim doccount as long
dim i as long
dim smsg as string
dim swapp as sldworks.sldworks
dim bdocwasvisible as boolean
dim openwarnings as long
dim openerrors as long
dim dwgpath as string
dim mydwgdoc as sldworks.modeldoc2
set swapp = application.sldworks
set swalldocs = swapp.enumdocuments2
set firstdoc = swapp.activedoc
doccount = 0
swalldocs.reset
swalldocs.next 1, swdoc, numdocsreturned
while numdocsreturned <> 0
bdocwasvisible = swdoc.visible
swapp.activatedoc swdoc.getpathname
dwgpath = swdoc.getpathname '
if (lcase(right(dwgpath, 3)) <> "drw") and (dwgpath <> "") then
dwgpath = left(dwgpath, len(dwgpath) - 3) & "drw"
set mydwgdoc = swapp.opendoc6(dwgpath, swdocdrawing, swopendocoptions_silent, "", openerrors, openwarnings)
if not mydwgdoc is nothing then
swapp.activatedoc mydwgdoc.getpathname
set mydwgdoc = nothing
end if
end if
swalldocs.next 1, swdoc, numdocsreturned
doccount = doccount + 1
wend
swapp.activatedoc firstdoc.getpathname
end sub
rob jensen
southern mn solidworks user group leader
rob, it looks like what is happening is that the string dwgpath is being changed from a .sldprt (or asm) file to a .slddrw file. i put a quote mark in front of the lines of code which need to be eliminated (commented out). let me know how that works.
sub showallopenfiles()
dim swdoc as sldworks.modeldoc2
dim swalldocs as enumdocuments2
dim firstdoc as sldworks.modeldoc2
dim dummy as boolean
dim numdocsreturned as long
dim doccount as long
dim i as long
dim smsg as string
dim swapp as sldworks.sldworks
dim bdocwasvisible as boolean
dim openwarnings as long
dim openerrors as long
dim dwgpath as string
dim mydwgdoc as sldworks.modeldoc2
set swapp = application.sldworks
set swalldocs = swapp.enumdocuments2
set firstdoc = swapp.activedoc
doccount = 0
swalldocs.reset
swalldocs.next 1, swdoc, numdocsreturned
while numdocsreturned <> 0
bdocwasvisible = swdoc.visible
swapp.activatedoc swdoc.getpathname
dwgpath = swdoc.getpathname '
'if (lcase(right(dwgpath, 3)) <> "drw") and (dwgpath <> "") then
'dwgpath = left(dwgpath, len(dwgpath) - 3) & "drw"
set mydwgdoc = swapp.opendoc6(dwgpath, swdocdrawing, swopendocoptions_silent, "", openerrors, openwarnings)
if not mydwgdoc is nothing then
swapp.activatedoc mydwgdoc.getpathname
set mydwgdoc = nothing
end if
'end if
swalldocs.next 1, swdoc, numdocsreturned
doccount = doccount + 1
wend
swapp.activatedoc firstdoc.getpathname
end sub
best regards,
tom
to defeat the wheat, go against the grain.
nope. i still get a "object library feature not supported" error
rob jensen
southern mn solidworks user group leader
hmm....it worked for me. when i opened the assembly, i made sure that everything was set to resolved, so the references were "visible". did you look at your tools>references in your vba editor? be sure that your sldworks 200x type library, solidworks 200x constants type library, and solidworks 200x commands type library references are all checked. this ensures that you won't have errors for a lack of loaded references.
cheers from nebraska,
tom
to defeat the wheat, go against the grain.
hey rob,
your macro looks a bit complicated for what you want it to do...
i have put together a small macro that will open all the parts in the open assembly document and then return to the initial assembly.
try it and let me know.
cheers,
--stav.
option explicit
dim swapp as sldworks.sldworks
dim modeldoc as sldworks.modeldoc2
dim moddoc as sldworks.modeldoc2
dim asmdoc as sldworks.assemblydoc
dim comp as sldworks.component2
dim vcomps as variant
dim i as integer
dim asmpath as string, compname as string
dim errors as long, warnings as long
sub main()
set swapp = application.sldworks
set modeldoc = swapp.activedoc
set asmdoc = modeldoc
asmpath = modeldoc.getpathname
vcomps = asmdoc.getcomponents(true)
for i = 0 to ubound(vcomps)
set comp = vcomps(i)
set moddoc = comp.getmodeldoc
if moddoc.gettype = 1 then
compname = comp.getpathname
set moddoc = swapp.activatedoc2(compname, false, errors)
end if
next
set modeldoc = swapp.activatedoc2(asmpath, false, errors)
end sub
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
edited: 10/20/2008 at 05:20 am by stavros antoniou
hi,
your code is very interesting. just wondering what would you modify to make it open only the sheetmetal parts of the active assembly ?
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
hi ben,
i had a look on the api and i cant seem to find a function call that tells you if a component is sheet metal or not.
however i am still on solidworks 2007 and i think they had enhanced the sheet metal api in solidworks 2008.
a "dirty" way i can think of telling, though i would not reccoment it, is to "look" for specific features in the components that identify and are only specific to sheet metal parts. you can do this by using the component2::featurebyname command and look for the flat pattern feature ("flat-pattern1") for example.
as i've said this issue might have been solved in later versions of solidworks (have a look in the api and see if there is a function call, under components that identifies if they are sheet metal or not).
hope this helped,
--stav.
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
edited: 10/20/2008 at 12:02 pm by stavros antoniou
originally posted by: stavros antoniou
hey rob,
your macro looks a bit complicated for what you want it to do...
i have put together a small macro that will open all the parts in the open assembly document and then return to the initial assembly.
try it and let me know.
cheers,
--stav.
option explicit
dim swapp as sldworks.sldworks
dim modeldoc as sldworks.modeldoc2
dim moddoc as sldworks.modeldoc2
dim asmdoc as sldworks.assemblydoc
dim comp as sldworks.component2
dim vcomps as variant
dim i as integer
dim asmpath as string, compname as string
dim errors as long, warnings as long
sub main()
set swapp = application.sldworks
set modeldoc = swapp.activedoc
set asmdoc = modeldoc
asmpath = modeldoc.getpathname
vcomps = asmdoc.getcomponents(true)
for i = 0 to ubound(vcomps)
set comp = vcomps(i)
set moddoc = comp.getmodeldoc
if moddoc.gettype = 1 then
compname = comp.getpathname
set moddoc = swapp.activatedoc2(compname, false, errors)
end if
next
set modeldoc = swapp.activatedoc2(asmpath, false, errors)
end sub
wonderful..!! works perfectly
thanks!!!
rob jensen
southern mn solidworks user group leader |
|