template path in API local

template path in API local

TRIALCAD2014
Enthusiast Enthusiast
508 Views
2 Replies
Message 1 of 3

template path in API local

TRIALCAD2014
Enthusiast
Enthusiast

I'm trying the new operation sample in the documentation https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-AEF0708D-B657-4E9F-9032-4535E0D1C417

my template manager tells me that my templates are stored under Local//my templates yet the documentation uses an absolute  path

path = "E://face.f3dhsm-template";

that does not match with how the product displays it.

how can I programatically get the /Local path?

 

Thank you,
Adrian

0 Likes
Accepted solutions (1)
509 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @TRIALCAD2014 .

 

I created a function to get the default template folder in the Win version.

# Fusion360API Python script
import traceback
import adsk.cam
import adsk.fusion
import adsk.core
import pathlib
import json


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

        path = get_CAM_Templates_Default_Folder_Path()

        if len(path) > 0:
            msg = f'The default template folder is \n {path}'
        else:
            msg = 'The default template folder was unknown.'

        ui.messageBox(msg)

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


def get_CAM_Templates_Default_Folder_Path() -> str:
    app: adsk.core.Application = adsk.core.Application.get()

    pathsJson = json.loads(app.executeTextCommand(u'paths.get'))
    tmpPath = pathlib.Path(pathsJson['userDataDirectory'])
    folder = tmpPath.parent.parent / 'CAM360' / 'templates'

    if folder.is_dir():
        return str(folder)
    else:
        return ''

 

However, if I were to create an add-in that uses CAM templates, I would export the templates beforehand and place them in the add-in folder to be called.

This way, the file is more secure and less likely to be modified.

Message 3 of 3

TRIALCAD2014
Enthusiast
Enthusiast

Hello,

 

Thank you for your helpful reply. I was expecting a method in the manufacture API to do that instead of using a round about way with textcommands.

I did manage to get it directly from Os with

localPath=os.path.dirname(os.path.abspath(__file__))+"\\..\\..\\..\\..\\CAM360\\templates\\"
    boxCountourTemplateFilename = localPath+"b box contour.f3dhsm-template"
    pauseTemplateFilename = localPath+"b box pause.f3dhsm-template"    
 
but your way seems to be more appropriate.
Thank you for the smart suggestion of putting the template in the scripts path. That would make my solution much simpler because will require just a os.path.abspath(__file__)) call
I'm thinking to make this plugin public so maybe it's simpler for the users to use the default. The templates will be better user created to match their machines. It's  little bit of grasping at the straws as the cam API is so inexistent that operations created with the templates will be invalid anyway.

Thank you
Adrian
    drillTemplateFilename = localPath+"b box drill.f3dhsm-template"