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: 

Sizing problem when performing a coincident constraint

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
vitor.carneiro
148 Views, 2 Replies

Sizing problem when performing a coincident constraint

Hello,

 

I would like help with the following problem.
I want to include a spline inside a sketch that already contains a line, and make two constraints: the first with the first point of the line and the spline, and the second, between the end point of the line and the middle of the spline.
But I encounter the problem of a line dimension error after the constraints (decreasing its size).
Here's the code and photo of the error found.

 

Note 1: I really need to insert the spline in the sketch, as this is just a test for another application, where it is necessary to perform this operation.

Note 2: I need the line to remain the same 8 cm as it initially has.

 

Thank you very much,
Vitor Urel

Labels (1)
2 REPLIES 2
Message 2 of 3
kandennti
in reply to: vitor.carneiro

Hi @vitor.carneiro .

 

How about adding a DistanceDimension in advance?

# Fusion360API Python script
import adsk.core, adsk.fusion, traceback

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app :adsk.fusion.Application = adsk.core.Application.get()
        ui = app.userInterface
        des :adsk.fusion.Design = app.activeProduct
        root :adsk.fusion.Component = des.rootComponent

        sk = root.sketches.add(root.xYConstructionPlane)
        sk1 = root.sketches.add(root.xYConstructionPlane)

        points = adsk.core.ObjectCollection.create()
        pnts = [
            [0,0,0],
            [5,1,0],
            [6,4,0],
            [7,6,0],
            [2,3,0],
            [0,1,0],
            ]
        Pnt3D = adsk.core.Point3D
        for p in pnts:
            points.add(Pnt3D.create(p[0],p[1],p[2]))

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

        spline1 = sk.include(spline)
        spline2 = spline1.item(0)

        line = sk.sketchCurves.sketchLines.addByTwoPoints(
            Pnt3D.create(0,0,0),
            Pnt3D.create(8,0,0)
        )

        # DistanceDimension
        sk.sketchDimensions.addDistanceDimension(
            line.startSketchPoint,
            line.endSketchPoint,
            adsk.fusion.DimensionOrientations.AlignedDimensionOrientation,
            Pnt3D.create(4,1,0))

        sk.geometricConstraints.addCoincident(
            line.startSketchPoint,
            spline2.startSketchPoint
        )

        sk.geometricConstraints.addCoincident(
            line.endSketchPoint,
            spline2
        )

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

1.png

 

Message 3 of 3
BrianEkins
in reply to: kandennti

If you want the line to remain exactly where it was before adding the coincident constraints, I think the best solution is to fix both endpoints of the line.  You can do that with something like this:

line.startSketchPoint.isFixed = True
line.endSketchPoint.isFixed = True
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report