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: 

Python Script does not display sketch

1 REPLY 1
Reply
Message 1 of 2
me19b057
192 Views, 1 Reply

Python Script does not display sketch

Hi!

I've just started using the API and want to make a sketch for which I have a script.

The script shows no warnings or errors in VSCode but when I run it on Fusion 360, nothing happens.

 

I would really appreciate it if someone could explain what is wrong or could refer to links from where I can learn.

Here is the code:

 

import adsk.core, adsk.fusion, adsk.cam, traceback, math

def Haack()
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent
        
        # Create a new sketch.
        sk = root.sketches.add(root.xYConstructionPlane)

        #Collection of points
        pnts = adsk.core.ObjectCollection.create()

        #Initializing loop to add points
        x=0
        L= 75.625
        for i in range(0,75.625,0.1)
            x = i
            phi = 1 - (2*x/L)
            theta = math.acos(phi)
            y = (2.75*2.5/math.pow(math.pi,0.5))*(math.pow((theta - (math.sin(2*theta)/2)),0.5))
            pnts.add(adsk.core.Point3D.create(x,y,0))
            sk.sketchCurves.sketchFittedSplines.add(pnts)
        ui.messageBox('Nose Cone Plotted')
    
 def run(context)
    try:
        Haack()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
1 REPLY 1
Message 2 of 2
JeromeBriot
in reply to: me19b057

Hello,

 

You should read a Python tutorial for beginners.

 

import adsk.core, adsk.fusion, adsk.cam, traceback, math 

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

        # Create a new sketch.
        sk = root.sketches.add(root.xYConstructionPlane)

        #Collection of points
        pnts = adsk.core.ObjectCollection.create()

        #Initializing loop to add points
        x=0
        L= 75.625
        for i in range(0, 75625, 100):
            x = i/1000
            phi = 1 - (2*x/L)
            theta = math.acos(phi)
            y = (2.75*2.5/math.pow(math.pi,0.5))*(math.pow((theta - (math.sin(2*theta)/2)),0.5))
            pnts.add(adsk.core.Point3D.create(x,y,0))
        sk.sketchCurves.sketchFittedSplines.add(pnts)
        ui.messageBox('Nose Cone Plotted')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def run(context):
    Haack()

 

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