Creating Openings in dynamo with python

I am trying to create openings in walls where ducts pass through them. I have been using this code I found however it does not work, it find the correct locations but revit error says cannot create openings. is there anyway to modify this code?
Forum 1|555x500

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

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

doc = DocumentManager.Instance.CurrentDBDocument
openings =

walls = IN[0]
points = IN[1]
direction = IN[2]
width = IN[3]
height = IN[4]

for idx in range(0,len(walls)):
if direction == ‘x’:
ULX=(points[idx]).X - width[idx]/2
ULY=(points[idx]).Y
ULZ=(points[idx]).Z + height[idx]/2

	UL = XYZ(ULX/304.8,ULY/304.8,ULZ/304.8)
	
	DRX=(points[idx]).X + width[idx]/2
	DRY=(points[idx]).Y
	DRZ=(points[idx]).Z - height[idx]/2
	
	DR = XYZ(DRX/304.8,DRY/304.8,DRZ/304.8)
else:
	ULX=(points[idx]).X
	ULY=(points[idx]).Y - width[idx]/2
	ULZ=(points[idx]).Z + height[idx]/2
		
	UL = XYZ(ULX/304.8,ULY/304.8,ULZ/304.8)
	
	DRX=(points[idx]).X
	DRY=(points[idx]).Y + width[idx]/2
	DRZ=(points[idx]).Z - height[idx]/2
	
	DR = XYZ(DRX/304.8,DRY/304.8,DRZ/304.8)

TransactionManager.Instance.EnsureInTransaction(doc)
opening = doc.Create.NewOpening(UnwrapElement(walls[idx]),UL,DR)
doc.Regenerate()
TransactionManager.Instance.TransactionTaskDone()
openings.append(opening)

OUT = openings

1 Like