formFeatures.add() hard crashes fusion, when in direct editing mode

formFeatures.add() hard crashes fusion, when in direct editing mode

vytska4301
Contributor Contributor
195 Views
2 Replies
Message 1 of 3

formFeatures.add() hard crashes fusion, when in direct editing mode

vytska4301
Contributor
Contributor
I am writing a subd- to tspline converter that allows converting tspline objects back and fourth to subd. i am trying to do TSplineBodies.addByTSMDescription, but in order to access it, i have to have a form feature created. I need the t-spline body to be "live" as it is, when regularly working with tspline bodies in direct editing mode (enabling and disabling timeline for the import works, however i loose the editable tspline, as it gets converted to Brep, when formFeature finishes).
The ui route for adding a Tspline body with a .tsm file also works in direct mode (the insert T-spline command), but .tsm it is not exposed through the importManager [adding tsm support in the import manager would probably be an easier and more elegant fix]


adding a script, that causes fusion to crash if timeline is dissabled

import
adsk.core, adsk.fusion, traceback

def run(context😞
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent
        #fusion hard crashes if executed in direct/no timeline mode), while works fine in parametric
        root.features.formFeatures.add()

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


p.s. [pipe feature also crashes in direct mode, however i overcame that with a sweep].
zozeorswaf
0 Likes
196 Views
2 Replies
Replies (2)
Message 2 of 3

Radwan-Almsora
Enthusiast
Enthusiast

The issue occurs because formFeatures.add() is strictly designed for Parametric Modeling (Timeline enabled) In Fusion 360, a Form Feature acts as a historical container that transitions the workspace into the Sculpt Environment Calling it in Direct Modeling (No Timeline) confuses the core engine and causes an immediate hard crash .

 

Here are the workarounds and fixes to solve this in your script:🛠️ Recommended Workarounds1. Execute the Native UI Command (Best for .tsm Files)Since the official "Insert T-Spline" UI command works perfectly in Direct Mode  you can trigger it programmatically using its Command ID. This bypasses the missing importManager support How: Use app.userInterface.commandDefinitions.itemById('FusionTSpIn_cmd').execute() to launch the native import dialog. Prevent Crashes Using Design Type ValidationAlways check the active design mode before attempting to create historical features. This ensures your script exits safely instead of crashing the software 💻 Crash-Safe ImplementationHere is how you can update your script to check the design environment type and avoid the hard crash

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        root = design.rootComponent
        
        # 1. Check if the timeline is disabled (Direct Design)
        if design.designType == adsk.fusion.DesignTypes.DirectDesignType:
            ui.messageBox('Error: formFeatures.add() cannot be used in Direct Modeling Mode.\nPlease enable the timeline or use native import commands.')
            return
            
        # 2. This will only run safely in Parametric Mode
        formFeature = root.features.formFeatures.add()
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Did you find this post helpful? If it gave you one or more solutions,

don't forget to click the Accept Solution button and leave a < like !

 

0 Likes
Message 3 of 3

vytska4301
Contributor
Contributor

@Radwan-Almsora can you please stop posting ai generated comments to like farm? your suggestions in multiple of my posts just re-state the issues i have using fusion api in direct editing mode

zozeorswaf
0 Likes