Mirror sectionview without a copy (Python)

Hi,

This is my first shot at creating a custum node for mirroring (without copy) a sectionview.
So bear with me
Revit 2017.2, Dynamo 1.3.2

I copied some Python code from another node that i used to get me started and needs to be cleaned up a bit

import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import ElementTransformUtils, Plane

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

doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

walls = UnwrapElement(IN[0])
planes = IN[1]
rvt_planes =list()
mirrored = list()
count = 0

def Dyn2RvtPlane(pl1):
	normal1 = pl1.Normal.ToXyz(True)
	origin1 = pl1.Origin.ToXyz(True)
	return Autodesk.Revit.DB.Plane(normal1, origin1)

TransactionManager.Instance.EnsureInTransaction(doc)
for p in planes:
	rvt_planes.append(Dyn2RvtPlane(p))
for w, rp in zip(walls, rvt_planes):
	try:
		item.Flip()
		ElementTransformUtils.MirrorElement(doc, w.Id, rp)
		count += 1
	except:
		count += 0
TransactionManager.Instance.TransactionTaskDone()
		
OUT = "%s elements mirrored" %count

This will mirror/copy my sections using the Revit Origin.
What i want is to mirror the sections on their own plane (flip) without a copy.
The part with ElementTransformUtils.MirrorElement(doc, w.Id, rp) needs a fourth argument (false) to prevent it making a copy, but if i do this nothing happens.
Creating new views is unwanted because the views are on sheet already, just filpped

i need a push in the right direction here, can someone help?

mirror_flip_sections.dyn (7.4 KB)

You you please format the code using the “</>” option as your codes formatting is otherwise lost and as Python is indent sensitive it would require people trying to help you to go through your entire code for indentations… :slight_smile:

Cant get it right with indents, tying to find a solution here, but its in the .dyn anyway…

You can do it like so:

1 Like

@Jonathan.Olesen

its now in the first post :slight_smile:

1 Like

anyone?

bump

I have gotten as far as… image

perhaps some python gurus would like to chime in… as “expected Plane, got Plane” is not very helpful :thinking:

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

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

doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

from System.Collections.Generic import *

walls = UnwrapElement(IN[0])
planes = IN[1]
rvt_planes =list()
mirrored = list()
e1=[]
count = 0

TransactionManager.Instance.EnsureInTransaction(doc)
for p in planes:
	rvt_planes.append(p)
for w, rp in zip(walls, rvt_planes):
	e1.append(w.Id)
	Icoll = List[ElementId](e1)
	ElementTransformUtils.MirrorElements(doc, Icoll, rp,1)
TransactionManager.Instance.TransactionTaskDone()
		
OUT = "%s elements mirrored" %count
2 Likes

@m.rijsmus The reason that original code wasn’t working is because when mirroring a section view, its not the view itself that’s meant to be mirrored, rather the section viewer/annotative element. It turns out that the Element ID of a section’s viewer is one less than the section view’s Element ID which is fortunate for making this work with inputting the view itself; this modified script will get the section viewer’s element ID from the section view. I also combined the method from the Clockwork node’s View.Plane Python script within it.

Here is a working script:

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

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

doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

from System.Collections.Generic import *

sections = IN[0]
if not isinstance(sections,list):
	sections = [sections]


#get View Plane to use as the Mirror Plane
def getPlane(s):
	s = UnwrapElement(s)
	origin = s.Origin
	normal = s.ViewDirection
	plane = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(normal,origin)
	return plane


#get the Element ID for the Section View's Annotative Viewer
def getViewer(s):
	viewerId = ElementId(s.Id - 1)
	return viewerId

def flipSection(s):
	ids = []
	ids.append(getViewer(s))
	Icoll = List[ElementId](ids)
	rp = getPlane(s)
	ElementTransformUtils.MirrorElements(doc, Icoll, rp, False)
	return s
	
count = 0

TransactionManager.Instance.EnsureInTransaction(doc)

for s in sections:
	try:
		flipSection(s)
		count = count + 1
	except:
		pass

TransactionManager.Instance.TransactionTaskDone()

OUT = "%s elements mirrored" %count
7 Likes