AnsweredAssumed Answered

CreateTrimmedCurve2 Not Working Correctly?

Question asked by Brian Smith on Feb 15, 2018
Latest reply on Feb 22, 2018 by Jacob Corder

I feel like I may be doing something terrible wrong, but I can't quite figure out what is wrong with this function. CreateTrimmedCurve2 does not seem to act predictably. Below are 4 examples that all I am doing is altering the start and direct of the beginning curve and the start and end points of the createtrimmedcurve2 function.

 

Option 1: The below code runs fine, and displays a temporary line.

 

Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim swModeler As SldWorks.Modeler

    Dim swCurve As SldWorks.Curve

    Dim trimmed_curve As SldWorks.Curve

    Dim nPt(2) As Double

    Dim nPte(2) As Double

    Dim vPt As Variant

    Dim vDir As Variant

    Dim retval As Long

    Dim swPart As SldWorks.PartDoc

   

    Set swApp = Application.SldWorks

    Set swModeler = swApp.GetModeler

    Set swPart = swApp.ActiveDoc

    nPt(0) = 0

    nPt(1) = 0

    nPt(2) = 0

    vPt = nPt

    nPte(0) = 0

    nPte(1) = 0

    nPte(2) = 1

    vDir = nPte

    Set swCurve = swModeler.CreateLine(vPt, vDir)

    Set trimmed_curve = swCurve.CreateTrimmedCurve2(0, 0, 0, 0, 0, 1)

    Set swBody = trimmed_curve.CreateWireBody()

    retval = swBody.Display3(swPart, 255, swTempBodySelectable)

    Stop

End Sub

 

 

Option 2: The below code runs fine, and displays a temporary line.

 

Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim swModeler As SldWorks.Modeler

    Dim swCurve As SldWorks.Curve

    Dim trimmed_curve As SldWorks.Curve

    Dim nPt(2) As Double

    Dim nPte(2) As Double

    Dim vPt As Variant

    Dim vDir As Variant

    Dim retval As Long

    Dim swPart As SldWorks.PartDoc

   

    Set swApp = Application.SldWorks

    Set swModeler = swApp.GetModeler

    Set swPart = swApp.ActiveDoc

    nPt(0) = -2

    nPt(1) = -2

    nPt(2) = -2

    vPt = nPt

    nPte(0) = 2

    nPte(1) = 2

    nPte(2) = 2

    vDir = nPte

    Set swCurve = swModeler.CreateLine(vPt, vDir)

    Set trimmed_curve = swCurve.CreateTrimmedCurve2(-1, -1, -1, 1, 1, 1)

    Set swBody = trimmed_curve.CreateWireBody()

    retval = swBody.Display3(swPart, 255, swTempBodySelectable)

    Stop

End Sub

 

 

Option 3: The below errors out at the bold line because I believe it is not creating the trimmed_curve object.

 

Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim swModeler As SldWorks.Modeler

    Dim swCurve As SldWorks.Curve

    Dim trimmed_curve As SldWorks.Curve

    Dim nPt(2) As Double

    Dim nPte(2) As Double

    Dim vPt As Variant

    Dim vDir As Variant

    Dim retval As Long

    Dim swPart As SldWorks.PartDoc

   

    Set swApp = Application.SldWorks

    Set swModeler = swApp.GetModeler

    Set swPart = swApp.ActiveDoc

    nPt(0) = -2

    nPt(1) = 0

    nPt(2) = 0

    vPt = nPt

    nPte(0) = 2

    nPte(1) = 0

    nPte(2) = 1

    vDir = nPte

    Set swCurve = swModeler.CreateLine(vPt, vDir)

    Set trimmed_curve = swCurve.CreateTrimmedCurve2(-1, 0, 0, 1, 0, 1)

   Set swBody = trimmed_curve.CreateWireBody()

    retval = swBody.Display3(swPart, 255, swTempBodySelectable)

    Stop

End Sub

 

Option 4: Similarly, the below errors out at the bold line because I believe it is not creating the trimmed_curve object.

 

Sub main()

    Dim swApp As SldWorks.SldWorks

    Dim swModeler As SldWorks.Modeler

    Dim swCurve As SldWorks.Curve

    Dim trimmed_curve As SldWorks.Curve

    Dim nPt(2) As Double

    Dim nPte(2) As Double

    Dim vPt As Variant

    Dim vDir As Variant

    Dim retval As Long

    Dim swPart As SldWorks.PartDoc

   

    Set swApp = Application.SldWorks

    Set swModeler = swApp.GetModeler

    Set swPart = swApp.ActiveDoc

    nPt(0) = 2

    nPt(1) = 0

    nPt(2) = 0

    vPt = nPt

    nPte(0) = 2

    nPte(1) = 0

    nPte(2) = 1

    vDir = nPte

    Set swCurve = swModeler.CreateLine(vPt, vDir)

    Set trimmed_curve = swCurve.CreateTrimmedCurve2(2, 0, 0, 2, 0, 1)

   Set swBody = trimmed_curve.CreateWireBody()

    retval = swBody.Display3(swPart, 255, swTempBodySelectable)

    Stop

End Sub

 

I've tried every combination that I can think of, but it doesn't seem to be doing anything. what I really want is a temporary line that is:

 

K is some constant.

Start (x, y, & z) End (x, y, & z+k)

 

I have tried a trim that is effectively start (x-k, y-k,z-k) end (x+k, y+k, z+k), and that also errors out, when x, y, z are not all equal.

 

I feel like I have ready everything on the forums in regards to the trimmed_curve and in the API, and I feel like I should at least be able to the third option. Thoughts? Any help is appreciated.

Outcomes