I’m working on python scirpt (in Dynamo) which create section view of the wall. Because I have just basic knowledge of python and c#, I used @jeremytammik expierence and just try to translate his code from the website Create Section View Parallel to Wall.
At the first look it works, but the problem starts when the walls have different Base Constraint then level 0. So, for example if bottom of the wall is level +1 and top level +2, the crop region of the section is moved by one level up:
I’ve checked all steps one by one and found nothing unusal. All values from the bounding box look right, have no idea why on upper levels crop region does not match to the wall.
Is there anyone who know where could I look the problem?
My code:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
wall = UnwrapElement(IN[0])
secTypeName = IN[1]
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
lc = wall.Location
line = lc.Curve
p = line.GetEndPoint(0)
q = line.GetEndPoint(1)
v = q - p
bb = wall.get_BoundingBox(None)
minZ = bb.Min.Z
maxZ = bb.Max.Z
w = v.GetLength()
h = maxZ - minZ
d = wall.WallType.Width
offset = 100 / 304.8
min = XYZ(-0.5*w - offset, minZ - offset, - offset - 0.5*d)
max = XYZ(0.5*w + offset, maxZ + offset, offset + 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
TransactionManager.Instance.EnsureInTransaction(doc)
newSection = ViewSection.CreateSection(doc, vftLst[0], sectionBox)
TransactionManager.Instance.TransactionTaskDone()
OUT = newSection
Hi @martin.marek, it’s great that you found where the issue where, but are you able to apply the final solution?
I am doing the same as you, my problem is just that the section view is created far above the element. Any ideas?