-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.py
52 lines (40 loc) · 1.73 KB
/
import.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Author-
# Description-
# import nah
import adsk.core, adsk.fusion
from typing import cast
import json
from .globals.globals import ui, units_manager, active_document, error, print_fusion
from .globals.types.types import Timeline, Feature, Error
from .features.features import set_sketch_data, set_extrude_data
def run(context):
try:
fileDialog = ui.createFileDialog()
fileDialog.title = "Select Timeline JSON File"
fileDialog.filter = "JSON files (*.json)"
if fileDialog.showOpen() != adsk.core.DialogResults.DialogOK:
return
timeline_data: Timeline
with open(fileDialog.filename, "r") as f:
timeline_data = json.load(f)
active_document.name = timeline_data["document_name"]
units_manager.distanceDisplayUnits = timeline_data["units"]
for feature in timeline_data["features"]:
set_feature_data(feature)
print_fusion("Timeline successfully imported")
except Exception as e:
error("Failed to import timeline", e)
def set_feature_data(feature: Feature | Error):
try:
if "error" in feature:
raise Exception("Failed to read feature error data")
if feature["type"] == "adsk::fusion::Sketch": # adsk.fusion.Sketch.classType()
print_fusion(f"Processing sketch: {feature['name']}")
set_sketch_data(feature["details"])
elif feature["type"] == "adsk::fusion::ExtrudeFeature": # adsk.fusion.ExtrudeFeature.classType()
print_fusion(f"Processing extrude: {feature['name']}")
set_extrude_data(feature["details"])
else:
raise Exception("Unknown feature type")
except Exception as e:
error("Failed to process feature", e)