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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Managing Sketch Curves and GeometricConstraints

Message 1 of 2
812 Views, 1 Reply

Managing Sketch Curves and GeometricConstraints

I'm trying to understand how an existing sketch made through the GUI is drawn and constrained through Python. I know how to get lists for each of the objects within a sketch, such as points, lines, arc, circles, and constraints. But I'm having a hard time figuring out how to know the names of the curves each constraint is referring to. Or basically how everything is interconnected/linked.


For example:

  1. I can get a list of points and give them all variable names.
  2. I can then get a list of all lines and give them all variable names
  3. I can use the start and end points on each line to refer back to the point name instead of hard coding locations.
  4. I can go through each line and list out which GeometricConstraints constraint it.
  5. I can also go through all the constraints in a sketch and get the entities or points they constrain. 

Is there an ID I can use to identify each constraint or curve or object in a sketch?


Or after Step #4, I could dig deeper by getting the other line or point in the constraint... but I still don't have a way of knowing which line that is.


Should I be adding an attribute to each curve so that I can figure out which one it is while I'm traversing the constraint web?


How does Fusion 360 recreate a sketch when the file is opened? Does it draw the curves, then add the constraints?

Message 2 of 2
in reply to: commonmandan

You don't need an ID but can use the object itself for comparison.  For example, lets say you have a list of 10 lines that we'll refer to as line 0, line 1, line 2, and up to line 9.  As you examine a sketch point to find out what's connected to it you can compare the lines you get back from the constraints to those in the list to know which lines are connected to a give point.  The most important line in the code below is the "if ent == line:" Where it's comparing two references to SketchLine objects to see if they're the same line. You can do that with any API objects to see if any references you have are to the same object.


def run(context):
    ui = None
        app = adsk.core.Application.get()
        ui  = app.userInterface
        skPointSel = ui.selectEntity('Select a sketch point.', 'SketchPoints')
        if skPointSel:
            skPoint = adsk.fusion.SketchPoint.cast(skPointSel.entity)
        # Get the parent sketch.
        sk = skPoint.parentSketch

        # Get the lines from the sketch.
        lines = []
        for line in sk.sketchCurves.sketchLines:
        connectedLines = 'Connected lines: '
        for ent in skPoint.connectedEntities:
            lineCnt = 0
            for line in lines:
                if ent == line:
                    connectedLines += str(lineCnt) + ', '
                lineCnt += 1

        if ui:

Attributes are typically used to solve two problems.  One is that you want to identify a particular entity so you can find it later, even after the model has changed or in another session.  The other thing attributes are used for is to associate information with a particular entity.



Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog

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