Gut cut elements only

I have a section, and I would like to select only the floors and walls that the section cut.
Is there a way to do that?

You can use select model elements.

a Python solution using the cropbox reduction (offset) in the view section

import clr
import itertools
from Autodesk.DesignScript.Geometry import *

#import Revit API
import Autodesk
from Autodesk.Revit.DB import *

from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument

import System
from System.Collections.Generic import List

def gen_PairPts(*args):
	"""generator for point pair loop
	for idx, pt in enumerate(args):
		try: yield pt, args[idx + 1]
		except : yield pt, args[0]

def solid_fromBBX(bbox):
	pt0 = XYZ( bbox.Min.X, bbox.Min.Y, bbox.Min.Z )
	pt1 = XYZ( bbox.Max.X, bbox.Min.Y, bbox.Min.Z )
	pt2 = XYZ( bbox.Max.X, bbox.Max.Y, bbox.Min.Z )
	pt3 = XYZ( bbox.Min.X, bbox.Max.Y, bbox.Min.Z )
	#create generator
	pairPts = gen_PairPts(pt0, pt1, pt2, pt3) 
	#Create loop, still in BBox coords
	edges = List[Curve]()
	for pt1, pt2 in pairPts:
		edges.Add(Line.CreateBound( pt1, pt2 ))

	height = bbox.Max.Z - bbox.Min.Z
	baseLoop = CurveLoop.Create( edges )
	loopList = List[CurveLoop]()
	loopList.Add( baseLoop )
	preTransformBox = GeometryCreationUtilities.CreateExtrusionGeometry( loopList, XYZ.BasisZ, height )
	transformBox = SolidUtils.CreateTransformed( preTransformBox, bbox.Transform )
	return transformBox
def changeOffsetFar(viewSection, value):
	viewtoSet = viewSection
	viewTempl = doc.GetElement(viewSection.ViewTemplateId)
	if viewTempl is not None:	
		lstnotcontrol = viewTempl.GetNonControlledTemplateParameterIds()
		bip = BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING
		if not any([bip.value__ == x.IntegerValue for x in lstnotcontrol]):
			viewtoSet = viewTempl	
	#set offset not depend of Template
def findSectionView(elemView):
	findView = None
	if isinstance(elemView, View):
		if 	elemView.ViewType == ViewType.Section:
			findView = elemView
		else: pass
	elif isinstance(elemView, Element):
		typeV = doc.GetElement(elemView.GetTypeId())
		if	isinstance(typeV, ViewFamilyType):	
			elemName = elemView.Name		
			collView = FilteredElementCollector(doc).OfClass(View)
			findView = [x for x in collView if not x.IsTemplate and x.Name == elemName and x.ViewType == ViewType.Section][0]
		else: pass
	else: pass
	return findView	
elemSection = UnwrapElement(IN[0])
catList = UnwrapElement(IN[1])
dependAsView = IN[2]

#store initial offsetFar
initOffset = elemSection.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).AsDouble()
#find categories from Enumeration
catBiplst = [ System.Enum.ToObject(BuiltInCategory, x.Id.IntegerValue ) for x in catList]
#find view section from select element
viewSection = findSectionView(elemSection)

if viewSection is not None:
	#reduce Offset Far
	changeOffsetFar(viewSection, 0.2)
	bbxView = viewSection.CropBox 
	solidbbx = solid_fromBBX(bbxView)
	filterSolid = ElementIntersectsSolidFilter(solidbbx)
	cats = List[BuiltInCategory](catBiplst)
	filtercat = ElementMulticategoryFilter(cats)
	if dependAsView:
		elemIntersect = FilteredElementCollector(doc, viewSection.Id).WherePasses(filtercat).ToElements()
		elemIntersect = FilteredElementCollector(doc).WherePasses(filterSolid).WherePasses(filtercat).ToElements()
	#restore Offset far	
	changeOffsetFar(viewSection, initOffset)
	iList = List[ElementId]([x.Id for x in elemIntersect])	
	OUT = elemIntersect

an example with electrical elements

1 Like