Message 1 of 1
Issue with createFromCAMTemplate2 - Need to Add Operations to the Start of the Setup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Fusion 360 Community,
I hope this message finds you well. I'm currently facing an issue with the `createFromCAMTemplate2` function in my Python script. When using this function, the new operations are added to the end of the parent setup. However, I need them to be added to the start of the setup.
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Get the active document.
doc = app.activeDocument
# From the Products collection on the active document, get the CAM Product.
cam: adsk.cam.CAM = doc.products.itemByProductType('CAMProductType')
# Check if anything was returned.
if cam == None:
ui.messageBox('There is no CAM data in the active document')
return
camManager = adsk.cam.CAMManager.get()
templateLibrary = camManager.libraryManager.templateLibrary
LocalFolder = templateLibrary.urlByLocation(adsk.cam.LibraryLocations.LocalLibraryLocation)
templateLibs = getLibrariesURLs(templateLibrary, LocalFolder)
for libUrl in templateLibs:
if 'Vacuum' in libUrl:
url = adsk.core.URL.create(libUrl)
break
VacuumTemplate = templateLibrary.templateAtURL(url)
setups = cam.setups
newVacuumOperation = adsk.cam.CreateFromCAMTemplateInput.create()
newVacuumOperation.camTemplate = VacuumTemplate
for setup in setups:
setup.createFromCAMTemplate2(newVacuumOperation)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def getLibrariesURLs(libraries: adsk.cam.ToolLibraries, url: adsk.core.URL):
''' Return the list of libraries URL in the specified library '''
urls: list[str] = []
libs = libraries.childAssetURLs(url)
for lib in libs:
urls.append(lib.toString())
for folder in libraries.childFolderURLs(url):
urls = urls + getLibrariesURLs(libraries, folder)
return urls
I have multiple setups, and I want the new vacuum operations to be added to the start of each setup, not the end.
I've reviewed the Autodesk Fusion 360 API documentation, but I couldn't find a direct solution. If anyone has encountered a similar issue or has suggestions on how to achieve this, your guidance would be greatly appreciated.
Thank you in advance for your time and assistance!