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: 

how I can import an exist file and modify it ?

1 REPLY 1
Reply
Message 1 of 2
mohammadkhader698
96 Views, 1 Reply

how I can import an exist file and modify it ?

I try to make a script to import an exist file I export it on my pc to modify it ?

which command I need to use ?

1 REPLY 1
Message 2 of 2

Hi @mohammadkhader698 .

 

If the document is in the data panel, there is no need to export it.

The documents "A" and "B" are in the same folder, and the following script is executed with "A" open.

1.png

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core


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

        # Search Ducument(DataFile)
        targetDocumentName = 'B'
        df: adsk.core.DataFile = getDataFileByName(targetDocumentName)
        if not df:
            return

        # Insert DataFile
        # https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-D2921ADB-3556-4B9E-98ED-2598EDDB852A
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent
        root.occurrences.addByInsert(
            df,
            adsk.core.Matrix3D.create(),
            False
        )

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


def getDataFileByName(
    name: str) -> adsk.core.DataFile:

    app: adsk.core.Application = adsk.core.Application.get()
    dataFolder: adsk.core.DataFolder = app.activeDocument.dataFile.parentFolder
    for df in dataFolder.dataFiles.asArray():
        if df.name == name:
            return df

    return None


After execution, "B" will end up being inserted.

2.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