I am just starting to try Dynamo and Python, and this is probably a very basic question.
My problem appears when I create a new Revit project, open Dynamo 1.3.3, and create a basic python script to create a duct form (0,0,0) and (5,5,5). Then I get the error
AtributeError: ‘Document’ object has no attribute 'NewDuct’
Code is as follows:
import clr
# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
#import Revit DB
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
#import Revit Creation where Create.Duct is
from Autodesk.Revit.Creation import *
clr.ImportExtensions(Revit.GeometryConversion)
# Import Revit elements
from Revit.Elements import *
# Import DocumentManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
#The inputs to this node will be stored as a list in the IN variables.
doc = DocumentManager.Instance.CurrentDBDocument
x = IN[0].ToXyz()
y = IN[0].ToXyz()
#ductType = IN[3]
#ductTypeUnwrapped = UnwrapElement(ductType) #not working
# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
doc.Create.NewDuct(x, y, ductType); #if DuctType is null then Revit picks first type.
# Stop Transaction
TransactionManager.Instance.TransactionTaskDone()
OUT = doc
Inputs to the Python block are just two points defined by coordinates.
Thanks in advance
I think where @Kulkul was getting to is that the NewDuct() method was deprecated in Revit 2017. You’ll need to use Duct.Create() method. See Revit API documentation in link below…
Thnaks, @Kulkul and @Daniel_Woodcock1, I got rid of the error by using Duct.Create, now I need to define the 5 inputs that are required for this function. I will try to include the full example when it’s working for future reference
I came across this post as I was getting the same error message. I updated the depreciated method as pointed out and ended up with this as a solution.
import clr
# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
#import Revit DB
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Mechanical import *
#import Revit Creation where Create.Duct is
from Autodesk.Revit.Creation import *
clr.ImportExtensions(Revit.GeometryConversion)
# Import Revit elements
from Revit.Elements import *
# Import DocumentManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
#The inputs to this node will be stored as a list in the IN variables.
doc = IN[0]
x = IN[1].ToXyz()
y = IN[2].ToXyz()
systemType = IN[3]
ductType = IN[4]
level = IN[5]
systemTypeID = ElementId(systemType)
ductTypeID = ElementId(ductType)
levelID = ElementId(level)
# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
#Revit 17.1 NewDuct() depreciated
#doc.Create.NewDuct(x, y, ductType); #if DuctType is null then Revit picks first type.
Duct.Create(doc, systemTypeID, ductTypeID, levelID, x, y);
# Stop Transaction
TransactionManager.Instance.TransactionTaskDone()
OUT = doc
Here is an Image of the Dynamo Nodes for Reference: