Create Floor with Openings - Python, Dynamo

Hello guys!
I’m trying to set a sript to create a Floor with Openings in Phyton + Dynamo.
But, When I run my script I get this Revit Error (No code error).
I would like to know what’s happening here
If you can help me, I’ll appreciate you

This is my code:

import clr 
import sys 
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib') 
import System 
from System import Array 
from System.Collections.Generic import * 
clr.AddReference('ProtoGeometry')  
from Autodesk.DesignScript.Geometry import * 
clr.AddReference("RevitNodes")
import Revit 
clr.ImportExtensions(Revit.Elements) 
clr.ImportExtensions(Revit.GeometryConversion) 
from Revit import GeometryConversion 
clr.AddReference("RevitServices")
import RevitServices 
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager 
clr.AddReference("RevitAPI") 
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import * 
from Autodesk.Revit.UI import *   

doc = DocumentManager.Instance.CurrentDBDocument 
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application  
uidoc = uiapp.ActiveUIDocument 

Curves = IN[0]
FloorType= UnwrapElement(IN[1])
Level = UnwrapElement(IN[2])
Is_Structural=IN[3]
OpeningCurves=IN[4]

RVT_Opening = CurveArray()

for i in OpeningCurves:

	RVT_Opening.Append(i.ToRevitType())


#Convertir RVT curves a CurveArray
RVT_Curves = CurveArray()

for i in Curves:
	
	RVT_Curves.Append(i.ToRevitType())

TransactionManager.Instance.EnsureInTransaction(doc)

#Creación del Piso
Floor = doc.Create.NewFloor(RVT_Curves,FloorType,Level,Is_Structural)


Opening = doc.Create.NewOpening(Floor,RVT_Opening,True)

TransactionManager.Instance.TransactionTaskDone()	
	
OUT = Floor

Okay never mind my other answer.

The solution is simple. You have to regenerate the current Document after making the floor and before making the opening. This way the document registers the new Floor.

import clr 
import sys 
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib') 
import System 
from System import Array 
from System.Collections.Generic import * 
clr.AddReference('ProtoGeometry')  
from Autodesk.DesignScript.Geometry import * 
clr.AddReference("RevitNodes")
import Revit 
clr.ImportExtensions(Revit.Elements) 
clr.ImportExtensions(Revit.GeometryConversion) 
from Revit import GeometryConversion 
clr.AddReference("RevitServices")
import RevitServices 
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager 
clr.AddReference("RevitAPI") 
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import * 
from Autodesk.Revit.UI import *   

doc = DocumentManager.Instance.CurrentDBDocument 
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application  
uidoc = uiapp.ActiveUIDocument 

Curves = IN[0]
FloorType= UnwrapElement(IN[1])
Level = UnwrapElement(IN[2])
Is_Structural=IN[3]
OpeningCurves=IN[4]

RVT_Opening = CurveArray()

for i in OpeningCurves:

	RVT_Opening.Append(i.ToRevitType())


#Convertir RVT curves a CurveArray
RVT_Curves = CurveArray()

for i in Curves:
	
	RVT_Curves.Append(i.ToRevitType())

TransactionManager.Instance.EnsureInTransaction(doc)

#Creación del Piso
Floor = doc.Create.NewFloor(RVT_Curves,FloorType,Level,Is_Structural)

#Regenerate the Document to make sure the Document Registers the Floor
doc.Regenerate()

#Creación del Piso
Opening = doc.Create.NewOpening(Floor,RVT_Opening,True)

TransactionManager.Instance.TransactionTaskDone()	

	
OUT = Floor

I added one line:
doc.Regenerate()

1 Like

Thank you!!!
It works!!!