-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwallsfrombreps.py
71 lines (62 loc) · 2.45 KB
/
wallsfrombreps.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
import trkRhinoPy as trp
import Rhino.Geometry as rg
import scriptcontext as sc
import rhinoscriptsyntax as rs
# import Rhino
tol=sc.doc.ModelAbsoluteTolerance
trans=rg.CurveOffsetCornerStyle.Sharp
objs = rs.GetObjects('select polysrfs', rs.filter.polysurface, preselect=True)
wallthickness = rs.GetReal('wall thickness', number=200)
levels = sc.sticky["lvldict"]
def alignNormal(id):
obj = sc.doc.Objects.Find(id)
geo = obj.Geometry
# print geo
# srf = rs.coercesurface(id)
# print srf
srf = geo.Faces[0]
# srf = face.UnderlyingSurface()
# print srf
normal = srf.NormalAt(srf.Domain(0).Mid, srf.Domain(1).Mid)
# print normal
# print normal.Z
if normal.Z < 0:
geo.Flip()
sc.doc.Objects.Replace(id, geo)
return id
# return rs.FlipSurface(id, True)
else:
return id
def wallByBrep(objid, height, offout, offin):
# height = float(rs.GetUserText(objid, 'height'))
obj = sc.doc.Objects.Find(objid).Geometry
facecrvs = []
curves = obj.DuplicateNakedEdgeCurves(1, 1)
curves = rg.Curve.JoinCurves(curves, tol)
curves = curves[0].Offset(rs.WorldXYPlane(),offout,tol,trans)
facecrvs.append(curves[0])
brepfaces=[face.DuplicateFace(False) for face in obj.Faces]
for x in brepfaces:
crvs = x.DuplicateEdgeCurves()
crvs = rg.Curve.JoinCurves(crvs, tol)
crvs = crvs[0].Offset(rs.WorldXYPlane(),offin,tol,trans)
# pln = rs.CurvePlane(crvID)
facecrvs.append(crvs[0])
plnrsrf = rg.Brep.CreatePlanarBreps(facecrvs, tol)
# rails = [rg.LineCurve(srf.Faces[0].PointAt(0,0), srf.Faces[0].PointAt(0,0) + rg.Point3d(0,0,height)) for srf in plnrsrf]
solids = [rg.BrepFace.CreateExtrusion(srf.Faces[0], rg.LineCurve(srf.Faces[0].PointAt(0,0), srf.Faces[0].PointAt(0,0) + rg.Point3d(0,0,height)), True) for srf in plnrsrf]
solidsrc = [sc.doc.Objects.AddBrep(c) for c in solids]
# railsrc = [sc.doc.Objects.AddCurve(c) for c in rails]
# facecrvsrc = [sc.doc.Objects.AddCurve(c) for c in facecrvs]
# rc = [sc.doc.Objects.AddBrep(c) for c in plnrsrf]
return solidsrc
def func(obj):
obj = alignNormal(obj)
width = wallthickness/2
lvl = levels[rs.GetUserText(obj, 'level')]
height = float(lvl['height'])
# height = float(rs.GetUserText(obj, "height"))
# lvl = rs.GetUserText(obj, 'level')
walls = wallByBrep(obj, height, width, -width)
[trp.copySourceData(wall, obj) for wall in walls]
map(func, objs)