Pull post from linked folder

Pull post from linked folder

dames123
Advocate Advocate
487 Views
5 Replies
Message 1 of 6

Pull post from linked folder

dames123
Advocate
Advocate

Is there a way to pull a post file from a linked folder using the API?

 

dames123_0-1718816348927.png

 

Thanks.

0 Likes
488 Views
5 Replies
Replies (5)
Message 2 of 6

dames123
Advocate
Advocate

BUMP

0 Likes
Message 3 of 6

boopathi.sivakumar
Autodesk
Autodesk

Hi @dames123 

I think currently we don't have a support to read post from linked library via API. I will just confirm that.

Do you want to import the post from your local directory then use it? is it the workflow you are trying to acheive?

 


Boopathi Sivakumar
Senior Technology Consultant

0 Likes
Message 4 of 6

dames123
Advocate
Advocate

Hi @boopathi.sivakumar 

Yes. I have a script that currently pulls a post from the Fusion local folder and I would like to change that to a linked folder. Maybe @Jorge_Jaramillo has some insight?

 

#n360API Python script
import adsk.core
import traceback
import adsk.core as core
import adsk.fusion as fusion
import adsk.cam as cam

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

    except:
      app.log('Failed:\n{}'.format(traceback.format_exc()))

def create_and_duplicate_ncprogram(
    app: adsk.core.Application, 
) -> None:

        try:
            camObj: adsk.cam.CAM = app.activeProduct
            ui = app.userInterface
            
            # https://url.us.m.mimecastprotect.com/s/R9VIC2kr1Nf6PQk3I9ku4o?domain=help.autodesk.com
            ncPrograms: adsk.cam.NCPrograms = camObj.ncPrograms
            for setup in camObj.setups:

                ncIpt: adsk.cam.NCProgramInput = ncPrograms.createInput()
                ncIpt.displayName = setup.name
                ncParameters = ncIpt.parameters
                ncParameters.itemByName('nc_program_filename').value.value = setup.name
                ncParameters.itemByName('nc_program_openInEditor').value.value = False
                ncParameters.itemByName('nc_program_useMachineConfig').value.value = True
                ncParameters.itemByName('nc_program_filename').value.value = setup.parameters.itemByName('job_programName').value.value # Set the filename to the same as the setup
                ncParameters.itemByName('nc_program_comment').value.value = setup.parameters.itemByName('job_programComment').value.value

                ncIpt.operations = [setup]

                prg = ncPrograms.add(ncIpt)
                prg.machine = setup.machine  # Set the machine to the same as the setup
                app.log(f' {setup.name=} :: {setup.machine=} {prg.machine=}')
                
                # Duplicate the NCProgram
                duplicatedPrg = prg.duplicate()
                if duplicatedPrg:
                    camObj.ncPrograms[-1].name = f"{setup.name} SETUPSHEET"
                    postConf = import_post_processor()
                    if postConf:
                        camObj.ncPrograms[-1].postConfiguration = postConf
                        
                else:
                    app.log(f"Failed to duplicate NCProgram for setup: {setup.name=}")
                    app.log("Dont forget to set your tool numbers")

            for prg in ncPrograms:
                app.log(f"{prg.name} : nc_program_post = {prg.parameters.itemByName('nc_program_post').value.value}")
                
            ui.messageBox("Dont forget to set your tool numbers")

        except:
            app.log('Failed:\n{}'.format(traceback.format_exc()))
            

def import_post_processor() -> adsk.cam.PostConfiguration | None:

        POST_PROCESSOR_DESCR = 'Setup-Sheet-For-High-Speed'
        POST_PROCESSOR_FILENAME = 'Setup-Sheet-For-High-Speed.cps'
        POST_PROCESSOR_URL = 'user://'

        camMngr: adsk.cam.CAMManager = adsk.cam.CAMManager.get()
        camLibMngr: adsk.cam.CAMLibraryManager = camMngr.libraryManager
        postLibrary = camLibMngr.postLibrary

        importedURL: adsk.core.URL = None
        local_url = adsk.core.URL.create(POST_PROCESSOR_URL)

        # 1. Look for post processor locally
        for url in postLibrary.childAssetURLs(local_url):
            if url.leafName == POST_PROCESSOR_FILENAME:
                importedURL = url

        if not importedURL:
            # 2. Look for post processor in Fusion's PostProcessors Library
            postQuery = postLibrary.createQuery(adsk.cam.LibraryLocations.Fusion360LibraryLocation)
            postConfigs = postQuery.execute()
            for config in postConfigs:
                if config.description == POST_PROCESSOR_DESCR:
                    # 3. If found it, copy it locally
                    importedURL = postLibrary.importPostConfiguration(config, local_url, POST_PROCESSOR_FILENAME)

        if importedURL:
            postConf = postLibrary.postConfigurationAtURL(importedURL)
            return(postConf)
        else:
            return(None)
        
adsk.terminate()
0 Likes
Message 5 of 6

Jorge_Jaramillo
Collaborator
Collaborator

Hi @dames123 ,

What do you  mean by a "linked folder"?

Is it on your local hard drive outside of Fusion's environment?

0 Likes
Message 6 of 6

dames123
Advocate
Advocate

Hi @Jorge_Jaramillo ,

 

Yes, you can link a folder on a network share for your team to access. I know I should probably use the cloud but I prefer a hard copy.

 

dames123_0-1731703410199.png

 

0 Likes