<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calling specific tool database in Script (Python) in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/calling-specific-tool-database-in-script-python/m-p/14100424#M22734</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8630364"&gt;@MarcoNKE&lt;/a&gt;&amp;nbsp;-san.&lt;BR /&gt;&lt;BR /&gt;I was mistaken. Here is a sample that accesses the first tool in this tool library.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 477px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1635016iF166A6AC4C3E4CB7/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
from typing import Optional
import adsk.core as core
import adsk.cam as cam


def run(context: dict) -&amp;gt; None:
    """Entry point for the Fusion360 script.

    Retrieves the first tool from the named library within 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_named_local_library("CustomTools")
        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_named_local_library(libraryName: str) -&amp;gt; Optional[cam.Tool]:
    """Return the first tool from the library matching libraryName within the local library.

    Args:
        libraryName: The name of the library to search for within the local library location.

    Returns:
        The first tool, or None if the library is not found or contains no tools.
    """
    camMgr: cam.CAMManager = cam.CAMManager.get()
    toolLibs: cam.ToolLibraries = camMgr.libraryManager.toolLibraries

    # Local
    rootUrl: core.URL = toolLibs.urlByLocation(
        cam.LibraryLocations.LocalLibraryLocation
    )

    # Custom Tools URL
    targetUrl: core.URL = None
    url: core.URL = None
    for url in toolLibs.childAssetURLs(rootUrl):
        if url.leafName == libraryName:
            targetUrl = url
            break

    if not targetUrl: return None
    
    # Custom Tools ToolLibrary
    targetToolLib: cam.ToolLibrary = toolLibs.toolLibraryAtURL(targetUrl)
    if targetToolLib.count &amp;lt; 1: return None

    # First Tool
    return targetToolLib.item(0)


def dump_tool_info(tool: cam.Tool) -&amp;gt; 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) -&amp;gt; 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)'&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 22 Apr 2026 00:31:46 GMT</pubDate>
    <dc:creator>kandennti</dc:creator>
    <dc:date>2026-04-22T00:31:46Z</dc:date>
    <item>
      <title>Calling specific tool database in Script (Python)</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/calling-specific-tool-database-in-script-python/m-p/14085256#M22705</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i can't find a solid method to call my specific tool library, located in local folder in fusion database, in script code&lt;/P&gt;&lt;P&gt;i tried to use some exemple in API Help in Fusion but it doesn't work&lt;BR /&gt;can you tell me a way to do it as simple as possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2026 10:41:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/calling-specific-tool-database-in-script-python/m-p/14085256#M22705</guid>
      <dc:creator>MarcoNKE</dc:creator>
      <dc:date>2026-04-10T10:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Calling specific tool database in Script (Python)</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/calling-specific-tool-database-in-script-python/m-p/14086544#M22714</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8630364"&gt;@MarcoNKE&lt;/a&gt;&amp;nbsp;-san.&lt;BR /&gt;&lt;BR /&gt;Is this the tool library you were looking for?&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
from typing import Optional
import adsk.core as core
import adsk.cam as cam


def run(context: dict) -&amp;gt; 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() -&amp;gt; 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,
) -&amp;gt; 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 &amp;gt; 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) -&amp;gt; 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) -&amp;gt; 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)'&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 11 Apr 2026 13:53:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/calling-specific-tool-database-in-script-python/m-p/14086544#M22714</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2026-04-11T13:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calling specific tool database in Script (Python)</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/calling-specific-tool-database-in-script-python/m-p/14097734#M22731</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;do i need to copy the whole code into mine?&lt;/P&gt;&lt;P&gt;i tried to do it but nothing happens&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2026 10:05:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/calling-specific-tool-database-in-script-python/m-p/14097734#M22731</guid>
      <dc:creator>MarcoNKE</dc:creator>
      <dc:date>2026-04-20T10:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calling specific tool database in Script (Python)</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/calling-specific-tool-database-in-script-python/m-p/14100424#M22734</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8630364"&gt;@MarcoNKE&lt;/a&gt;&amp;nbsp;-san.&lt;BR /&gt;&lt;BR /&gt;I was mistaken. Here is a sample that accesses the first tool in this tool library.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 477px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1635016iF166A6AC4C3E4CB7/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# Fusion360API Python script

import traceback
from typing import Optional
import adsk.core as core
import adsk.cam as cam


def run(context: dict) -&amp;gt; None:
    """Entry point for the Fusion360 script.

    Retrieves the first tool from the named library within 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_named_local_library("CustomTools")
        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_named_local_library(libraryName: str) -&amp;gt; Optional[cam.Tool]:
    """Return the first tool from the library matching libraryName within the local library.

    Args:
        libraryName: The name of the library to search for within the local library location.

    Returns:
        The first tool, or None if the library is not found or contains no tools.
    """
    camMgr: cam.CAMManager = cam.CAMManager.get()
    toolLibs: cam.ToolLibraries = camMgr.libraryManager.toolLibraries

    # Local
    rootUrl: core.URL = toolLibs.urlByLocation(
        cam.LibraryLocations.LocalLibraryLocation
    )

    # Custom Tools URL
    targetUrl: core.URL = None
    url: core.URL = None
    for url in toolLibs.childAssetURLs(rootUrl):
        if url.leafName == libraryName:
            targetUrl = url
            break

    if not targetUrl: return None
    
    # Custom Tools ToolLibrary
    targetToolLib: cam.ToolLibrary = toolLibs.toolLibraryAtURL(targetUrl)
    if targetToolLib.count &amp;lt; 1: return None

    # First Tool
    return targetToolLib.item(0)


def dump_tool_info(tool: cam.Tool) -&amp;gt; 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) -&amp;gt; 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)'&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 22 Apr 2026 00:31:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/calling-specific-tool-database-in-script-python/m-p/14100424#M22734</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2026-04-22T00:31:46Z</dc:date>
    </item>
  </channel>
</rss>

