几何尺寸与公差论坛

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

【转帖】examinig part component mates

[复制链接]
发表于 2009-4-12 20:51:38 | 显示全部楼层 |阅读模式
examinig part component mates ?
hi there,
i have a part that is mated with a line in a 3d-sketch. the 3d-sketch is in an assembly. the user selects the part on the screen and my addin recieves the icomponent2 interface of the part.
how do i get the isketchline-interface of the mated line?
my idea was to examine the mates of the part by examining the feature tree of the part. unfortunately the functions that returns the feature tree of the component returns everything except the mategroup of the part.
i use the same functions that were descibed in the solidworks api help "traversing assembly at component and feature levels example"
thanks in advance,
matthias senff
although the feature tree of an assembly appears to show the mates of a part inside a folder under the part, i'm pretty sure they really aren't there. i think you'll have to traverse the mates of the assembly and check their components to see if one of the components is the one you are interested in.
i'll get you eh steve, if it's the last thing i dooooo!
unfortunately our solution will work with a lot of parts, assemblys and sub assemblys. if we traverse all features of all assemblys and sub assemblys it will lead to performance problems.
when you traverse the assembly your program does not follow the manager tree so i think it would be hard to find the mates for each part. to follow the tree the way it shows in your window, check out the "traverse featuremanager design tree" example and "treecontrolitem." this goes down the tree in the same order that the tree is in. it uses nodes like the tree view in vb. depending on how you have your sw tree options set ( see below), when you find a part or an assembly in the tree, then the next "childnode" will either be the mates for that part or the folder that your mates are in. you can then get each mates using childnode.getnext and examine each mate. a couple commands you will learn if you don't know them already will be feat.getspecificfeature2, mate.mateentity and mateent.reference.
to set your tree options, right click on the top feature in you tree, which is the name of your part, choose "tree display" and then either "view features" or "view mates and dependencies" this will change whether the next item below the part in the tree is a folder or a mate.
i hope this isn't to long of a note.
hope this helps.
dan miel
edited: 01/28/2009 at 03:43 pm by dan miel
you can begin examine your selected part and go upperwards. it is not necessary traverse all components.
option explicit
sub main()
dim swmodel as sldworks.modeldoc2
dim swapp as sldworks.sldworks
dim swfeat as sldworks.feature
dim swmatefeat as sldworks.feature
dim swsubfeat as sldworks.feature
dim swmate as sldworks.mate2
dim swselmgr as sldworks.selectionmgr
dim comp as sldworks.component2
dim model1 as sldworks.modeldoc2
set swapp = application.sldworks
if swapp is nothing then
err.raise 1234, , "solidworks is gone."
end if
set swmodel = swapp.activedoc
set swselmgr = swmodel.selectionmanager
set comp = swselmgr.getselectedobjectscomponent(1)
if comp is nothing then
set model1 = swmodel
else
set model1 = comp.getmodeldoc
end if
set swfeat = model1.firstfeature
back:
' iterate over features in featuremanager design tree
do while not swfeat is nothing
if ucase("mategroup") = ucase(swfeat.gettypename) then
set swmatefeat = swfeat
exit do
end if
set swfeat = swfeat.getnextfeature
loop
if not swmatefeat is nothing then ' get first mate, which is a subfeature
set swsubfeat = swmatefeat.getfirstsubfeature
do while not swsubfeat is nothing
set swmate = swsubfeat.getspecificfeature2
if not swmate is nothing then
debug.print swmate.mateentity(0).referencecomponent.name2
debug.print swmate.mateentity(1).referencecomponent.name2
end if
' get the next mate in mategroup
set swsubfeat = swsubfeat.getnextsubfeature
loop
else
if not comp is nothing then
set comp = comp.getparent
if comp is nothing then
set model1 = swmodel
else
set model1 = comp.getmodeldoc
end if
set swfeat = model1.firstfeature
if not swfeat is nothing then goto back
end if
end if
end sub
i thought there is an easier way. examining only the parents will not help, because the 3d-sketch may be in a subassembly of a parent. i think i will check out traversing the featuremanager design tree.
thanks for the answers.
matthias senff
but mate is allways in parent.
set comp = swmate.mateentity(0).referencecomponent you can find component set ent = swmateent(0).reference you have entity using for mate.
thanks again,
i was unaware that solidworks assigns the mates automatically to the correct assembly if you change the underlying structures so that you can always reach them by the parents.
if you replace a part in an assembly and the new part does not have the same surface as the old part, or if a component is suppressed the mateentity will not return the referencecomponent. so if you select a mate and it has an invalid component, when you check for the referencecomponent, it will not return a name because the link is broken.
when you traverse the featuremanager design tree and check the mates below each part and assembly, you know which mates belong to that part. you can then check each mate for broken references.
what i'm saying is that as long as you know that your mates are good and not invalid you can find the components for the mate like ivana is doing, but if a referencecomponent is suppressed then i don't think mateentity will find it.
dan miel
matthias
this macro should go down the tree and find each component and then the mates for that component. it retrieves the information whether the components are in folders or not. i wrote this macro so it finds all parts of all sub assemblies. if you want it to find the top level only, comment out the line indicated. this prints out the component name the mates to that component and any folder that the components are in.
if you are looking for mates for a particular part you just need to insert a check that looks for the component name that you want to check.
dan miel
sw 2008
edited: 02/01/2009 at 04:47 pm by dan miel
answer thanks dan,
i try to combine your and ivanas code to find an efficient solution.
matthias senff
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 10:58 , Processed in 0.037464 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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