Hello all,
I have a serious problem with work in edited document via API.
Lets imagine following situation: There is similar structure opened in SolidWorks:
Main.sldasm
- SubMain.sldasm<1>
- Part1.sldasm<1>
- Part2.sldasm<2>
Now imagine that SubMain.sldasm is actually edited.
I found that in this case I have two significant documents: Main.sldasm and its "EditTarget" SubMain.sldasm.
Next I found that API function like AssemblyDoc.AddComponent4 must be called on Main.sldasm (top level document) although the component is inserted to SubMain.sldasm.Same is with the functions operating with the selected objects (like AddMate3) - selection must be done in the top assembly (Main.sldasm) by "SelectByID" method. For that it is necessary to create special identification string used in SelectByID method (e.g.
I found the way how build the string but I think that it is unhappy way ( I would like to work with the "Select" method of the SW objects in this case - it is faster)
So my question is: Is any possibility how to call methods like AddComponent, AddMate etc. for the edited document directly? If not, is any possibility how can work methods called for top document with the objects from edited document which were selected by object.Select method?
Here is example of code which works (note: swDoc is the top level (active) document):
boolstatus = swDoc.Extension.SelectByID2(OUTPUT_AXIS_1_ET1@SubASM-1@MainASM/Flanged_flange-1@SubASM", "AXIS", 0, 0, 0, false, 0, null, 0)
boolstatus = swDoc.Extension.SelectByID2(Line1@Piping_1@SubASM-1@MainASM", "EXTSKETCHSEGMENT", -0.1097967997165, 0.03821723076923, 0, true, 0, null, 0)
boolstatus = swDoc.Extension.SelectByID2(Line1@Piping_1@SubASM-1@MainASM", "EXTSKETCHSEGMENT", -0.1097967997165, 0.03821723076923, 0, true, 0, null, 0)
(swDoc as nsw.AssemblyDoc).AddMate3((int)nconst.swMateType_e.swMateCOINCIDENT, (int)nconst.swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, out err);
Here is example of code that doesn't work (note: swDoc is the top level (active) document):
swAxis.Select2(false, 0)
swSegment.Select4(true,0)
(swDoc as nsw.AssemblyDoc).AddMate3((int)nconst.swMateType_e.swMateCOINCIDENT, (int)nconst.swMateAlign_e.swMateAlignALIGNED, false, 0, 0, 0, 0, 0, 0, 0, 0, false, out err);
SolidworksApi macros