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
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
Hello, I am a beginner in dynamo, I want to make a circular opening on a circular floor. What inputs did you put at “IN0” and “opening curves” ? because I entered a circle that represents my floor and a smaller circle that represents my opening. This does not work.
import clr
import sys
import System
clr.AddReference("System.Numerics")
#
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import net library
from System import Array
from System.Collections.Generic import List, IList, Dictionary
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
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
app = uiapp.Application
sdkNumber = int(app.VersionNumber)
curves = IN[0]
floorType= UnwrapElement(IN[1])
level = UnwrapElement(IN[2])
is_Structural=IN[3]
openingCurves=IN[4]
TransactionManager.Instance.EnsureInTransaction(doc)
#
if sdkNumber > 2021:
outer_Curves = List[DB.Curve]([i.ToRevitType() for i in curves])
inner_Curves = List[DB.Curve]([i.ToRevitType() for i in openingCurves])
#
outer_curveloop = CurveLoop.Create(outer_Curves)
inner_curveloop = CurveLoop.Create(inner_Curves)
floor = Floor.Create(doc, List[CurveLoop]([outer_curveloop, inner_curveloop]), floorType.Id, level.Id)
else:
rvt_Curves = CurveArray()
for i in curves:
rvt_Curves.Append(i.ToRevitType())
floor = doc.Create.NewFloor(rvt_Curves, floorType, level, is_Structural)
#Regenerate the Document to make sure the Document Registers the Floor
doc.Regenerate()
#
rvt_Opening = CurveArray()
for i in openingCurves:
rvt_Opening.Append(i.ToRevitType())
#
opening = doc.Create.NewOpening(floor, rvt_Opening, True)
TransactionManager.Instance.TransactionTaskDone()
OUT = floor
Hello, you added this namespace ( clr.AddReference("System.Numerics") ), but you don’t use it here in the rest of the code (that’s right)
this is an improved boiler plate code