how I can import an exist file and modify it ?

how I can import an exist file and modify it ?

mohammadkhader698
Participant Participant
339 Views
1 Reply
Message 1 of 2

how I can import an exist file and modify it ?

mohammadkhader698
Participant
Participant

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 ?

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

kandennti
Mentor
Mentor

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

 

0 Likes