几何尺寸与公差论坛

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

【转帖】children of component pattern

[复制链接]
发表于 2009-4-13 09:43:28 | 显示全部楼层 |阅读模式
children of component pattern
for a component pattern (localpattern1) in an assembly i want to get a list of the child instances of the pattern. i have been using feature.getchildren which actually works fine.
my problems arise if localpattern1 or some if the component instances from localpattern1 is used in another pattern (localpattern2). if i now use getchildren on localpattern1 the result also includes some but not all component instances from the second pattern!
the api help for feature.getchildren states that it only returns "direct children" - not children of children. however that doesn't seem to be the case... (could it be a bug...?)
can anyone throw some light at me - or give me ideas on how to only get the "direct children" of a component pattern?
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
hi jorn
i'm writing a program that makes a list of all the parts in an assembly. it is listing folders and parts. when i go through the feature tree the patterned parts show up before the pattern feature and when i try to use the feature.getchildren i just get an empty variant. yours is the only post i could find on this subject and it sounds like you're farther than i am. did you ever get the problems solved?
hi dan,
old case - i don't remember all the details and i am not sure for what project/task i wanted to use getchildren but i think i have located the right one.
i am pretty sure i had to give up getchildren because of the problems mentioned in my first post. instead i have used swfeature.getfirstsubfeature and swsubfeature.getnextsubfeature - see the following example (fraction of a procedure). please ignore what is irrelevant for you. my need was to identify and select components with specific names in a component pattern.
'-------------
'select the component pattern
call selectobject(patternfeaturename, "comppattern", 0, 0, 0, false, 0, nothing, 0)
'get the pattern feature
set swfeature = part.selectionmanager.getselectedobject6(1, -1)
set swsubfeature = swfeature.getfirstsubfeature
'if swsubfeature it nothing then exit sub (it is nothing when the pattern amount is 1 = no children)
if swsubfeature is nothing then
exit sub
end if
'clear selection list
part.clearselection2 true
'get number of characters in component name
componentnamelength = len(componentname)
'loop as long as swsubfeature is not nothing
do while (not (swsubfeature is nothing))
subfeaturename = swsubfeature.name
'debug.print subfeaturename
'if componentname is empty or the name of the current subfeature is equal to the specified componentname
'then select the subfeature.
if componentname = "" or left(subfeaturename, componentnamelength) = componentname then
call selectobject(subfeaturename & "@" & assemblyname, "component", 0, 0, 0, true, 0, nothing, 0)
end if
'get the next subfeature
set swsubfeature = swsubfeature.getnextsubfeature
loop
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
thanks jorn
i finally got what i wanted by traversing the feature tree and adding the pattern names to a collection. i then created a collection for each pattern in the first collection. i then traversed the feature tree a second time and when i found a reference that belonged to a pattern i would check the parent name and add that reference to the collection for that pattern. finally when i found the patterns at the end of the tree i would print out the proper collection. a rather long and to complicated for a simple task. your information will simplify my process.
thanks again
dan miel
sw 2008
dan,
happy i could help.
cheers!
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
hi jorn,
could you post all your code? it seems to resolved one of my issue but i'm not really got in vb so i don't really know how to get it works.
thanks,
steph
originally posted by: stephane demers
hi jorn,
could you post all your code? it seems to resolved one of my issue but i'm not really got in vb so i don't really know how to get it works.
stephane,
it's a small part of a large project which i cannot post here. what exactly are you struggeling with?
cheers,
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
that's ok i resolved my issue. but i got a new problem... i'm in a drawing of a part (1 level only) how can i get the custom properties for this part ??? do you know ?
steph
originally posted by: stephane demers
that's ok i resolved my issue. but i got a new problem... i'm in a drawing of a part (1 level only) how can i get the custom properties for this part ??? do you know ?
stephane,
i see you have raised the same question in another thread (
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
edited: 05/06/2008 at 10:21 am by jorn bjarning
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-24 20:18 , Processed in 0.038271 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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