Last active
January 25, 2022 12:36
-
-
Save moyashi/642300e7b423961c26a0888515eb8709 to your computer and use it in GitHub Desktop.
Fusion360でファイルを開こうとしてエラー「ダウンロードしたファイルが見つかりません。考えられるファイルパス: 」が出た後で実行すると開けるようになることもあるスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Author-moyashi | |
# Fusion360において日本語交じりのファイルを作ると発生するエラー「ダウンロードしたファイルが見つかりません。考えられるファイルパス:」に対処するFusion360用Pythonスクリプト | |
# エラーが出たらこれを実行するとファイル名が修正されて開けるようになる(こともある) | |
# 「ツール」>「アドイン」>「スクリプトとアドイン」>「スクリプト」>「作成」で新規スクリプトを作り、コピペして登録。 | |
# Shift + Sで「スクリプトとアドイン」のダイアログが表示できるので、そこから実行が楽。 | |
import adsk.core, traceback | |
import os, sys | |
from pathlib import Path | |
import xml.etree.ElementTree as ET | |
def dumpMsg(msg :str): | |
adsk.core.Application.get().userInterface.palettes.itemById('TextCommands').writeText(str(msg)) | |
def run(context): | |
# 「XXXXXXX」の部分は自分のパスに書き換える | |
fpath = "/Users/XXXXXXX/Library/Application Support/Autodesk/Autodesk Fusion 360/XXXXXXX/W.login/F/" | |
app = adsk.core.Application.get() | |
ui = app.userInterface | |
os.chdir(fpath) | |
p = Path(".") | |
for f in p.glob("*._xx"): | |
tree = ET.parse(f) | |
root = tree.getroot() | |
metadata = root.findall('WIPFileMetaData')[0] | |
fs = metadata.findall('FileSize')[0].attrib['Bytes'] | |
fn = metadata.findall('DesignFilePath')[0].text | |
if (Path(fn).exists() == False): | |
for fl in p.glob("*"): | |
if (fl.stat().st_size == int(fs)): | |
fl.rename(Path(fn).name) | |
ui.messageBox("ファイル" + fl.name + "を" + Path(fn).name + "にリネームしました") | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment