Hello,
I wonder how to create a tool by the help of the API.
It seems to me that the proper way is to generate a json file and import this file with the API. Is there any documetation, open source examples about it? We need to check how much effort it would be to develop an interface from an external tool library software.
Greetings Daniel
Hello,
I wonder how to create a tool by the help of the API.
It seems to me that the proper way is to generate a json file and import this file with the API. Is there any documetation, open source examples about it? We need to check how much effort it would be to develop an interface from an external tool library software.
Greetings Daniel
Hi @daniel.schaefer9P5YP -San.
It was created in a previous test.
Just create a new document and create 3 drill tools.
# Fusion360API Python script
import traceback
import adsk.core as core
import adsk.cam as cam
import json
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
app.documents.add(core.DocumentTypes.FusionDesignDocumentType)
camObj: cam.CAM = get_cam_product()
docToolLib: cam.ToolLibrary = camObj.documentToolLibrary
# (diameter, Tcode))
toolInfos = (
(10.0, 1),
(20.0, 3),
(30.0, 5),
)
for diameter, tCode in toolInfos:
tool: cam.Tool = create_tool_drill(diameter, tCode)
docToolLib.add(tool)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def create_tool_drill(
diameter: float,
tCode: int) -> cam.Tool:
toolDict = {
"BMC": "hss",
"GRADE": "generic",
"description": "",
"geometry": {
"CSP": False,
"DC": 10,
"HAND": True,
"LB": 100,
"LCF": 80,
"NOF": 2,
"NT": 1,
"OAL": 130,
"RE": 0,
"SFDM": 10,
"SIG": 118,
"TP": 0,
"shoulder-length": 90,
"thread-profile-angle": 60,
"tip-diameter": 0,
"tip-length": 0,
"tip-offset": 0
},
"guid": "4de24d46-3bcf-4894-a603-a4974729624a",
"post-process": {
"break-control": False,
"comment": "",
"diameter-offset": 987,
"length-offset": 987,
"live": True,
"manual-tool-change": False,
"number": 987,
"turret": 0
},
"product-id": "",
"product-link": "",
"start-values": {
"presets": [
{
"description": "",
"f_z": 0,
"guid": "fa0617f0-ee91-46cf-b231-36a32b86047f",
"n": 5000,
"name": "test",
"tool-coolant": "flood",
"use-feed-per-revolution": False,
"v_c": 157.07963267948963,
"v_f": 0,
"v_f_leadIn": 0,
"v_f_leadOut": 0,
"v_f_plunge": 1000,
"v_f_ramp": 0,
"v_f_retract": 1000
}
]
},
"type": "drill",
"unit": "millimeters",
"vendor": ""
}
toolDict['geometry']['DC'] = diameter
toolDict['geometry']['LB'] = diameter * 20
toolDict['geometry']['LCF'] = diameter * 5
toolDict['geometry']['OAL'] = diameter * 25
toolDict['geometry']['SFDM'] = diameter
toolDict['geometry']['shoulder-length'] = diameter * 15
toolDict['post-process']['number'] = tCode
toolDict['post-process']['diameter-offset'] = tCode
toolDict['post-process']['length-offset'] = tCode
tool: cam.Tool = cam.Tool.createFromJson(json.dumps(toolDict))
return tool
def get_cam_product() -> cam.CAM:
app: core.Application = core.Application.get()
activete_cam_env()
return app.activeProduct
def activete_cam_env() -> None:
app: core.Application = core.Application.get()
ui: core.UserInterface = app.userInterface
camWS: core.Workspace = ui.workspaces.itemById('CAMEnvironment')
camWS.activate()
I don't know if this will help, as I think if it were actual, it would be done in an external JSON file.
Hi @daniel.schaefer9P5YP -San.
It was created in a previous test.
Just create a new document and create 3 drill tools.
# Fusion360API Python script
import traceback
import adsk.core as core
import adsk.cam as cam
import json
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
app.documents.add(core.DocumentTypes.FusionDesignDocumentType)
camObj: cam.CAM = get_cam_product()
docToolLib: cam.ToolLibrary = camObj.documentToolLibrary
# (diameter, Tcode))
toolInfos = (
(10.0, 1),
(20.0, 3),
(30.0, 5),
)
for diameter, tCode in toolInfos:
tool: cam.Tool = create_tool_drill(diameter, tCode)
docToolLib.add(tool)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def create_tool_drill(
diameter: float,
tCode: int) -> cam.Tool:
toolDict = {
"BMC": "hss",
"GRADE": "generic",
"description": "",
"geometry": {
"CSP": False,
"DC": 10,
"HAND": True,
"LB": 100,
"LCF": 80,
"NOF": 2,
"NT": 1,
"OAL": 130,
"RE": 0,
"SFDM": 10,
"SIG": 118,
"TP": 0,
"shoulder-length": 90,
"thread-profile-angle": 60,
"tip-diameter": 0,
"tip-length": 0,
"tip-offset": 0
},
"guid": "4de24d46-3bcf-4894-a603-a4974729624a",
"post-process": {
"break-control": False,
"comment": "",
"diameter-offset": 987,
"length-offset": 987,
"live": True,
"manual-tool-change": False,
"number": 987,
"turret": 0
},
"product-id": "",
"product-link": "",
"start-values": {
"presets": [
{
"description": "",
"f_z": 0,
"guid": "fa0617f0-ee91-46cf-b231-36a32b86047f",
"n": 5000,
"name": "test",
"tool-coolant": "flood",
"use-feed-per-revolution": False,
"v_c": 157.07963267948963,
"v_f": 0,
"v_f_leadIn": 0,
"v_f_leadOut": 0,
"v_f_plunge": 1000,
"v_f_ramp": 0,
"v_f_retract": 1000
}
]
},
"type": "drill",
"unit": "millimeters",
"vendor": ""
}
toolDict['geometry']['DC'] = diameter
toolDict['geometry']['LB'] = diameter * 20
toolDict['geometry']['LCF'] = diameter * 5
toolDict['geometry']['OAL'] = diameter * 25
toolDict['geometry']['SFDM'] = diameter
toolDict['geometry']['shoulder-length'] = diameter * 15
toolDict['post-process']['number'] = tCode
toolDict['post-process']['diameter-offset'] = tCode
toolDict['post-process']['length-offset'] = tCode
tool: cam.Tool = cam.Tool.createFromJson(json.dumps(toolDict))
return tool
def get_cam_product() -> cam.CAM:
app: core.Application = core.Application.get()
activete_cam_env()
return app.activeProduct
def activete_cam_env() -> None:
app: core.Application = core.Application.get()
ui: core.UserInterface = app.userInterface
camWS: core.Workspace = ui.workspaces.itemById('CAMEnvironment')
camWS.activate()
I don't know if this will help, as I think if it were actual, it would be done in an external JSON file.
Can't find what you're looking for? Ask the community or share your knowledge.