Fusion 360 Script Error: "(filename) is an active document"

Fusion 360 Script Error: "(filename) is an active document"

don_tonny_123
Explorer Explorer
389 Views
4 Replies
Message 1 of 5

Fusion 360 Script Error: "(filename) is an active document"

don_tonny_123
Explorer
Explorer

 

Hi everyone,

 

I'm experiencing a persistent issue when trying to run a Python script in Fusion 360. I keep getting the error message:

 

AttributeError: 'NoneType' object has no attribute 'isActive'

or

No active document / No active product

 

Here's what I've tried so far:

 

I start Fusion 360 normally

 

I create a new design via File → New Design

 

I do NOT open the script dialog first

 

Then I go to Utilities → Scripts and Add-Ins, select my script, and click Run

 

The script crashes immediately with the error that no active design/product is found

 

Even with this minimal test script:

 

app = adsk.core.Application.get()

ui = app.userInterface

 

if not app.activeDocument:

ui.messageBox("No active document found")

return

 

 

 

…I still get the same error, even though a new design is definitely open.

 

I’ve already:

 

Reset Fusion settings

 

Cleared the cache folders

 

Disabled all add-ins

 

Reinstalled Fusion 360

 

Nothing helps.

 

Has anyone else encountered this issue or found a workaround?

Any ideas would be greatly appreciated!

 

Thanks in advance.

 

 

 

Fusion 2601.1.34 x86_64

Aktiver Plan: Privatanwender

Windows 11 Home 23H2 (22631.5126)

0 Likes
390 Views
4 Replies
Replies (4)
Message 2 of 5

don_tonny_123
Explorer
Explorer

 +++

 

Hi everyone,

 

I'm experiencing a persistent issue when trying to run a Python script in Fusion 360. I keep getting the error message:

 

AttributeError: 'NoneType' object has no attribute 'isActive'

or

No active document / No active product

 

Here's what I've tried so far:

 

I start Fusion 360 normally

 

I create a new design via File → New Design

 

I do NOT open the script dialog first

 

Then I go to Utilities → Scripts and Add-Ins, select my script, and click Run

 

The script crashes immediately with the error that no active design/product is found

 

Even with this minimal test script:

 

app = adsk.core.Application.get()

ui = app.userInterface

 

if not app.activeDocument:

ui.messageBox("No active document found")

return

 

 

 

…I still get the same error, even though a new design is definitely open.

 

I’ve already:

 

Reset Fusion settings

 

Cleared the cache folders

 

Disabled all add-ins

 

Reinstalled Fusion 360

 

Nothing helps.

 

Has anyone else encountered this issue or found a workaround?

Any ideas would be greatly appreciated!

 

Thanks in advance.

 

 

 

Fusion 2601.1.34 x86_64

Aktiver Plan: Privatanwender

Windows 11 Home 23H2 (22631.5126)

 

 

0 Likes
Message 3 of 5

kandennti
Mentor
Mentor

Hi @don_tonny_123 -san.

After creating a new script, it looks like this.

"""This file acts as the main module for this script."""

import traceback
import adsk.core
import adsk.fusion
# import adsk.cam

# Initialize the global variables for the Application and UserInterface objects.
app = adsk.core.Application.get()
ui  = app.userInterface


def run(_context: str):
    """This function is called by Fusion when the script is run."""

    try:
        # Your code goes here.
        ui.messageBox(f'"{app.activeDocument.name}" is the active Document.')
    except:  #pylint:disable=bare-except
        # Write the error message to the TEXT COMMANDS window.
        app.log(f'Failed:\n{traceback.format_exc()}')


I created a new document and ran the script and got the same result as the image you attached. I don't see anything wrong with it.

 

If there is a problem, please provide the actual code you ran.

0 Likes
Message 4 of 5

don_tonny_123
Explorer
Explorer

Hello Kandennti,

As an example, this code creates a small curved component. After execution, this message appears, but the component is not displayed.

 

 

 

import adsk.core, adsk.fusion, traceback

 

def run(context):

    ui = None

    try:

        app = adsk.core.Application.get()

        ui = app.userInterface

        

        # 🔥 NEU: Dokument sicherstellen

        design = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

        design = app.activeProduct

        rootComp = design.rootComponent

        

        # Maße

        length = 220.0 # Länge in mm

        width_front = 60.0 # Breite vorne

        width_rear = 70.0 # Breite hinten

        thickness = 3.0 # Materialstärke

        

        # Trapez-Skizze erstellen

        sketches = rootComp.sketches

        xyPlane = rootComp.xYConstructionPlane

        sketch = sketches.add(xyPlane)

        

        # Punkte für Trapez

        points = adsk.core.ObjectCollection.create()

        points.add(adsk.core.Point3D.create(0, 0, 0))

        points.add(adsk.core.Point3D.create(length, 0, 0))

        points.add(adsk.core.Point3D.create(length, width_rear, 0))

        points.add(adsk.core.Point3D.create(0, width_front, 0))

        

        # Linien zeichnen

        sketch.sketchCurves.sketchLines.addByTwoPoints(points.item(0), points.item(1))

        sketch.sketchCurves.sketchLines.addByTwoPoints(points.item(1), points.item(2))

        sketch.sketchCurves.sketchLines.addByTwoPoints(points.item(2), points.item(3))

        sketch.sketchCurves.sketchLines.addByTwoPoints(points.item(3), points.item(0))

        

        # Extrudieren

        extrudes = rootComp.features.extrudeFeatures

        profile = sketch.profiles.item(0)

        extrudeInput = extrudes.createInput(profile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

        extrudeInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(thickness))

        extrude = extrudes.add(extrudeInput)

        

        # Sheet Metal aktivieren

        sheetMetal = design.fusionSheetMetal

        if sheetMetal.sheetMetalRules.count == 0:

            sheetMetal.addSheetMetalRule()

        sheetMetalRule = sheetMetal.sheetMetalRules.item(0)

        sheetMetalRule.thickness = thickness

        

        ui.messageBox('Biegung R620 manuell im Sheet Metal-Werkzeug hinzufügen!')

        

    except:

        if ui:

            ui.messageBox('Fehler:\n{}'.format(traceback.format_exc()))

0 Likes
Message 5 of 5

kandennti
Mentor
Mentor

@don_tonny_123 -san.

 

I checked and found that there is no method to create a new sheet metal rule.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-BFE11BED-D717-415F-B401-3F0769F7673E 

 

Therefore, we are using a text command to force a solid body to become a sheet metal body to create a sheet metal rule.

・・・
        # Extrudieren
        extrudes = rootComp.features.extrudeFeatures
        profile = sketch.profiles.item(0)
        extrudeInput = extrudes.createInput(profile, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        extrudeInput.setDistanceExtent(False, adsk.core.ValueInput.createByReal(thickness))
        extrude = extrudes.add(extrudeInput)

        # Sheet Metal aktivieren
        # sheetMetal = design.fusionSheetMetal
        # if sheetMetal.sheetMetalRules.count == 0:
        #     sheetMetal.addSheetMetalRule()
        # sheetMetalRule = sheetMetal.sheetMetalRules.item(0)
        # sheetMetalRule.thickness = thickness

        ui.activeSelections.clear()
        ui.activeSelections.add(extrude.endFaces[0])
        app.executeTextCommand(u"Commands.Start ConvertToSheetMetalCmd")
        app.executeTextCommand(u"NuCommands.CommitCmd")
        ui.activeSelections.clear()

        ui.messageBox('Biegung R620 manuell im Sheet Metal-Werkzeug hinzufügen!')
・・・
0 Likes