Message 1 of 1
Load tools in Python Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
i'm getting started with API so my code could be weird.
here below i'm having an issue with the part of loading library tools in the toolpath operation
it works when it picks the tool called "tool" but it doesn't work when reach the second tool called "tool2"
can you tell me what is wrong with this code?
it works when it picks the tool called "tool" but it doesn't work when reach the second tool called "tool2"
can you tell me what is wrong with this code?
thanks!
import traceback
import adsk.core
import adsk.fusion
import adsk.cam
# Initialize the global variables for the Application and UserInterface objects.
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.activeDocument
cam = adsk.cam.CAM.cast(app.activeProduct)
def run(_context: str😞
try:
# Get the Setups collection.
setups = cam.setups
# Create a SetupsInput object to define a milling setup.
setupInput = setups.createInput(
adsk.cam.OperationTypes.MillingOperation)
# Specify the first body in the model as the model geometry.
camOcc = cam.designRootOccurrence
setupInput.models = [camOcc.bRepBodies[0]]
# Set the origin to be at the top center of the model box.
originParam = setupInput.parameters.itemByName('wcs_origin_mode')
choiceVal: adsk.cam.ChoiceParameterValue = originParam.value
choiceVal.value = 'modelPoint'
originPoint = setupInput.parameters.itemByName('wcs_origin_boxPoint')
choiceVal: adsk.cam.ChoiceParameterValue = originPoint.value
choiceVal.value = 'top center'
# progNameParam = setup
# progNameParam.expres
setupInput.name = "Fase1"
setup = setups.add(setupInput)
# Get a reference to the CAMManager object.
camMgr = adsk.cam.CAMManager.get()
# Get the ToolLibraries object.
toolLibs = camMgr.libraryManager.toolLibraries
# Get the URL for the local libraries.
localLibLocationURL = toolLibs.urlByLocation(
adsk.cam.LibraryLocations.LocalLibraryLocation)
# Get the URL of the folder, which will be for the "CustomTools" folder.
f360FolderURLs = toolLibs.childFolderURLs(localLibLocationURL)
customToolsFolderURL = f360FolderURLs[0]
# Get the "CustomMilling" library.
f360LibraryURLs = toolLibs.childAssetURLs(customToolsFolderURL)
toolLib = None
for libURL in f360LibraryURLs:
if 'TestTool' in libURL.leafName:
toolLib = toolLibs.toolLibraryAtURL(libURL)
all_tools = list(toolLib)
# Find a specific tool.
for tool in all_tools:
if tool.parameters.itemByName('tool_description').value == 'Ø 50 R0,8 H150 kennametal (m)':
return tool
# Creazione lavorazioni 2D
opInput = setup.operations.createInput('face')
opInput.tool = tool
opInput.displayName = "Spiana Z0"
direction = opInput.parameters.itemByName(
"direction").expression = "'both ways'"
opInput.parameters.itemByName("passExtension").expression = '15 mm'
opInput.parameters.itemByName("doMultipleDepths").expression = 'true'
opInput.parameters.itemByName('maximumStepdown').expression = '0.5 mm'
op = setup.operations.add(opInput)
##################### Generate operations ####################
cam.generateToolpath(op)
# Cerca il secondo utensile
tool2 = None
for t in all_tools:
if t.parameters.itemByName('tool_description').value == '12 PIANA L40':
tool2 = t
break
# Creazione lavorazioni 2D
opInput2 = setup.operations.createInput('pocket2d')
opInput2.tool = tool2
opInput2.displayName = "Tasca interna"
opInput2.parameters.itemByName("doMultipleDepths").expression = 'true'
opInput2.parameters.itemByName('maximumStepdown').expression = '0.5 mm'
op2 = setup.operations.add(opInput2)
##################### Generate operations ####################
cam.generateToolpath(op2)
except: # pylint:disable=bare-except
# Write the error message to the TEXT COMMANDS window.
ui.inputBox('Failed:\n{}'.format(traceback.format_exc()), 'Error')
app.log(f'Failed:\n{traceback.format_exc()}')