Hello everyone
This topic is related to the two preor ones How to classify unsorted levels name and Levels with python in which I prefer to use Python to place my family istances in their corresponding levels, so I’ve two cases relating to my total height H_Total in which I should place either one (Fut1) or both of them (Fut1 and Fut2) according the Heigh levels H_Shaft and H_2 by taking the following condition into consideration:
If H_Total % H_Shaft = 0 (So only the instance Fut1 is duplicated to the last level)
else H_2 ≠ 0 (so the instance Fut2 should be placed to the last level)
(Note: H_2 is the remaing Height from the made division H_Total / H_Shaft )
-
Since each instanes is related to its below level, in the case where H_2 ≠ 0 I always end up with one extra instance (Fut1)
-
In addition to duplicating , I should rotate the even ones by 180 degrees as shown in the reference below but they become miss placed because their point location is not in the center, so How can I set it to the center to avoid this issue
Please chek my script , dyn file and Revit file below
import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import *
R_exter_Shaft = IN[0]
Thk_Shaft = IN[1]
R_inter_Shaft = R_exter_Shaft - Thk_Shaft
H_Total = IN[2]
H_Shaft = IN[3]
Thk_Slab = IN[4]
H_1 = H_Shaft - Thk_Slab
Family_Cat = IN[5]
Family_Path = IN[6]
Material = IN[7]
Family1_name = 'Shaft1'
Family2_name = 'Shaft2'
Long_Trape = 0.8
angle_Trape = math.degrees(math.atan((Long_Trape/2) / R_inter_Shaft))
# Set Levels_List
if H_Total % H_Shaft > 0:
H_Level = [ i * H_Shaft + H_Shaft for i in range(0, int(H_Total //H_Shaft))]
#compute the remaining Height H_2 from the divison (H_Total / H_Shaft)
H_2 = H_Total - H_Level[-1]
else:
H_Level = [ i * H_Shaft + H_Shaft for i in range(0, int(H_Total //H_Shaft) - 1)]
H_2 = 0
#H_Level.insert(len(H_Level),H_Total)
H_Level.insert(0,0)
#Shaft1_Profil
lst1 = []
Pt1 = Point.ByCoordinates( R_exter_Shaft, 0, -Thk_Slab)
lst1.append(Pt1)
Pt2 = Point.ByCoordinates( R_exter_Shaft, 0, H_1)
lst1.append(Pt2)
Pt3 = Point.ByCoordinates( R_inter_Shaft , 0, H_1)
lst1.append(Pt3)
Pt4 = Point.ByCoordinates( R_inter_Shaft , 0, -Thk_Slab)
lst1.append(Pt4)
vector = Vector.ByCoordinates(0, 0, 1)
Center_pt = Point.ByCoordinates(0, 0, 0)
Shaft1_Profil = Polygon.ByPoints(lst1)
Shaft1 = Solid.ByRevolve(Shaft1_Profil, Center_pt, vector, 0, 360)
#Shaft2_Profil
lst2 = []
Pt_1 = Point.ByCoordinates( R_exter_Shaft, 0, -Thk_Slab)
lst2.append(Pt_1)
Pt_2 = Point.ByCoordinates( R_exter_Shaft, 0, H_2)
lst2.append(Pt_2)
Pt_3 = Point.ByCoordinates( R_inter_Shaft , 0, H_2)
lst2.append(Pt_3)
Pt_4 = Point.ByCoordinates( R_inter_Shaft , 0, -Thk_Slab)
lst2.append(Pt_4)
vector = Vector.ByCoordinates(0, 0, 1)
Center_pt = Point.ByCoordinates(0, 0, 0)
Shaft2_Profil = Polygon.ByPoints(lst2)
Shaft2 = Solid.ByRevolve(Shaft2_Profil, Center_pt, vector, 0, 360)
Slab_Profil = Surface.ByPatch(Circle.ByCenterPointRadius(Center_pt, R_inter_Shaft ))
Slab = Surface.Thicken(Slab_Profil, -Thk_Slab, bool(0))
# opening profil to be subtract from the slab
Trape_arc = Arc.ByCenterPointRadiusAngle(Center_pt, R_inter_Shaft, -angle_Trape, angle_Trape, vector )
Pt1 = Trape_arc.StartPoint
Pt2 = Trape_arc.EndPoint
Pt3 = Pt1.Translate(-Long_Trape)
Pt4 = Pt2.Translate(-Long_Trape)
Line1 = Line.ByStartPointEndPoint(Pt3, Pt4)
Line2 = Line.ByStartPointEndPoint(Pt3, Pt1)
Line3 = Line.ByStartPointEndPoint(Pt4, Pt2)
Profil_Trape = Surface.ByPatch(PolyCurve.ByJoinedCurves([Line1, Line2, Trape_arc, Line3]))
Trape = Surface.Thicken(Profil_Trape, Thk_Slab, bool(0))
Finale_Slab = Solid.Difference(Slab, Trape)
# Shaft1 geometry and Family Type
lst3 = [Shaft1, Finale_Slab]
Final_Shaft1 = Solid.ByUnion(lst3)
Final_Shaft1 = Geometry.Scale(Final_Shaft1, 0.3048)
Final_Shaft1 = FamilyType.ByGeometry(Final_Shaft1, Family1_name, Family_Cat, Family_Path, Material, 'a')
# Shaft2 geometry and Family Type
lst4 = [Shaft2, Finale_Slab]
Final_Shaft2 = Solid.ByUnion(lst4)
Final_Shaft2 = Geometry.Scale(Final_Shaft2, 0.3048)
Final_Shaft2 = FamilyType.ByGeometry(Final_Shaft2, Family2_name, Family_Cat, Family_Path, Material, 'a')
# create Revit Levels
k = 0
Niv = []
for i in H_Level:
k += 1
Lev = Level.ByElevationAndName(i, 'Niveau ' + str(k))
Niv.append(Lev)
print(Lev)
H_Level.sort(reverse=True)
#create and place family Instances Fut1 and Fut2 in their corresponding levels
Fut = []
for i, j in zip(Niv, H_Level):
Fut1 = FamilyInstance.ByPointAndLevel(Final_Shaft1, Point.ByCoordinates(-R_exter_Shaft, -R_exter_Shaft, 0), i )
H_offset = j
print(Fut1)
Fut.append(Fut1)
if H_offset < H_Shaft:
Fut2 = FamilyInstance.ByPointAndLevel(Final_Shaft2, Point.ByCoordinates(-R_exter_Shaft, -R_exter_Shaft, 0), i )
print(Fut2)
Fut.append(Fut2)
Fut = [FamilyInstance.SetRotation(i, 180) for count, i in enumerate(Fut) if count % 2 == 1]
OUT = Fut
here an exemple what I’m looking for
Shaft_python.dyn (25.1 KB)
Shaft_test.rvt (3.5 MB)
Thanks.