#Finds the BuildingName in the first part of the filename
lstSplit =
bygn =
try:
rvt_file_name = doc.Title
except:
rvt_file_name = “Unkown” # file may not be saved
lstSplit = rvt_file_name.Split(“_”)
bygn = lstSplit[0].ToString()
value =
viewFamilyTypes = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()
vftLst =
for vf in viewFamilyTypes:
if vf.LookupParameter(“Type Name”).AsString() == secTypeName:
vftLst.append(vf.Id)
Determine section box
for i in wall:
idx.append(wall.index(i))
lc = i.Location
line = lc.Curve
p = line.GetEndPoint(0)
q = line.GetEndPoint(1)
v = q - p
bb = i.get_BoundingBox(None)
minZ = bb.Min.Z
maxZ = bb.Max.Z
w = v.GetLength()
h = maxZ - minZ
d = i.WallType.Width
offset = 100 / 304.8
offsetHeight = 200 / 304.8
offsetFront = 1 / 304.8
min = XYZ(-0.5*w - offset, - offset, - offsetFront - 0.5*d)
max = XYZ(0.5*w + offset, h + offsetHeight, offsetFront + 0.5*d)
midpoint = p + 0.5*v
walldir = v.Normalize()
up = XYZ.BasisZ
viewdir = walldir.CrossProduct(up)
t = Transform.Identity
t.Origin = midpoint
t.BasisX = walldir
t.BasisY = up
t.BasisZ = viewdir
sectionBox = BoundingBoxXYZ()
sectionBox.Transform = t
sectionBox.Min = min
sectionBox.Max = max
#Base Constraint value
DB = i.GetParameters("Base Constraint")
for y in DB:
value = y.AsValueString()
TransactionManager.Instance.EnsureInTransaction(doc)
newSection = ViewSection.CreateSection(doc, vftLst[0], sectionBox)
newParameterValue = newSection.LookupParameter('View Name')
newParameterValue.Set(bygn +"_"+ value +"_"+ wall.index(i).ToString())
sectionLst.append(newSection)
test = idx[-1] +1
TransactionManager.Instance.TransactionTaskDone()
OUT = test.ToString() + " sectionviews have been created", sectionLst
Can you re-paste your code and make sure the whole thing gets formatted this time? That’ll make it much easier to read.
According to the output, you created all those new sections. Have you confirmed they aren’t in the project? Have you searched for them in the browser? Confirmed sections are visible and within the scope of your views?
If it helps, when i try to run the script and have a view list scheduel open in Revit i can see the section views being created in a flash then they are gone
Your code works for me. Are you sure you don’t get any Revit errors after running and the elements don’t exist? Can you select any of the sections by Id?
I have not been able to find the solution on my end, but when i ran it on the same project on a different computer it worked just fine, so my guess is i somehow have tainted the model through testing.