Hi,
Im new to APIs. Im struggling with a concept, because i cant get the type of arrays and selected items right. My idea is basicly: save the selected lines and points coordinates in oder into an array, then read it in a loop, so i can insert a spline to the coordinates and make it tangent with the lines. I know very few codes in API but im familiar with other languages. I can come up with a pseudo code, but i have no idea what am i doing:).
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Sub main()
Set SelMgr = swModel.SelectionManager
Dim numsel As Long
If (SelMgr.GetSelectedObjectCount = 0) Then
swApp.SendMsgToUser ("Select points.")
Else
Dim Points() As Double
Dim Lines() As Double
Dim j As Integer
'there could be an if to check if the selected items are points
ReDim Points(numsel)
For j = 0 To numsel
'this is probably wrong, i dont get it how can i get the coordinates of selected object
Set Points(j) = SelMgr.GetSelectedObjectsComponent6(j, -1)
Next j
'there could be an if to check if the selected items are lines
For j = 0 To numsel
Set Lines(j) = SelMgr.GetSelectedObjectsComponent6(j, -1)
Next j
For j=0 to numsel
Dim pointArray As Variant
Dim skSegment As Object
'i just copied a recorded macro, i can probably paste the variables from the array in this, but any help i accept
Set pointArray = Points(j), Points(j+1)
Set skSegment = Part.SketchManager.CreateSpline((pointArray))
boolstatus = Part.Extension.SelectByID2("Spline1", "SKETCHSEGMENT", 0, 1.81015384357535E-02, 2.09337519325041E-02, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 0, 4.71625117067592E-02, 1.10825745525022E-02, True, 0, Nothing, 1)
Part.SketchAddConstraints "sgTANGENT"
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Spline1", "SKETCHSEGMENT", 0, -3.97741286717577E-02, 7.28987126120142E-02, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line2", "SKETCHSEGMENT", 0, -4.44534379272586E-02, 0.10146712701402, True, 0, Nothing, 1)
Part.SketchAddConstraints "sgTANGENT"
' it has to jump to every second j, but i dont know neither how to do it
j++
Next j
Debug.Print numsel
End If
End Sub
I would be happy for any scratch of information, and again to be clear, im lack of the basic knowledge of macros, i can only barely understand other people's macros, so i work from those with copy/paste, i only understand the basic programming stuff like loops and codestructure. thx for any help