几何尺寸与公差论坛

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

【转帖】addmate3 depends on selection method

[复制链接]
发表于 2009-4-12 23:00:53 | 显示全部楼层 |阅读模式
addmate3 depends on selection method?
hi,
i'm working on a macro that will attach the mates referred to by two matereferences.
i've found that once i have the two entity objects to mate together, let's call them swentity1 and swentity2, i can select them with swmodel.extension.selectbyid2 and create the mate using swassy.addmate3. i can also select the first entity with swentity1.select4 (using an appropriate selectdata object that specifies mark=1), and second with selectbyid2, and it works.
what doesn't work is selecting both entities using select4. in this case, addmate3 reports success and i get a non-null mate2 object, but no mate is shown in the solidworks interface (nothing in the feature tree, component can still be manually moved).
i'd really rather not have to use selectbyid2 in this case, since it requires me to build a long selection string with information i don't necessarily have available. any hints as to why selecting using select4 on the entity objects that i already have isn't working?
to summarize, this works:
swmodel.clearselection2 (true)
dim selectresult as boolean
' select the first entity
dim selectdata as sldworks.selectdata
set selectdata = swmodel.selectionmanager.createselectdata
selectdata.mark = 1
selectresult = swentity1.select4(false, selectdata): debug.assert(selectresult)
' select the second entity, using selectbyid2
dim swfeat2 as sldworks.feature
set swfeat2 = swentity2
selectresult = swmodel.extension.selectbyid2(swfeat2.name & "@test component 2" & "@sample assy for mr macro", "plane", 0#, 0#, 0#, true, 1, nothing, swselectoptiondefault): debug.assert (selectresult)
' create the mate
dim firstmate as sldworks.mate2
dim errorstatus as long
set firstmate = swassy.addmate3(swmatecoincident, swalignnone, false, 0, 0, 0, 0, 0, 0, 0, 0, false, errorstatus)
... and this doesn't work:
swmodel.clearselection2 (true)
dim selectresult as boolean
' select the first entity
dim selectdata as sldworks.selectdata
set selectdata = swmodel.selectionmanager.createselectdata
selectdata.mark = 1
selectresult = swentity1.select4(false, selectdata): debug.assert(selectresult)
' select the second entity, using select4
selectresult = swentity2.select4(true, selectdata): debug.assert(selectresult)
' create the mate
dim firstmate as sldworks.mate2
dim errorstatus as long
set firstmate = swassy.addmate3(swmatecoincident, swalignnone, false, 0, 0, 0, 0, 0, 0, 0, 0, false, errorstatus)
btw i am aware that the api docs specifically mention doing the selection with selectbyid2. but then why does my first method work?
thanks
- rdo
you can try selecting your first entity then use
bret = entity.select(1)
'select your second entity
bret = entity.select(2)
'then use add mate
i hope this helps
dan miel
same result with that, unfortunately. thanks though
- rdo
its probably that it needs more than just those 2 entities selecting; often the selectbyid2 selects more than just the entity. it may also be that he selections require marks adding to them.
the quickest solution is ask api help they will tell you what thte function requires regarding selection.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 22:40 , Processed in 0.037740 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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