What are the keywords for creating a spline with tangent driving?

Hi all

I'm a beginner on SW, and I'm interested in creating macros for trajectory construction.

I try to reproduce as faithfully as possible the trajectory of an industrial knitting yarn.  The trajectory passes through 4 points and lines and splines are used for its construction.

Thanks to macro recording, I was able to retrieve the script necessary to create points, build lines as well as splines.

However, I need to have control over the tangents of the start and end points (which are calculated). Unfortunately, when I use macro recording and build the spline with tangent driving, I don't see any new "function" appear.

Is it possible to recover this function?

 

Here is the save script that I got after manual construction (there are probably some unnecessary lines left):

Partial Class SolidWorksMacro

Public Sub main()
Dim swDoc As ModelDoc2 = Nothing
Dim swPart As PartDoc = Nothing
Dim swDrawing As DrawingDoc = Nothing
Dim swAssembly As AssemblyDoc = Nothing
Dim boolstatus As Boolean = false
Dim longstatus as integer = 0
Dim longwarnings as integer = 0
swDoc = CType(swApp.ActiveDoc,ModelDoc2)
swDoc.SketchManager.Insert3DSketch(true)
'
Dim skSegment As SketchSegment = Nothing
skSegment = CType(swDoc.SketchManager.CreateLine(0.000000, 0.000000, 0.000000, -0.002000, 0.004000, -0.000500),SketchSegment)
swDoc.SetPickMode()
swDoc.ClearSelection2(true)
'
Dim pointArray As Array = Nothing
Dim points(8) Ace Double
points(0) = -0.002
points(1) = 0.004
points(2) = -0.0005
points(3) = 0.004
points(4) = 0.008
points(5) = -0.0015
points(6) = 0.016
points(7) = 0.009
points(8) = -0.002
pointArray = points
skSegment = CType(swDoc.SketchManager.CreateSpline(pointArray),SketchSegment)
boolstatus = swDoc.Extension.SelectByID2("Spline1", "SKETCHSEGMENT", 0.0, 0.0, 0, False, 0, Nothing, 0)
swDoc.ShowNamedView2("*Left", 3)
swDoc.ClearSelection2(true)
swDoc.EditUndo2(1)
boolstatus = swDoc.Extension.SelectByID2("Spline1", "SKETCHSEGMENT", 0.0070000000000000000062, 0.0060299676105561159, -0.0010150801486359592, false, 0, Nothing, 0)
swDoc.ShowNamedView2("*Face", 1)
swDoc.ShowNamedView2("*Left", 3)
swDoc.ClearSelection2(true)
swDoc.EditUndo2(1)
boolstatus = swDoc.Extension.SelectByID2("Spline1", "SKETCHSEGMENT", 0.006999999999999999984, 0.0049025748626198599, -0.00080798849755920818, false, 0, Nothing, 0)
swDoc.ShowNamedView2("*Face", 1)
swDoc.ClearSelection2(true)
swDoc.SketchManager.Insert3DSketch(true)
End Sub

''' <summary>
''' The SldWorks swApp variable is pre-assigned for you.
''' </summary>
Public swApp As SldWorks


End Class

Thanks again

 

Hello

This is the AddCurvatureControl method , here is the help page:

http://help.solidworks.com/2016/English/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.ISketchSpline~AddCurvatureControl.html

See this example from SolidWorks:

http://help.solidworks.com/2015/English/api/sldworksapi/Set_Spline_Tangency_and_Curvature_Controls_Example_VB.htm
 

@ .PL,

 

thanks for the information, but I didn't manage to use AddTangencyControl.

I don't have enough control at the moment.

However, I found something intermediate by imposing tangency relations between line/spline (I had to create an extra point and a line in the plane that goes well to impose the tagente at the end point):

boolstatus = swDoc.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 0.001252185401910166,         0.0021753914154531259, 0.00035, False, 0, Nothing, 0)
boolstatus = swDoc.Extension.SelectByID2("Spline1", "SKETCHSEGMENT", 0.0012466358052038895, 0.0021750333769559468, 0.00035, True, 0, Nothing, 1)
swDoc.SketchAddConstraints("sgTANGENT")

 

A little additional question:

when selecting an entity (point, line, etc.) with SelectByID2, do the numeric values correspond to something specific (coordinates?, others?).


vues.jpg

  "Edit":

I was able to add the AddTangencyControl command. Below is my example.

On the other hand, it seems that it only gives the means to control the tangent manually on the GUI once the macro is executed. In addition, the control is only applied for the last point of the spline and no matter what coordinates are entered, it has no influence.

Have I forgotten something?

I found another example (not yet tested) in "Get and Set Spline Handles Example (VBA)"  here:

help.solidworks.com/2016/English/api/sldworksapi/Get_and_Set_Spline_Handles_Example_VB.htm

Since I want to impose my tangents at certain points (start and finish) shouldn't I use instead:

swSpline. GetSplineHandles()

TangentMagnitude

TangentRadialDirection

 

??

  Public Sub main()

        Dim swDoc As ModelDoc2 = Nothing
        Dim swPart As PartDoc = Nothing
        Dim swDrawing As DrawingDoc = Nothing
        Dim swAssembly As AssemblyDoc = Nothing
        Dim boolstatus As Boolean = False
        Dim longstatus as integer = 0
        Dim longwarnings as integer = 0


        Dim swSpline As SketchSpline = Nothing
        Dim swSplineH1 As SplineHandle = Nothing

        swDoc = CType(swApp.ActiveDoc, ModelDoc2)
        swDoc.SketchManager.Insert3DSketch(True)
        Dim skSegment As SketchSegment = Nothing
        skSegment = CType(swDoc.SketchManager.CreateLine(0.0, 0.0, 0.0, -0.0002, 0.00087, 0.000175), SketchSegment)
        swDoc.SketchAddConstraints("sgFIXED")

        swDoc.ClearSelection2(true)
        '
        Dim pointArray As Array = Nothing
        Dim points(8) Ace Double
        points(0) = -0.0002
        points(1) = 0.00087
        points(2) = 0.000175
        points(3) = 0.0002
        points(4) = 0.00203
        points(5) = 0.000525
        points(6) = 0.00125
        points(7) = 0.002175
        points(8) = 0.0007
        pointArray = points
        skSegment = CType(swDoc.SketchManager.CreateSpline(pointArray), SketchSegment)
        swDoc.ClearSelection2(True)
 

        boolstatus = swDoc.Extension.SelectByID2("Spline1", "SKETCHSEGMENT", 0.0, 0.0, 0.0, False, 0, Nothing, 0)

        swSpline = swDoc.SelectionManager.GetSelectedObject6(1, 0)
        swSplineH1 = swSpline.AddTangencyControl(-0.0002, 0.00087, 0.000175)


        swDoc.SketchManager.Insert3DSketch(True)
        swDoc.ClearSelection2(True)
       
    End Sub