Create section and rotate section in same script

I am building a dynamo script that creates multiple sections for a model group. One of the sections I want to rotate after it is created, in them same script. I use a SectionView.ByCoordinateSystemMinPointMaxPoint to create the sections and that works fine. But then I use a python script to rotate one of the sections and that won’t work. When I put the python script in a separate dynamo script it works fine. Can somebody help me with this problem?

Extra information about the working of the python and dynamo script:

I want to create sections and rotate a section in one script, because what the rotation needs to be is determent when the sections are create and do not prefer to make a separate parameter in Revit so that the data can be used in a separate script that rotates the section.

The python script uses the boundingbox of the section to determine its centerpoint and rotate the section around the Z axis. When I created the section and rotate the section in the same dynamo script, the python script is not able to find the boundingbox of the section. When I remove the boundingbox out of the script and try to rotate the element around 0.0.0 point in Revit, it won’t work.

With the dynamo script I want in the future, is to make several sections for different model groups at once and place them on sheets. Because the modelgroup can also be slanted and the views always needs be at right angles to the model group, I also use sections as floorplans that I have rotated 90 degrees. With the create section view node, this all goes fine. But the sections that are “floorplans” views are always in vertical direction no matter how I put in the coordinate system in the create section node. I need those views to be in horizontal direction. So that its why I want to rotate the section after creating section.

1 Like

Hello
you can’t rotate directly a section View, it’s necessary to use sub-Elements in this case
here an example of workaround
RotateSectionView

import clr
import sys
import System
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument


pf_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
sys.path.append(pf_path + '\\IronPython 2.7\\Lib')

def geSubElements(v):
	classFilter = ElementClassFilter(SketchPlane )
	skplanes = [doc.GetElement(x) for x in v.GetDependentElements(classFilter)]
	catFilter = ElementCategoryFilter(BuiltInCategory.OST_Viewers)
	elements = [doc.GetElement(x) for x in v.GetDependentElements(catFilter)]	
	for e in elements:
		if hasattr(e, "Location"):
			return skplanes[0], e

toList = lambda x : x if hasattr(x, '__iter__') else [x]
lstSectionViews = toList(UnwrapElement(IN[0]))
level = UnwrapElement(IN[1])
zValue = level.ProjectElevation

TransactionManager.Instance.EnsureInTransaction(doc)

for v in lstSectionViews:
	skpl, elem = geSubElements(v)
	cropbox = v.CropBox
	tf = cropbox.Transform
	plane = skpl.GetPlane()
	origin = plane.Origin
	centerBox = (tf.OfPoint(cropbox.Min) + tf.OfPoint(cropbox.Max)) * 0.5
	vectorTr = XYZ(0, 0, zValue + 3 - origin.Z )
	axis = Line.CreateUnbound(origin, plane.XVec )
	ElementTransformUtils.RotateElement(doc, elem.Id, axis, math.pi * -0.5)
	doc.Regenerate()
	elem.Location.Move(vectorTr)

TransactionManager.Instance.TransactionTaskDone()

OUT = lstSectionViews
3 Likes

Thanks for the help, its works great

1 Like