-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathspb_Brep_Face_count.py
More file actions
89 lines (66 loc) · 2.44 KB
/
spb_Brep_Face_count.py
File metadata and controls
89 lines (66 loc) · 2.44 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
"""
"""
#! python 2 Must be on a line number less than 32.
from __future__ import absolute_import, division, print_function, unicode_literals
"""
181628: Created.
191025: Now accepts invalid breps.
210319: Now also reports surface count.
250130: Now, input of Nothing will select all normal breps.
Refactored.
"""
import Rhino
import Rhino.DocObjects as rd
import Rhino.Geometry as rg
import scriptcontext as sc
def _getAllNormalBreps():
oes = rd.ObjectEnumeratorSettings()
oes.LockedObjects = False # Default is True.
oes.ObjectTypeFilter = rd.ObjectType.Brep
return list(sc.doc.Objects.GetObjectList(oes))
def main():
res, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects(
"Select breps <All normal>",
acceptNothing=True,
filter=rd.ObjectType.Brep)
if res == Rhino.Commands.Result.Cancel: return
rdBs = [_.Object() for _ in objrefs] if objrefs else _getAllNormalBreps()
iCt_Fs_All = iCt_Ss_All = iCt_Bs = 0
iCt_Bs_Input = len(rdBs)
bReportEveryBrep = False
if iCt_Bs_Input > 10:
s = "More than 10 breps are selected, so only total faces of all,"
s += " not individual brep counts, is reported."
print(s)
elif iCt_Bs_Input > 1 and iCt_Bs_Input <= 10:
bReportEveryBrep = True
for rdB in rdBs:
rgB = rdB.BrepGeometry
iCt_Fs = rgB.Faces.Count
iCt_Ss = rgB.Surfaces.Count
if iCt_Fs is None:
s = "Faces were not obtained from {}.".format(rdB.Id)
s += " Check validity of brep."
print(s)
continue
iCt_Fs_All += iCt_Fs
iCt_Ss_All += iCt_Ss
iCt_Bs += 1
if bReportEveryBrep:
s = "{} faces in {}, ".format(
iCt_Fs, rdB.Id)
if iCt_Ss != iCt_Fs:
s += "but {} surfaces are in brep.".format(iCt_Ss)
else:
s += "and surface count is the same."
print(s)
if iCt_Fs_All > 0:
s = "{} faces in {}, ".format(
iCt_Fs_All,
("{} breps".format(iCt_Bs) if bool(iCt_Bs-1) else "brep"))
if iCt_Ss_All != iCt_Fs_All:
s += "but {} surfaces are in brep.".format(iCt_Ss_All)
else:
s += "and surface count is the same."
print(s)
if __name__ == '__main__': main()