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: 

Running script in design history

4 REPLIES 4
Reply
Message 1 of 5
hpekristiansen
521 Views, 4 Replies

Running script in design history

I would like to

1. Use the GUI to design a visual pleasing body 🙂

2. Run a script, that creates a wireframe from that body

3. Continue to use the GUI to create a base for the object

 

I would like to run the script in the middle of my design process, and I would like to be able to go back and make changes to the original body. Can a script be incorporated in the design history?

ScreenShot2019-12-13T230547@2X.png

 

Does something like this exist?

Will it be possible in the future?

Is there any workaround?

 

4 REPLIES 4
Message 2 of 5
goyals
in reply to: hpekristiansen

There are API to group certain feature in the timeline http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7b9f1f72-ec07-4dd4-8725-93421aa6b9b4 but there is no API to add custom feature which participates in the design compute pipeline. Thanks.



Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 5
kandennti
in reply to: hpekristiansen

Hi hpekristiansen.

 

Everything is done with API, do you want this kind of processing?

1.png

#Fusion360API Python script
#Author-kantoku
#Description-add sketch

import adsk.core, adsk.fusion, traceback


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

        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        # create body
        initExtrude(root, 0, 0, 5, 5)
        initExtrude(root, 10, 10, 15, 15)
        fit(app)

        # two previous
        ui.messageBox('moves the timeline marker to the two previous ')
        timeline = des.timeline
        for dmy in range(2):
            timeline.moveToPreviousStep()

        # add sketch
        ui.messageBox('add sketch')
        initSketch(root, -5, -5, -10, -10)
        fit(app)

        # end of the timeline
        ui.messageBox('moves the marker to the end of the timeline')
        timeline.moveToEnd()
        fit(app)

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

def fit(app):
    actView = app.activeViewport
    actView.refresh()
    actView.fit()

def initExtrude(comp, x1, y1, x2, y2):
    skt = initSketch(comp, x1, y1, x2, y2)
    prof = skt.profiles.item(0)

    exts = comp.features.extrudeFeatures
    newBodyOpe = adsk.fusion.FeatureOperations.NewBodyFeatureOperation
    extIpt = exts.createInput(prof, newBodyOpe)
    dist = adsk.core.ValueInput.createByReal(5.0)
    extIpt.setDistanceExtent(False, dist)
    extIpt.isSolid = True
    exts.add(extIpt)

def initSketch(comp, x1, y1, x2, y2):
    skts = comp.sketches
    skt = skts.add(comp.xYConstructionPlane)

    pnt3d = adsk.core.Point3D
    pnt1 = pnt3d.create(x1, y1, 0.0)
    pnt2 = pnt3d.create(x2, y2, 0.0)

    lines = skt.sketchCurves.sketchLines
    lines.addTwoPointRectangle(pnt1, pnt2)

    return skt

 

Message 4 of 5
hpekristiansen
in reply to: kandennti

Thank you for the suggestion - It is a workaround of sorts.

 

I would need to make the changes in the GUI, and rerun the script(instead of it running automatically as part of the timeline). The script would need to identify what it did the last time it ran, delete that and redo it. I do not see that as practically.

Message 5 of 5
kandennti
in reply to: hpekristiansen

I don't understand English at all, so I might be mistaken.
It was interpreted as a profile replacement process using sketches added in the GUI.

 

The data created by the previous script is attached.

 

 

1.png
The green arrow extrude is created using a blue arrow sketch.
Replace this with the red arrow profile.

 

 

2.png

However, for the script, start from the position where the sketch was created with the GUI,

and select the sketch.

 

#Fusion360API Python script
#Author-kantoku
#Description-replace profile

import adsk.core, adsk.fusion, traceback

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

        # select sketch
        msg = 'Select Sketch'
        selFiltter :str = 'Sketches, SketchCurves, SketchLines, SketchCircles, SketchPoints'
        sel :adsk.core.Selection = selectEnt(ui, msg ,selFiltter)
        if not sel: return

        # get sketch
        selEnt = sel.entity
        skt :adsk.fusion.Sketch = None
        if selEnt.objectType == 'adsk::fusion::Sketch':
            skt = selEnt
        else:
            skt = selEnt.parentSketch

        # find ExtrudeFeature
        timeline :adsk.fusion.Timeline = des.timeline
        for idx in range(timeline.markerPosition, timeline.count):
            ent = timeline.item(idx).entity
            
            if ent.objectType == 'adsk::fusion::ExtrudeFeature':
                pros = adsk.core.ObjectCollection.create()
                [pros.add(pro) for pro in skt.profiles]

                # replace profile
                ent.profile = pros
                break

        # timeline move end
        timeline.moveToEnd()

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

def selectEnt(
        ui :adsk.core.UserInterface,
        msg :str, 
        filtterStr :str) -> adsk.core.Selection :

    try:
        sel = ui.selectEntity(msg, filtterStr)
        return sel
    except:
        return None

3.png

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