Select Component, create new file and paste as a linked component?

Select Component, create new file and paste as a linked component?

ebunn3
Advocate Advocate
362 Views
2 Replies
Message 1 of 3

Select Component, create new file and paste as a linked component?

ebunn3
Advocate
Advocate

Is it possible to do the following with the api?

 

  • select a component and copy it
  • create a new document
  • insert or paste in the linked component.  

 

Possible using this?   Is there an example?  

Component.saveCopyAs Method

 

 


Thanks

 

Eric

 

0 Likes
363 Views
2 Replies
Replies (2)
Message 2 of 3

ebunn3
Advocate
Advocate

Replying to my own post:

 

I have figured out how to use component.saveCopyAs and have pasted the code below.  I still would like to know how I could have it linked to the original component file because it appears to be just a copy.  Is this possible?

 

Eric

#Author-Bunn
#Description-Select Entities on screen and return the filtered selection.  Does one at a time only.

import adsk.core, adsk.fusion, adsk.cam, traceback




def selectEnt(msg: str,filtterStr: str) -> adsk.core.Selection:
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        sel = ui.selectEntity(msg, filtterStr)
        #get the BRep from the selection (Programming Interface  Fusion 360 API User's Manual  Selection Filters)
        if filtterStr == 'Faces':
            face = adsk.fusion.BRepFace.cast(sel.entity)
            return face
        elif  filtterStr == 'Bodies':
            body = adsk.fusion.BRepBody.cast(sel.entity)
            return body
        elif  filtterStr == 'SolidBodies':
            body = adsk.fusion.BRepBody.cast(sel.entity)
            return body
        elif  filtterStr == 'Edges':
            body = adsk.fusion.BRepEdge.cast(sel.entity)
            return body
        else:
            return sel
    except:
        return None

def getDataFolder():
    # get active datafile
    actDataFile: adsk.core.DataFile = app.activeDocument.dataFile
    if actDataFile:
        # get the unique data file
        dataFolder: adsk.core.DataFolder = app.activeDocument.dataFile.parentFolder
        return dataFolder
    else:
        return None

ui = None
app = adsk.core.Application.get()
ui  = app.userInterface
root = app.activeProduct.rootComponent
parentName = root.name

ui.messageBox('Select Body')
targetBody: adsk.fusion.BRepFace = selectEnt('Select Body','SolidBodies')
comp = targetBody.parentComponent
name = comp.name

#get dataFolder
dataFolder = getDataFolder()
if not dataFolder:
    ui.messageBox('Save file first.')
else: 
    comp.saveCopyAs(parentName + " " + name + "Tray Design",dataFolder,"","")

 

0 Likes
Message 3 of 3

BrianEkins
Mentor
Mentor

There are a couple of options if you want to reference geometry from one file into another.  The first is to insert an existing file into another.  You can do this in the UI but having the file open you want to insert into and finding the file you want to insert in the data panel.  Right-click on the file in the data panel and choose "Insert into Current Design". You'll see the contents of the file appear in the active file as a new occurrence.  It's a reference to the original design so if you edit the original design, this will update.  A limitation of this approach is you get the contents of the entire file and can't pick and choose specific bodies or other entities.  You are also limited in what you can do with the inserted geometry.  For example, you can't add additional features to the model. You need to add them to the original model instead. However, it is possible to do this using the API.

 

The other approach is to use the Derive functionality.  You use the "Insert Derive" command, which is available in the INSERT panel. This is similar in that you have the design active that you want to insert into and then run the command. This command prompts you to select another design and then you can choose items from that design to include so you can limit it to a specific body. The resulting body is still associative to the original design but it behaves like any other body and you can add additional features to it.  If you modify the original design, everything will update.  The derive functionality is not currently supported by the API at all.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com