Hi, I’m trying to do something that might seem simple (cut a wall into two parts), but I’m stuck on the DivideParts method of the PartUtils class.
I think I’m correct for the cut line and sketchplane. The rest, I don’t really understand why I’m getting an error message.
Script Python
import sys
import clr
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import HostObjectUtils,ShellLayerType,SketchPlane,XYZ,Line,PartUtils,ElementId,CurveArray
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
import System
from System.Collections.Generic import List
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Transactions import TransactionManager
def findpts(f):
lpts=[]
clt=f.GetEdgesAsCurveLoops()
for cl in clt:
for c in cl:
lpts.append(c.GetEndPoint(0))
return lpts
mur=UnwrapElement(IN[0])
ht=IN[1]
lc=mur.Location.Curve
leid=List[ElementId]()
leid.Add(mur.Id)
doc=mur.Document
refplane=HostObjectUtils.GetSideFaces(mur,ShellLayerType.Exterior)[0]
faceext=mur.GetGeometryObjectFromReference(refplane)
TransactionManager.Instance.EnsureInTransaction(doc)
skplane=SketchPlane.Create(doc,refplane)
doc.Regenerate()
PartUtils.CreateParts(doc,leid)
doc.Regenerate()
pext=findpts(faceext)
pstartloc=lc.GetEndPoint(0)
newp=[XYZ(p.X,p.Y,pstartloc.Z) for p in pext]
np2=sorted(newp,key=lambda p:(p.X))
pd=XYZ(np2[0].X,np2[0].Y,np2[0].Z)
pf=XYZ(np2[-1].X,np2[-1].Y,np2[-1].Z)
orient=XYZ(pf.X-pd.X,pf.Y-pd.Y,pf.Z-pd.Z).Normalize()
pstart=pd.Add(orient.Multiply(-1/0.3048))
pend=pf.Add(orient.Multiply(1/0.3048))
linecut=Line.CreateBound(XYZ(pstart.X,pstart.Y,pstart.Z+ht/0.3048),XYZ(pend.X,pend.Y,pend.Z+ht/0.3048))
lcur=CurveArray()
lcur.Append(linecut)
intersectionElementsIds = List[ElementId]()
parts = PartUtils.GetAssociatedParts(doc, mur.Id,True, True)
partDivide = PartUtils.DivideParts(doc, parts, intersectionElementsIds, lcur, skplane.Id)
TransactionManager.Instance.TransactionTaskDone()
OUT=partDivide
Thanks in advance, kind regards,
christian.stan