Split a 3D Curve

Split a 3D Curve

florian_wenzel
Advocate Advocate
1,084 Views
9 Replies
Message 1 of 10

Split a 3D Curve

florian_wenzel
Advocate
Advocate

Hi,

i try to Split a 3D Curve.

I took a similar Scrip for Split2D Curve, which works for 2D curves, but my Goal is to Split a 3D Curve.

 

I use the  SDKInventorAddIn in Visual Studio

 

Public Sub SampleCommandFunction()
Dim partDoc As PartDocument
partDoc = g_inventorApplication.ActiveDocument

Dim spline As Object
spline = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveFilter, "Select 3d spline")

' Get the spline geometry from the entity.
Dim splineCurve As BSplineCurve
splineCurve = spline.Geometry

' Determine the parameter value for geometric midpoint of the curve.
Dim curveEval As CurveEvaluator
curveEval = splineCurve.Evaluator
Dim startParam As Double
Dim endParam As Double
Call curveEval.GetParamExtents(startParam, endParam)
Dim midParam As Double
Call curveEval.GetParamAtLength(startParam, spline.Length / 2, midParam)

' Split the curve.
Dim curve1 As BSplineCurve
Dim curve2 As BSplineCurve
Call splineCurve.Split(midParam, curve1, curve2)

' Create new sketch curves using the extracted splines.
Dim splineSketch As Sketch3D
splineSketch = spline.Parent
Call splineSketch.SketchFixedSplines.Add(curve1)
Call splineSketch.SketchFixedSplines.Add(curve2)

' Delete the original curve.
spline.Delete
End Sub

 

I can select a Curve, but without any Result.

Actually my Goal is to Split the Curve with equal Length and also choose the quantity, but first only in Middle

 

Any Suggestion.

Thanks

florianwenzelEJNZZ_0-1643153621309.png

 

 

0 Likes
Accepted solutions (3)
1,085 Views
9 Replies
Replies (9)
Message 2 of 10

nedeljko.sovljanski
Advocate
Advocate
Accepted solution

If you run your code as addin then there should be try catch block around execute method. That means your you will not crash inventor but your addin will stop work. I put your code in macro and this lines throwing exceptions

Call splineSketch.SketchFixedSplines.Add(curve1)
Call splineSketch.SketchFixedSplines.Add(curve2)

nedeljkosovljanski_0-1643196358182.png

 

0 Likes
Message 3 of 10

nedeljko.sovljanski
Advocate
Advocate

As I can see in documentation

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-C30FAF86-6494-4170-AFD7-0D98E686159D

there is no SketchFixedSplines property in Sketch3D object. There is SketchFixedSplines3D but that is only returns values.

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-EE6B2929-6F1A-4E34-A742-D34618B74C67

Message 4 of 10

florian_wenzel
Advocate
Advocate

Thanks, you right.

I try with SketchFixedSplines3D

 

0 Likes
Message 5 of 10

nedeljko.sovljanski
Advocate
Advocate
Accepted solution

Only Include() method can add new Sketch3D but inout parameter is 

Input object to copy into the sketch. In a part context, valid input includes Edges, 3d sketch entities and planar sketch entities

You are trying to add BSplineCurve.

For this problem (how to convert) only @adam.nagy can help you.

0 Likes
Message 6 of 10

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

Not sure what Inventor version you are using but in 2022 SketchFixedSplines3D.Add() seems to work fine:

Sub SplitSpline()
  Dim sp As SketchControlPointSpline3D
  Set sp = ThisApplication.ActiveDocument.SelectSet(1)
  
  Dim sk As Sketch3D
  Set sk = sp.Parent
  
  Dim bs As BSplineCurve
  Set bs = sp.Geometry
  
  Dim minp As Double
  Dim maxp As Double
  Call bs.Evaluator.GetParamExtents(minp, maxp)
  
  Dim midp As Double
  Call bs.Evaluator.GetParamAtLength(minp, sp.Length / 2, midp)
  
  Dim c1 As BSplineCurve
  Dim c2 As BSplineCurve
  Call bs.Split(midp, c1, c2)
  
  Call sk.SketchFixedSplines3D.Add(c1)
  Call sk.SketchFixedSplines3D.Add(c2)
  
  Call sp.Delete
End Sub

adamnagy_1-1643200939773.png

 



Adam Nagy
Autodesk Platform Services
Message 7 of 10

florian_wenzel
Advocate
Advocate

Ok, it works!

 

florianwenzelEJNZZ_0-1643202820796.pngflorianwenzelEJNZZ_1-1643202872606.png

 

florianwenzelEJNZZ_2-1643202924866.png

 

0 Likes
Message 8 of 10

florian_wenzel
Advocate
Advocate

Looks good, 

the only small problem is , that all Curves are still there.

But this is not a big problem, you can choose the Curves what you need.

Then you can make a Works Surface at End of Curve.

Great!

0 Likes
Message 9 of 10

florian_wenzel
Advocate
Advocate

florianwenzelEJNZZ_3-1643203111370.png

Public Sub SampleCommandFunction()
Dim partDoc As PartDocument
partDoc = g_inventorApplication.ActiveDocument

Dim spline As Object
spline = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveFilter, "Select 3d spline")

' Get the spline geometry from the entity.
Dim splineCurve As BSplineCurve
splineCurve = spline.Geometry

' Determine the parameter value for geometric midpoint of the curve.
Dim curveEval As CurveEvaluator
curveEval = splineCurve.Evaluator
Dim startParam As Double
Dim endParam As Double
Call curveEval.GetParamExtents(startParam, endParam)
Dim midParam As Double
Call curveEval.GetParamAtLength(startParam, spline.Length / 2, midParam)

' Split the curve.
Dim curve1 As BSplineCurve
Dim curve2 As BSplineCurve
Call splineCurve.Split(midParam, curve1, curve2)

' Create new sketch curves using the extracted splines.
Dim splineSketch As Sketch3D
splineSketch = spline.Parent
Call splineSketch.SketchFixedSplines3D.Add(curve1)
Call splineSketch.SketchFixedSplines3D.Add(curve2)

' Delete the original curve.
spline.Delete
End Sub

Message 10 of 10

florian_wenzel
Advocate
Advocate
Hi,
im using Inventor 2022 and Visual Studio with SDK. Then i modify the VBA to VB.NET - it works 🙂
i didint refresh the Site before, so i even dont saw you Answers, sorry for this.
It was the moment which i was trying the Function.
Thanks very much!
0 Likes