-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFind Mass.py
77 lines (60 loc) · 1.95 KB
/
Find Mass.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Fusion360API Python script
import traceback
import adsk.core as core
import adsk.fusion as fusion
def run(context):
ui: core.UserInterface = None
try:
app: core.Application = core.Application.get()
ui = app.userInterface
msg: str = 'Select Entity'
selFilter: str = 'Bodies,Occurrences,RootComponents'
sel: core.Selection = selectEnt(msg, selFilter)
if not sel:
return
show_physicalProperties(sel.entity)
a=1
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def show_physicalProperties(
entity: core.Base,
):
if not hasattr(entity, 'physicalProperties'):
return
props: fusion.PhysicalProperties = entity.physicalProperties
if hasattr(entity, 'transform2'):
origin, _, _, _ = entity.transform2.getAsCoordinateSystem()
worldXYZ = origin.asArray()
else:
worldXYZ = '-'
infos = [
f'Mass \t\t{round(props.mass)} kg',
f'Volume \t\t{round(props.volume)} cm^3',
f'Density \t\t{round(props.density*1000)} g/cm^3',
f'Area \t\t{round(props.area)} cm^2',
f'World X,Y,Z \t\t{worldXYZ}',
f'CenterOfMass \t{props.centerOfMass.asArray()}',
]
# infos = [
# f'Mass \t\t{props.mass}',
# f'Volume \t\t{props.volume}',
# f'Density \t\t{props.density}',
# f'Area \t\t{props.area}',
# f'World X,Y,Z \t\t{worldXYZ}',
# f'CenterOfMass \t{props.centerOfMass.asArray()}',
# ]
app: core.Application = core.Application.get()
ui: core.UserInterface = app.userInterface
ui.messageBox('\n'.join(infos))
def selectEnt(
msg: str,
filterStr: str
) -> core.Selection:
try:
app: core.Application = core.Application.get()
ui: core.UserInterface = app.userInterface
sel = ui.selectEntity(msg, filterStr)
return sel
except:
return None