Hello
for a project I have to make a SolidWorks macro in order to automate a certain task. So far I have managed to create the parts automatically, and to assemble them in an assembly.
Nevertheless, I am now faced with a problem: I have to link the parts together with constraints. So I try to do it automatically. Here's the code:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
' Mate
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Removed mat.-Extru.1@disque1-1@Assemblage1", "BODYFEATURE", 0, 0, 0, False, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Boss.-Extru.6@Pièce1-1@Assemblage1", "BODYFEATURE", 0, 0, 0, True, 1, Nothing, 0)
Dim swMate As Mate2
Set swMate = Part.AddMate5(1, 0, False, 3.90150366882658E-02, 0.001, 0.001, 0.001, 0.001, 0, 0.5235987755983, 0.5235987755983, False, False, 0, longstatus)
Part.ClearSelection2 True
Part.EditRebuild3
End Sub
(on two pieces.)
The problem is as follows:
When I try to do the constraint manually (so by removing the associated line in the code above), I have two choices depending on the markers that it puts in my code (the arguments of the SelectID2 methods)
- -If I use marker 0, the parts are not actually selected in the constraints menu (screenshot 1)
- - If I use marker 1, I only have one constraint choice!
So I think there must be a parameter of my methods that is not the right one, but despite long searches I haven't found it. So I come to ask you the question: how can this constraint be achieved automatically?
Thank you in advance for the help you can give me.
captures_ecran.rar