たまーにしか使わない上にタイトル通り面倒だから書いたのですが、できてくる xml ファイルの内容、ネジ周りの数字が全く信用なりません。
しかし、光造形プリンタで造形してみる機会があって、Φ62mmでなんとかなった*1から、「もしかしたら役に立つ人もいるかも」と思って公開してみました。
動かなかったらご愛嬌、できたファイルの内容が間違っていたらご容赦いただければ。
# -*- coding: utf-8 -*- # ネジゲージドットコム(http://www.nejigauge.com/tec8.html) # JIS B7111-1975 # と # fusion360 ISOMetricprofile.xml # を参考にして作成した私家版 import glob import os import re import xml.dom.minidom as md import xml.etree.ElementTree as et def main(): root = et.Element('ThreadType') tree = et.ElementTree(element=root) Name = et.SubElement(root, 'Name') Name.text = 'Camera Lens Filter Metric Threads (JIS B7111-1975) Private Edition' CustomName = et.SubElement(root, 'CustomName') CustomName.text = 'CameraLensFilterMetricPE' Unit = et.SubElement(root, 'Unit') Unit.text = 'mm' Angle = et.SubElement(root, 'Angle') Angle.text = '60' # ないとエラーを起こすので、適当な数値を入れている SortOrder = et.SubElement(root, 'SortOrder') SortOrder.text = '100' threads_list = [13.5, 16.5, 19.5, 22.5, 25.5, 27, 30.5, 34, 35.5, 37.5, 40.5, 43, 46, 49, 52, 55, 58, 62, 67, 72, 77, 82, 86, 95] for thread_diameter in threads_list: if thread_diameter<=40.5: threadsize = 0.5 kousa = 0.1 ex_ma = (13.500 - 13.480) + kousa / 2 ex_p = (13.500 - 13.155) + kousa / 2 ex_mi = (13.500 - 12.829) + kousa / 2 in_p = (13.500 - 13.290) + 0.115 / 2 in_mi = (13.500 - 13.099) + 0.14 / 2 hma = thread_diameter + 0.086 elif thread_diameter>=86: threadsize = 1 kousa = 0.145 ex_ma = (95.000 - 94.960) + kousa / 2 ex_p = (95.000 - 94.310) + kousa / 2 ex_mi = (95.000 - 93.662) + kousa / 2 in_p = (95.000 - 94.525) + 0.175 / 2 in_mi = (95.000 - 94.122) + 0.205 / 2 hma = thread_diameter + 0.147 else: threadsize = 0.75 kousa = 0.12 ex_ma = (82.000 - 81.970) + kousa / 2 ex_p = (82.000 - 81.483) + kousa / 2 ex_mi = (82.000 - 80.998) + kousa / 2 in_p = (82.000 - 81.653) + 0.140 / 2 in_mi = (82.000 - 81.358) + 0.170 / 2 hma = thread_diameter + 0.12 gma = thread_diameter - ex_ma gp = thread_diameter - ex_p gmi = thread_diameter - ex_mi hp = thread_diameter - in_p hmi = thread_diameter - in_mi tap = thread_diameter - threadsize ThreadSize = et.SubElement(root, 'ThreadSize') Size = et.SubElement(ThreadSize, 'Size') Size.text = str(thread_diameter) Designation= et.SubElement(ThreadSize, 'Designation') ThreadDesignation = et.SubElement(Designation, 'ThreadDesignation') ThreadDesignation.text = f'M{thread_diameter:2.1f}x{threadsize:1.1f}' CTD = et.SubElement(Designation, 'CTD') CTD.text = f'M{thread_diameter:2.1f}x{threadsize:1.1f}' Pitch = et.SubElement(Designation, 'Pitch') Pitch.text = f'{threadsize:1.1f}' Thread = et.SubElement(Designation, 'Thread') Gender = et.SubElement(Thread, 'Gender') Gender.text = 'external' # ないとエラーを起こすので便宜的に入れている Class = et.SubElement(Thread, 'Class') Class.text = '6g' MajorDia = et.SubElement(Thread, 'MajorDia') MajorDia.text = f'{gma:2.4f}' PitchDia = et.SubElement(Thread, 'PitchDia') PitchDia.text = f'{gp:2.4f}' MinorDia = et.SubElement(Thread, 'MinorDia') MinorDia.text = f'{gmi:2.4f}' Thread = et.SubElement(Designation, 'Thread') Gender = et.SubElement(Thread, 'Gender') Gender.text = 'internal' # ないとエラーを起こすので便宜的に入れている Class = et.SubElement(Thread, 'Class') Class.text = '6H' MajorDia = et.SubElement(Thread, 'MajorDia') MajorDia.text = f'{hma:2.4f}' PitchDia = et.SubElement(Thread, 'PitchDia') PitchDia.text = f'{hp:2.4f}' MinorDia = et.SubElement(Thread, 'MinorDia') MinorDia.text = f'{hmi:2.4f}' TapDrill = et.SubElement(Thread, 'TapDrill') TapDrill.text = f'{tap:2.2f}' document = md.parseString(et.tostring(root, 'utf-8')) # windows10 # ディレクトリの path のリストを作成 pathlists = [i for i in glob.glob(os.path.expanduser('~\\AppData\\Local\\Autodesk\\webdeploy\\production\\*\\Fusion\\Server\\Fusion\\Configuration\\ThreadData'))] # ディレクトリの作成時間のリストを作成 pathlists_time = [os.path.getctime(pathlist) for pathlist in pathlists] # 2つのリストから作成時間の一番新しいディレクトリの path を求める path = pathlists[pathlists_time.index(max(pathlists_time))] # OSX 未確認にて御免 #path = '/Applications/Fusion360.app/Contents/Libraries/Applications/Fusion/Fusion/Server/Fusion/Configuration/ThreadData/' file_name = 'CameraLensFilterMetricThreadsPE.xml' path_to_file = os.path.join(path, file_name) def write_xml(): file = open(path_to_file, 'w') document.writexml(file, encoding='utf-8', newl='\n', indent='', addindent=' ') file.close() if not os.path.isfile(path_to_file): write_xml() if not os.path.isfile(path_to_file): write_xml() if __name__ == '__main__': main()
*1:いやいや入った