Hi @MarcoNKE -san.
Is this the tool library you were looking for?
# Fusion360API Python script
import traceback
from typing import Optional
import adsk.core as core
import adsk.cam as cam
def run(context: dict) -> None:
"""Entry point for the Fusion360 script.
Retrieves the first tool found under the local tool library
and prints its representative parameters to the debug console.
"""
ui: Optional[core.UserInterface] = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
tool: Optional[cam.Tool] = get_first_tool_from_local_library()
if tool:
dump_tool_info(tool)
else:
print('No tool found in the local library.')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def get_first_tool_from_local_library() -> Optional[cam.Tool]:
"""Return the first tool found under the local tool library.
Returns:
The first tool, or None if no tool is found.
"""
camMgr: cam.CAMManager = cam.CAMManager.get()
toolLibs: cam.ToolLibraries = camMgr.libraryManager.toolLibraries
rootUrl: core.URL = toolLibs.urlByLocation(
cam.LibraryLocations.LocalLibraryLocation
)
return _find_first_tool(toolLibs, rootUrl)
def _find_first_tool(
toolLibs: cam.ToolLibraries,
url: core.URL,
) -> Optional[cam.Tool]:
"""Recursively search under the given URL and return the first tool.
Args:
toolLibs: The tool libraries manager.
url: The folder URL to start searching from.
Returns:
The first tool, or None if no tool is found.
"""
for assetUrl in toolLibs.childAssetURLs(url):
toolLib: cam.ToolLibrary = toolLibs.toolLibraryAtURL(assetUrl)
if toolLib and toolLib.count > 0:
return toolLib.item(0)
for folderUrl in toolLibs.childFolderURLs(url):
found: Optional[cam.Tool] = _find_first_tool(toolLibs, folderUrl)
if found:
return found
return None
def dump_tool_info(tool: cam.Tool) -> None:
"""Print representative parameters of a tool to the debug console.
Args:
tool: The tool whose information will be printed.
"""
names: list[str] = [
'tool_description',
'tool_number',
'tool_type',
'tool_diameter',
'tool_numberOfFlutes',
'tool_material',
'tool_vendor',
'tool_productId',
]
for name in names:
prm: Optional[cam.CAMParameter] = tool.parameters.itemByName(name)
if prm:
print(f'{name}: {_format_param_value(prm)}')
else:
print(f'{name}: (not set)')
def _format_param_value(prm: cam.CAMParameter) -> str:
"""Return the value of a CAM parameter as a string.
Numeric parameters are read via ``prm.value.value``, while
string parameters are read via ``prm.expression``.
Args:
prm: The CAM parameter to read.
Returns:
The string representation of the value, or ``'(empty)'`` if
it cannot be retrieved.
"""
try:
v = prm.value.value
if v is not None and v != '':
return str(v)
except:
pass
try:
expr: str = prm.expression
if expr:
return expr.strip("'\"")
except:
pass
return '(empty)'