Multiple .step file export driven by a changing variable in sketch.

Multiple .step file export driven by a changing variable in sketch.

tireblower
Community Visitor Community Visitor
308 Views
1 Reply
Message 1 of 2

Multiple .step file export driven by a changing variable in sketch.

tireblower
Community Visitor
Community Visitor

Hello everyone!

 

I have a question - 

Is it possible to add a variable in the sketch, produce all of the extrusions, etc, to get the solids, and then, when exporting the .step files out, have the .step files export with that variable changing its value?

 

Let's say I had made that variable for the length of the workpiece, ( originally 30mm let's say ) and then the first .step file export would have 30mm as the workpiece length, then the next as 29mm as the workpiece length, then the next 28mm, and so on, based on my pre-set change in the variable.

So here I would be left with 30 .step files, with workpiece length varying from 30mm to 1 mm.

 

Thank you in advance!

0 Likes
309 Views
1 Reply
Reply (1)
Message 2 of 2

kandennti
Mentor
Mentor

Hi @tireblower .

 

Does "variable in sketch" mean letters in the sketch?

 

For now, I have created a sample that exports a Step file while varying the extrusion height from 30 to 1.
Please open the attached f3d and then run the script.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core
import pathlib

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

        # query
        res = getExportFolder()
        if len(res) < 1:
            return
        dirPath = pathlib.Path(res)

        # get ModelParameter
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent
        extFeats: adsk.fusion.ExtendFeatures = root.features.extrudeFeatures
        extFeat: adsk.fusion.ExtendFeature = extFeats.item(0)
        distancePrm: adsk.fusion.ModelParameter = extFeat.extentOne.distance

        # get export manager
        expMgr: adsk.fusion.ExportManager = des.exportManager

        # distance list - unit Cm
        distanceLst = [round(i*0.1, 1) for i in range(30, 0, -1)]

        # update & export
        for dist in distanceLst:
            distancePrm.value = dist
            expPath = str(dirPath / f'{dist*10}.stp')
            stpOpts: adsk.fusion.STEPExportOptions = expMgr.createSTEPExportOptions(
                expPath,
                root
            )
            expMgr.execute(stpOpts)

        ui.messageBox('Done')

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


def getExportFolder() -> str:
    app: adsk.core.Application = adsk.core.Application.get()
    ui: adsk.core.UserInterface = app.userInterface

    dirDlg: adsk.core.FolderDialog = ui.createFolderDialog()
    dirDlg.title = 'Export Step File Test'

    res = dirDlg.showDialog()
    if res == adsk.core.DialogResults.DialogOK:
        return dirDlg.folder
    else:
        return ''