AttributeError: 'Document' object has no attribute 'NewDuct'

Hello,

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

Hi @xberzal

There are couple of items missing in your code. But first which Revit version are you using?

Hi kulkul.
it’s Revit 2019.

Hi @xberzal,

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…

http://www.revitapidocs.com/2017.1/6f8b1fa9-5e94-2a31-c921-ec1db957b31b.htm

Also, you are assigning X = IN[0] and Y = IN[0]. This is the same point and will fail as a line based family cannot have coincidental endpoints.

Also, what error are you getting from the UnwrapElement as you say it is failing?

Cheers,
Dan

2 Likes

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

1 Like

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:

Hi kphillips,
Could you upload an image of the dynamo nodes to accompany this script please.
Thanks in advance

The Image of the Dynamo nodes were uploaded on the previous post. Can you see that?