Gut cut elements only

Hi,
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.

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

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

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *

clr.AddReference('RevitServices')
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)
	TransactionManager.Instance.ForceCloseTransaction()
	TransactionManager.Instance.EnsureInTransaction(doc)
	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	
	
	viewtoSet.get_Parameter(BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING).Set(1)
	#set offset not depend of Template
	viewSection.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).Set(value)
	TransactionManager.Instance.TransactionTaskDone()
	doc.Regenerate()
	
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()
	else:
		elemIntersect = FilteredElementCollector(doc).WherePasses(filterSolid).WherePasses(filtercat).ToElements()
	#restore Offset far	
	changeOffsetFar(viewSection, initOffset)
	iList = List[ElementId]([x.Id for x in elemIntersect])	
	uidoc.Selection.SetElementIds(iList)
	OUT = elemIntersect

an example with electrical elements

1 Like