AnsweredAssumed Answered

Trim toroidal surface

Question asked by Alexandre Gragnano on Nov 29, 2016
Latest reply on Nov 29, 2016 by Alexandre Gragnano

Hi,

 

I would like to create a piece of torus by trimming a toroidal surface created with:

2017 SOLIDWORKS API Help - CreateToroidalSurface Method (IModeler)

 

My code:

'--------------------------------------------------------------------------
' Preconditions:
' 1. Create a new empty part.
' 2. Place a breakpoint at End Sub statement.
'
' Postconditions:
' 1. Creates a new torus body.
' 2. Visualize the temporary body in red.
'-----------------------------------------------------------------------

Option Explicit

Sub main()
    
    Dim swApp As SldWorks.SldWorks
    Set swApp = Application.SldWorks
    
    Dim swDoc As SldWorks.ModelDoc2
    Set swDoc = swApp.ActiveDoc
    
    Dim swModeler As SldWorks.Modeler
    Set swModeler = swApp.GetModeler
    
    Dim torusCenter(0 To 2) As Double
    torusCenter(0) = 0#
    torusCenter(1) = 0#
    torusCenter(2) = 0#
    
    Dim torusAxis(0 To 2) As Double
    torusAxis(0) = 0#
    torusAxis(1) = 1#
    torusAxis(2) = 0#
    
    Dim torusRefDir(0 To 2) As Double
    torusRefDir(0) = 1#
    torusRefDir(1) = 0#
    torusRefDir(2) = 0#
    
    Dim torusMajorRadius As Double
    torusMajorRadius = 0.1
    
    Dim torusMinorRadius As Double
    torusMinorRadius = 0.01
    
    Dim swTorusSurface As SldWorks.Surface
    Set swTorusSurface = swModeler.CreateToroidalSurface( _
        torusCenter, _
        torusAxis, _
        torusRefDir, _
        torusMajorRadius, _
        torusMinorRadius)
    
    Dim swParams As SldWorks.SurfaceParameterizationData
    Set swParams = swTorusSurface.Parameterization2
    
    Debug.Print "UMin: " & swParams.UMin
    Debug.Print "UMax: " & swParams.UMax
    Debug.Print "VMin: " & swParams.VMin
    Debug.Print "VMax: " & swParams.VMax
    
    Dim swCurveStart As SldWorks.Curve
    Set swCurveStart = swTorusSurface.MakeIsoCurve2(False, swParams.UMin)
    
    Dim swCurveEnd As SldWorks.Curve
    Set swCurveEnd = swTorusSurface.MakeIsoCurve2(False, swParams.UMax / 2)
    
    Dim swCurves(0 To 1) As SldWorks.Curve
    Set swCurves(0) = swCurveStart
    Set swCurves(1) = swCurveEnd
    
    Dim swBody As SldWorks.Body2
    Set swBody = swTorusSurface.CreateTrimmedSheet4(swCurves, True)
    
    swBody.Display3 swDoc, RGB(255, 0, 0), 0
    swDoc.ViewZoomtofit2
    
End Sub

 

The returned body is Nothing.

I suppose my trimming curves have to be trimmed too.

I tried CreateTrimmedCurve2 method but has no effect.

Some help will be welcome.

 

Best regards.

Outcomes