Merge SketchSpline3D

Merge SketchSpline3D

florian_wenzel
Advocate Advocate
323 Views
3 Replies
Message 1 of 4

Merge SketchSpline3D

florian_wenzel
Advocate
Advocate

Hi,

Inventor 2022

API VisualStudio VB.NET

 

i try to Merge some 3d Curves.

Exactly, i want  to create New Spline using few other splines.

In this example the WorkFlow look like this:

I pick a Edge from a Body

Then i get all Tangent Connectet Edges

Create Sketch3D and include all Edges in this Sketch

 

Then my Idea is, to get all SketchPoints3D, and All FitPoints from each SketchSplines3D 

But i get Error with FitPoints.

 

This is my Code:

 

 

       
  Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

 Dim oEdge As Edge = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, " Pick a Edge")

        Dim oEdgeColl As EdgeCollection = oEdge.TangentiallyConnectedEdges

        MsgBox("oEdgeColl " & oEdgeColl.Count)

        Dim oSketch3D As Sketch3D = oCompDef.Sketches3D.Add

        Dim oEntity As SketchEntity3D
        For i = 1 To oEdgeColl.Count
            Dim oEdge_i As Edge = oEdgeColl.Item(i)
            oEntity = oSketch3D.Include(oEdge_i)
            oEntity.Reference = False
        Next

        Dim oSketchSpline3D As SketchSpline3D
        Dim oSketchPoint3D As SketchPoint3D
        Dim oObjColl As ObjectCollection = oTO.CreateObjectCollection

        Dim oCtrlDef As ButtonDefinition
        oCtrlDef = g_inventorApplication.CommandManager.ControlDefinitions.Item("Sketch3DDeleteConstraintsCtxCmd")
        Dim oSelectSet As SelectSet
        oSelectSet = oPartDoc.SelectSet
        oCtrlDef.Execute()


        For j = 1 To oSketch3D.SketchSplines3D.Count
            oSketchSpline3D = oSketch3D.SketchSplines3D.Item(j)
            oSketchSpline3D.Reference = False
            Dim oLong As Long = oSketchSpline3D.FitPointCount
            Dim oString As String = oLong.ToString
            MsgBox(" FitPoint " & oString)

            For k = 1 To oSketchSpline3D.FitPointCount
                oSketchPoint3D = oSketchSpline3D.FitPoint(k)
                oObjColl.Add(oSketchPoint3D)
            Next
        Next

        MsgBox(" oObjColl " & oObjColl.Co)

        For l = 1 To oSketch3D.SketchPoints3D.Count
            oSketchPoint3D = oSketch3D.SketchPoints3D.Item(l)
            oObjColl.Add(oSketchPoint3D)
        Next


        MsgBox("SketchPoints3D " & oSketch3D.SketchPoints3D.Count)

 

 

 

 

florian_wenzel_0-1669636647875.png

 

 

Thanks for any Suggestion

0 Likes
Accepted solutions (2)
324 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @florian_wenzel.  I don't know if this will make any difference in the outcome, but I did notice something in your code that seemed wrong to me.  I see that you created a SelectSet, but then you did not actually add the Sketch3D object to that set yet, which would have selected it, before executing the command to delete all the constraints from it.  So, I assume that it did not delete all the constraints from it, which might have cause problems in what you were trying to do later in the code, but I'm not sure.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 4

florian_wenzel
Advocate
Advocate

Hi,

i think with this Deleting Constaraints is ok, because i select PartDoc.

 

I got something like this, but this is not Perfect.

florian_wenzel_0-1669654125848.png

 

florian_wenzel_0-1669653903926.png

 

Code:

 

 

 

 

 

        Dim oEdge As Edge = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeFilter, " Pick a Edge")
        Dim oVertex As Vertex = g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kPartVertexFilter, " Pick a Vertex StartPoint of Curve")
        Dim oStartPoint As Point = oVertex.Point
        Dim oEdgeColl As EdgeCollection = oEdge.TangentiallyConnectedEdges



        Dim oSketch3D As Sketch3D = oCompDef.Sketches3D.Add

        Dim oEntity As SketchEntity3D
        For i = 1 To oEdgeColl.Count
            Dim oEdge_i As Edge = oEdgeColl.Item(i)
            oEntity = oSketch3D.Include(oEdge_i)
            oEntity.Reference = False
        Next

        Dim oSketchSpline3D As SketchSpline3D

        Dim oObjColl As ObjectCollection = oTO.CreateObjectCollection
        Dim oObjCollPoints As ObjectCollection = oTO.CreateObjectCollection
        Dim oObjCollPointsX As ObjectCollection = oTO.CreateObjectCollection

        Dim oCtrlDef As ButtonDefinition
        oCtrlDef = g_inventorApplication.CommandManager.ControlDefinitions.Item("Sketch3DDeleteConstraintsCtxCmd")
        Dim oSelectSet As SelectSet
        oSelectSet = oPartDoc.SelectSet
        oCtrlDef.Execute()





        For j = 1 To oSketch3D.SketchSplines3D.Count
            oSketchSpline3D = oSketch3D.SketchSplines3D.Item(j)

            Dim oPoles As Double() = {}
            Dim oKnots As Double() = {}
            Dim oWeights As Double() = {}

            oSketchSpline3D.Geometry.GetBSplineData(oPoles, oKnots, oWeights)
            For k = 1 To oPoles.Count / 3

                Dim oPoint As Point = oSketchSpline3D.Geometry.PoleAtIndex(k)
                oObjColl.Add(oPoint)
            Next
        Next



        Dim oDistance As New List(Of Double)


        For k = 1 To oObjColl.Count
            Dim oPoint As Point = oObjColl.Item(k)
            Dim oDouble As Double = oPoint.DistanceTo(oStartPoint)
            oDistance.Add(oDouble)
        Next

        oDistance.Sort()
        oDistance.Distinct().ToList()
        Dim oList As IEnumerable(Of Double) = oDistance.Distinct()



        For l = 0 To oList.Count - 1

            Dim oDouble_A As Double = oList(l)

            For m = 1 To oObjColl.Count

                Dim oPoint_X As Point = oObjColl.Item(m)
                Dim oDouble_X As Double = oPoint_X.DistanceTo(oStartPoint)

                If oDouble_A = oDouble_X Then

                    oObjCollPoints.Add(oPoint_X)
                    Exit For

                End If

            Next

        Next




        Dim oSketch3D_New As Sketch3D = oCompDef.Sketches3D.Add
        Dim oSplineCV As SketchControlPointSpline3D = oSketch3D_New.SketchControlPointSplines3D.Add(oObjCollPoints)

        Dim oSplineMerge As SketchSpline3D = oSplineCV.ConvertToSpline

 

Have someone better Solution?

How to Merge the Spline with better Tolerance?

I was Thinking to Cut with Planes each Spline, to get more Points, and then Create a Spline.

But maybe someone, have better idea?

Thanks for any Suggestion

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @florian_wenzel.  This seems like a fairly complex thing you are trying to achieve, and I don't think I have tried doing this exact process before, but I'm thinking that if you need more accuracy, then you may need to use more points along the profile.  To do that, I might suggest that instead of using the 'BSplineCurve.GetBSplineData' and 'PoleAtIndex', I might try using BSplineCurve.Evaluator.GetPointAtParam inside a loop with something like an additional 0.1 increment for the parameter at each loop, which should get you 10 points along its length.  Or maybe even something even smaller for more accuracy.  Then add each point to your ObjectCollection for use later.  Just a thought.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)