時間が無いので、これです。
# 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) # CAMの取得 camObj: cam.CAM = get_cam_product() # ドキュメントのツールライブラリ docToolLib: cam.ToolLibrary = camObj.documentToolLibrary # 作るドリル情報 # set(set(工具半径, Tcode)) toolInfos = ( (5.0, 1), (10.0, 3), (15.0, 5), ) # ドリルを作る for radius, tCode in toolInfos: tool: cam.Tool = create_tool_drill(radius, tCode) docToolLib.add(tool) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def create_tool_drill( radius: float, tCode: int ) -> cam.Tool: ''' ドリル作成 ''' diameter = radius * 2 sorth = '{"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": "\u65e2\u5b9a\u306e\u30d7\u30ea\u30bb\u30c3\u30c8", "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 = json.loads(sorth) # toolDict['geometry']['CSP'] toolDict['geometry']['DC'] = diameter #直径 # toolDict['geometry']['HAND'] toolDict['geometry']['LB'] = diameter * 20 #ホルダー下 toolDict['geometry']['LCF'] = diameter * 5 #刃長 # toolDict['geometry']['NOF'] # toolDict['geometry']['NT'] toolDict['geometry']['OAL'] = diameter * 25 #全長 # toolDict['geometry']['RE'] toolDict['geometry']['SFDM'] = diameter #軸直径 # toolDict['geometry']['SIG'] # toolDict['geometry']['TP'] toolDict['geometry']['shoulder-length'] = diameter * 15 #首下 # toolDict['geometry']['thread-profile-angle'] # toolDict['geometry']['tip-diameter'] # toolDict['geometry']['tip-length'] # toolDict['geometry']['tip-offset'] 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: ''' CAMの取得 ''' app: core.Application = core.Application.get() activete_cam_env() return app.activeProduct def activete_cam_env() -> None: ''' CAMアクティブ ''' app: core.Application = core.Application.get() ui: core.UserInterface = app.userInterface camWS: core.Workspace = ui.workspaces.itemById('CAMEnvironment') camWS.activate()
恐らく工具は正攻法だとJsonでしか作れ無さそうなのですが、逆に考えれば
Jsonで作れちゃいます。
スクリプトを実行すると、新たなドキュメントを作成し、
ドキュメントのツールライブラリに工具を作ります。
そこ、工具径に対して工具長が異常だとか気にしない!
切削条件とかも恐らく変更可能なのですが、上記のスクリプトは
Jsonを修正して工具を作っています。
Jsonのキーが省略され過ぎていて、何の項目か?が分からない・・・。
本当は、Toolオブジェクトのパラメータで変更したいのですが、
ちょっと試した感じだと変更されなかったのですが、試し足りない
可能性あり。