-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInspect_Crv.py
More file actions
142 lines (107 loc) · 3.21 KB
/
Inspect_Crv.py
File metadata and controls
142 lines (107 loc) · 3.21 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""
Report the curve type of a SketchCurve or BrepEdge and additional info
for NURBS curves.
"""
"""
220320: Created.
220419: Modified printed output.
"""
import adsk.core as ac
import adsk.fusion as af
import traceback
_app = ac.Application.get()
_ui = _app.userInterface
def log(printMe): _app.log(str(printMe))
def getKnotInfo(knots):
"""
Returns a string.
"""
iK = 0
ts_Unique = []
ms = []
iKsPerM = []
deltas_ts = []
while iK < len(knots):
k = knots[iK]
ts_Unique.append(k)
m = knots.count(k)
ms.append(m)
iKsPerM.append(range(iK, iK+m))
if iK > 0: deltas_ts.append(ts_Unique[-1]-ts_Unique[-2])
iK += m
s = f"Count:{len(knots)}"
s += f" SpanCt:{len(ms)-1}"
s += f" Multiplicities: {','.join(str(i) for i in ms)}"
# Record knot parameters to at least 3 decimal places but more if
# required to display all unique values.
for dec_plcs in range(15, 3-1, -1):
LIST = [" {: .{}f}".format(t, dec_plcs) for t in ts_Unique]
if len(set(LIST)) != len(ts_Unique):
dec_plcs += 1
break
s += "\n "
zipped = zip(iKsPerM, ts_Unique)
s_JoinUs = []
for idxs, t in zipped:
if len(idxs) == 1:
s_JoinUs.append(f"[{idxs[0]}]{t:.{dec_plcs}f}")#.format(t, dec_plcs, idxs[0]))
else:
s_JoinUs.append(f"[{idxs[0]},{idxs[-1]}]{t:.{dec_plcs}f}")#.format(t, dec_plcs, idxs[0], idxs[-1]))
s += " ".join(s_JoinUs)
if abs(min(deltas_ts) - max(deltas_ts)) <= 10.0**(-dec_plcs):
s += " Deltas:{0:.{1}f}".format(
deltas_ts[0], dec_plcs)
else:
s += " DeltaRange:[{0:.{2}f},{1:.{2}f}]".format(
min(deltas_ts), max(deltas_ts), dec_plcs)
return s
def getNurbsCrvInfo(nc: ac.NurbsCurve3D):
(
bSuccess,
controlPoints,
degree,
knots,
isRational_getData,
weights,
isPeriodic,
) = nc.getData()
if not bSuccess: return
s = f"\ndegree: {degree}"
s += f"\nCP count: {len(controlPoints)}"
s += f"\nknots: {getKnotInfo(knots)}"
# s += f"\nisRational (per property): {nc.isRational}"
s += f"\nisRational: {isRational_getData}"
s += f"\nweights: {weights if weights else None}"
s += f"\nisPeriodic: {isPeriodic}"
return s
def getCrvInfo(sel: ac.Selection):
ent = sel.entity
s = '\n'
s += f"Selected: {ent.objectType[14:]}"
if isinstance(ent, af.BRepEdge):
crv = ent.geometry
elif isinstance(ent, af.SketchCurve):
crv = ent.geometry
else:
raise ValueError("Wrong selection entity type passed to printInfo. Try again.")
s += f"\nGeometry: {crv.objectType[12:]}"
if isinstance(crv, (ac.NurbsCurve3D)):
s += getNurbsCrvInfo(crv)
return s
def main():
while True:
try:
sel = _ui.selectEntity(
"Select a sketch curve or brep edge",
filter="Edges,SketchCurves")
except:
return
sInfo = getCrvInfo(sel)
log(sInfo)
def run(context):
try:
main()
except:
log(f"\nFailed:\n{traceback.format_exc()}")
finally:
log("\nEnd of script.")