![]() |
【转帖】addmate3 depends on selection method
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. |
所有的时间均为北京时间。 现在的时间是 10:33 PM. |