Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Constrained points get duplicated when creating a spline in Fusion using Python

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
josikWFKBV
201 Views, 2 Replies

Constrained points get duplicated when creating a spline in Fusion using Python

I have created a code that adds points to a sketch, dimensions them and then I would like a spline to go through it.

For the spline not to be altered by accident in the future, I would like to constrain everything that is possible, starting with the points. I have accomplished that, and if I run my code (at the end of this question) without the line: 

 

spline = sketch.sketchCurves.sketchFittedSplines.add(points)

 

everything works well and I get a sketch that looks like this: 

josikWFKBV_0-1727966127773.png

 

Unfortunately when I try to add these points to a spline, I lose the constraints. Here if I try to move it to the side, I get double of all the points I have...

josikWFKBV_1-1727966216156.pngjosikWFKBV_2-1727966223532.pngAm I duplicating some points by accident, or is there some logical flaw in my process? 

 

here is my code:

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try: 
        app = adsk.core.Application.get()
        ui = app.userInterface

        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        design = app.activeProduct

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Create a new sketch on the xy plane.
        sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)

        # Create an object collection for the points.
        points = adsk.core.ObjectCollection.create()

        dims = adsk.fusion.SketchDimensions.cast(sketch.sketchDimensions)

        a = 4
        xStart = -2
        xEnd = 2
        increment = 1
        i = 0

        for x in range(xStart, xEnd, increment):
            
            y = a * x ** 2

            if x > 0:
                textY = -x 
            else:
                textY = x 
                

            origin = sketch.originPoint
            point = sketch.sketchPoints.add(adsk.core.Point3D.create(x, y, 0))
            points.add(point)
            textPointX = adsk.core.Point3D.create(x, textY, 0)   
            textPointY = adsk.core.Point3D.create(x*1.5, y, 0)              

            dim = sketch.sketchDimensions
            distanceDimension = dim.addDistanceDimension(origin, points[i], adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation, textPointX)
            distanceDimension = dim.addDistanceDimension(origin, points[i], adsk.fusion.DimensionOrientations.VerticalDimensionOrientation, textPointY)
            

            i = i +1

        spline = sketch.sketchCurves.sketchFittedSplines.add(points)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

Looking forward to your replies and ideas 🙂 

2 REPLIES 2
Message 2 of 3
josikWFKBV
in reply to: josikWFKBV

I have partially solved this by adding "spline.isFixed = True"
Message 3 of 3

Hi,

 

I'd expect the sketchFittedSplines_var.add() method to use the sketchPoints supplied (as it receive both Point3D and SketchPoint objects), but it certainly duplicates them.

One solution could be just make the points collection of Point3Ds instead of SketchPoints, and then add the constraints after the spline creation, like in the following code snippet:

    spline = sketch.sketchCurves.sketchFittedSplines.add(points)
    for p in spline.fitPoints:
        textPointX = adsk.core.Point3D.create(p.geometry.x, -p.geometry.x, 0)
        textPointY = adsk.core.Point3D.create(p.geometry.x*1.5, p.geometry.y, 0)
        dims.addDistanceDimension(origin, p, adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation, textPointX)
        dims.addDistanceDimension(origin, p, adsk.fusion.DimensionOrientations.VerticalDimensionOrientation, textPointY)

 

I hope this can help.

 

Regards,

Jorge Jaramillo

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report