Using Cloud Library Post for Post Process Input

Joshua.mursic
Advocate

Using Cloud Library Post for Post Process Input

Joshua.mursic
Advocate
Advocate

Hello, I am trying to use a Post processor on my cloud library for use in the PostProcessInput class. The 

PostProcessInput class wants the post configuration to be a string path to the post, but I dont understand how to give it a post that is located in my Cloud Library.
 

 

import adsk.core, adsk.cam

app = adsk.core.Application.get()
ui = app.userInterface

def getPost(targetPostName:str):
    camManager = adsk.cam.CAMManager.get()
    libraryManager = camManager.libraryManager
    postLibraries = libraryManager.postLibrary
    cloudFolder = postLibraries.urlByLocation(adsk.cam.LibraryLocations.CloudLibraryLocation)
    cloudPostlibrary = postLibraries.childAssetURLs(cloudFolder)

    # Get Templates
    for cloudPost in cloudPostlibrary:
        postName = cloudPost.toString()
        if targetPostName in postName:
            postUrl = adsk.core.URL.create(postName)
            # postConfiguration = postLibraries.postConfigurationAtURL(postUrl)
            return postUrl.toString()

    # Error if not found
    ui.messageBox(f"Could not find Postprocessor {targetPostName}")


def postProcess():
    cam:adsk.cam.CAM = app.activeDocument.products.itemByProductType("CAMProductType")
    setups = cam.setups
    setup = setups.item(0)

    # specify the program name, post configuration to use and a folder destination for the nc file
    programName = '1010'
    postConfig = getPost("Dumper.cps")
    outputFolder = cam.temporaryFolder
    units = adsk.cam.PostOutputUnitOptions.DocumentUnitsOutput
    # create the postInput object
    postInput = adsk.cam.PostProcessInput.create(programName, postConfig, outputFolder, units)
    postInput.isOpenInEditor = False

    cam.postProcess(setup, postInput)

 

 

Here I am searching my cloud library for the post with the name Dumper.cps, then I am getting the URL to that post as a string, which looks like this: "cloud://Dumper.cps"

 

I pass that to the PostProcessInput class, but it is returning:

"RuntimeError: 3 : The input configuration file does not exist."

 

Is it possible to use cloud posts?

1 Like
Reply
Accepted solutions (1)
431 Views
2 Replies
Replies (2)

kandennti
Mentor
Mentor
Accepted solution

Hi @Joshua.mursic -San.

 

I modified it based on the sample here.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-995d634e-a8ef-4f2b-a826-1d32171f4998 

 

def getPost(targetPostName:str):
    camManager = adsk.cam.CAMManager.get()
    libraryManager = camManager.libraryManager
    postLibraries = libraryManager.postLibrary
    cloudFolder = postLibraries.urlByLocation(adsk.cam.LibraryLocations.CloudLibraryLocation)
    cloudPostlibrary = postLibraries.childAssetURLs(cloudFolder)

    # Get Templates
    for cloudPost in cloudPostlibrary:
        postName = cloudPost.toString()
        if targetPostName in postName:
            postUrl = adsk.core.URL.create(postName)
            # postConfiguration = postLibraries.postConfigurationAtURL(postUrl)
            # return postUrl.toString()
            return postLibraries.postConfigurationAtURL(postUrl)

    # Error if not found
    ui.messageBox(f"Could not find Postprocessor {targetPostName}")


def postProcess():
    cam:adsk.cam.CAM = app.activeDocument.products.itemByProductType("CAMProductType")
    setups = cam.setups
    setup = setups.item(0)

    # specify the program name, post configuration to use and a folder destination for the nc file
    programName = '1010'
    postConfig = getPost("Dumper.cps")
    outputFolder = cam.temporaryFolder
    # units = adsk.cam.PostOutputUnitOptions.DocumentUnitsOutput
    # create the postInput object
    # postInput = adsk.cam.PostProcessInput.create(programName, postConfig, outputFolder, units)
    # postInput.isOpenInEditor = False

    # cam.postProcess(setup, postInput)

    ncInput = cam.ncPrograms.createInput()
    ncInput.displayName = 'NC Program Sample'

    ncParameters = ncInput.parameters
    ncParameters.itemByName('nc_program_name').value.value = programName
    ncParameters.itemByName('nc_program_filename').value.value = 'NCProgramSample'
    ncParameters.itemByName('nc_program_openInEditor').value.value = False
    ncParameters.itemByName("nc_program_unit").value.value = 'DocumentUnit'
    ncParameters.itemByName('nc_program_output_folder').value.value = outputFolder

    ncInput.operations = list(setup.operations)
    newProgram = cam.ncPrograms.add(ncInput)
    newProgram.postConfiguration = postConfig

    postOptions = adsk.cam.NCProgramPostProcessOptions.create()

    newProgram.postProcess(postOptions)

 

It seems to work fine in my environment.

 

1 Like

Joshua.mursic
Advocate
Advocate

@kandennti  thank you very much!

1 Like