|
switching config on part in sub-assy
hello fella's !
i've been using following code to switch the configurations of a subassy :
boolstatus = modeldoc2.extension.selectbyid2("yadayada", "component", yada)
set modeldoc2 = swapp.activedoc
set swselmgr = modeldoc2.selectionmanager
set swselobj = swselmgr.getselectedobject4(1)
swselobj.referencedconfiguration = tkc
this has been working great.
now i was planning on using the same method to switch the configuration of a part within a subassy. however this doesn't work ...
boolstatus = modeldoc2.extension.selectbyid2("yadayada", "component",yada)
set swselmgr = modeldoc2.selectionmanager
set swselobj = swselmgr.getselectedobject4(1)
dim config as string
select case typedeurcb.value
case 19
config = "60"
case 20
config = "80"
case 21
config = "100"
case 20
config = "140"
end select
swselobj.referencedconfiguration = config
any ideas ? advice is as usual welcome !
greets,
bert
*edit/p.s.: *
i'm not getting any errors on running the above code, but the configuration simply does not change into the desired one ...
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
edited: 03/16/2009 at 10:17 am by bert de spiegelaere
hi bert,
have you verified that you have actually selected the right component? you don't show the options you are using for the selectbyid operation - are you sure you don't have anything else selected so when using the getselectedobject4(1) you don't get the right component?
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
hi jorn, thanks for replying !
i'm using the same way of selection as the original is.
boolstatus = modeldoc2.extension.selectbyid2("kader-2@draaideur/pvc dagkant-1@kader", "component", 0, 0, 0, false, 0, nothing, 0)
set swselmgr = modeldoc2.selectionmanager
set swselobj = swselmgr.getselectedobject4(1)
this works with my sub assy's .
i have 2 sub-assy's that effectively get a config switch from this code, but my part doesn't want to switch. i'm sure the right part is selected, as it gets highlighted (in blue) in the feature tree !
maybe it has somthing to do with the config names having in them ? (this part is based on weldments/structural members).
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
every component in a main assembly has a component object associated with it. however, when that component is inside a subassembly there are certain things you can't do. i believe you're going to have to get the component in the context of the subassembly that holds it.
i'll get you eh steve, if it's the last thing i dooooo!
hiya josh !
that made sense to me, but how do you figure i'd do that ?
open the subassy, change the parts config and then returning to the main assy ?
greets,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
sort of like that. i would use:
name2 to get the full name (including instance number) of the component you selected.
getparent to get the parent component of the component you are interested in.
getmodeldoc2 to get the modeldoc2 object for the parent subassembly
getcomponents to get an array of all components of the parent subassembly
and then loop through the component array, comparing the name2 to the component's name in main assembly. when the names match, you've found it.
while this sounds like a lot of processing, it's actually very fast. much faster than opening the subassembly in its own window and then trying to use selectbyid to select it.
i'll get you eh steve, if it's the last thing i dooooo!
i can go for that, looks like you know what yer on about.
is there any way on this bright world you could/would provide me with a sample of code on this ?
if thats not to much to ask offcourse, i'd hate to bother ..
otherwise i'll try to look into this method myself, no worries.
thanks, bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
option explicit
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim swselmgr as sldworks.selectionmgr
dim swselcomp as sldworks.component2
dim swparentcomp as sldworks.component2
dim swparentdoc as sldworks.modeldoc2
dim vcompsofparent as variant
dim vcompofparent as variant
dim swcompofparent as sldworks.component2
dim snameinmain as string
dim snameinparent as string
dim bret as boolean
dim generalselobj as object
dim i as integer
dim curselcount as long
dim newobjtoselect as object
dim swver as variant
dim resolveit as integer
dim doctitle as string
dim dwgdoccomp as drawingcomponent
dim oldtoggleval as long
set swapp = application.sldworks
set swmodel = swapp.activedoc
if swmodel.gettype <> swdocassembly then
msgbox "this macro works on assembly documents only."
exit sub
end if
set swselmgr = swmodel.selectionmanager
curselcount = swselmgr.getselectedobjectcount
if curselcount = 0 then
msgbox "nothing was selected"
exit sub
end if
set generalselobj = swselmgr.getselectedobject(curselcount)
set swselcomp = swselmgr.getselectedobjectscomponent(curselcount)
snameinmain = swselcomp.name2
set swparentcomp = swselcomp.getparent
if not swparentcomp is nothing then
set swparentdoc = swparentcomp.getmodeldoc
vcompsofparent = swparentdoc.getcomponents(true)
for each vcompofparent in vcompsofparent
set swcompofparent = vcompofparent
if instr(1, snameinmain, swcompofparent.name2, vbtextcompare) > 0 then
exit for
end if
next
debug.print "found " & swcompofparent.name2 & " in assembly " & swparentdoc.gettitle
else
debug.print "the selected component " & snameinmain & " has no parent."
end if
end sub
i'll get you eh steve, if it's the last thing i dooooo!
whoa thats heavy ...
and this really is the utmost straightforeward way of switching a config of a part within a subassy ?
i'm certainly not doubting it is, just feels like overkill
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
well, there are always other ways, but this is the most straightforward that comes to mind. it's not complete, though. all this shows is how to get the child component in the context of its parent assembly. it doesn't change it. to do this right you need to get the referenced config of the parent assembly in the main assembly and make sure you change the component config in the proper parent config.
i'll get you eh steve, if it's the last thing i dooooo!
so then, how does the above translate into following situation ?
(main assy)
draaideur (configname = default)
|
--> (sub assy)
kader (configname = default)
|
--> (part)
pvc dagkant (has 4 configs to switch when needed)
i'm trying to puzzle together the above sub .
that successfully selects the part doesnt it ?
thanks for the input,
bert
*edit / ps: when i typed this reply, it was intended for better readability ..
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
edited: 03/17/2009 at 03:13 am by bert de spiegelaere |
|