几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-12, 08:51 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】examinig part component mates

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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】creating a reference poin on a surface yang686526 SolidWorks二次开发 0 2009-04-12 08:36 PM
【转帖】draw shaft using visual basic application yang686526 SolidWorks二次开发 0 2009-04-12 06:01 PM


所有的时间均为北京时间。 现在的时间是 06:07 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多