Choosing the right method (overload) for flex duct creation

revit

#1

Hello everyone,

I’m trying to create a piece of flex duct through the API with this method:

I’ve create the following code in which the input is a piece of duct with a single open connector and an air terminal with an open connector.

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitAPI")
import Autodesk

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

terminal = UnwrapElement(IN[0])
duct = UnwrapElement(IN[0])
ducttype = UnwrapElement(IN[1])


TransactionManager.Instance.EnsureInTransaction(doc)

csi1 = duct.MEPModel.ConnectorManager.UnusedConnectors.ForwardIterator()
while csi1.MoveNext():
	connector1 = csi1.Current

csi2 = terminal.MEPModel.ConnectorManager.UnusedConnectors.ForwardIterator()
while csi2.MoveNext():
	connector2 = csi2.Current

flexduct = doc.Create.NewFlexDuct(connector1, connector2, ducttype)

TransactionManager.Instance.TransactionTaskDone()

OUT = flexduct

Now the problem is that I get the following error message telling me to feed it a list of points instead of a connector.


Is there a way to make it use the method with the connectors instead of the method with the list of points?


#2

You are feeding pipetype as a list and the overload is expecting a FlexPipeType…

Edit: FlexDuctType actually…

Anyway, it’s very important that you make sure that the data types are correct, that’s the only way iron python can decide which metohod (overload) to use.


#3

Argh, yeah stupid of me…
I changed the type, but it’s still giving me the same warning. That would mean that probably one of the connectors isn’t a connector data type? I’ll go look into that. Thanks!


#4

also note: All Elements of Type returns a list (event though it contains only one element)


#5

I removed that and I also had my inputs assigned all wrong. Almost there I think :slight_smile: I’ll post the result.


#6

Well I’m stumped… I’ve created a second python node that outputs the 3 variables for the method. They all seem to be of the correct type, but I still get the same error message… any ideas?

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitAPI")
import Autodesk

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

terminal = UnwrapElement(IN[0])
duct = UnwrapElement(IN[1])
ducttype = UnwrapElement(IN[2])


TransactionManager.Instance.EnsureInTransaction(doc)

csi1 = duct.ConnectorManager.UnusedConnectors.ForwardIterator()
while csi1.MoveNext():
	connector1 = csi1.Current

csi2 = terminal.MEPModel.ConnectorManager.UnusedConnectors.ForwardIterator()
while csi2.MoveNext():
	connector2 = csi2.Current

flexduct = doc.Create.NewFlexDuct(connector1, connector2, ducttype)

TransactionManager.Instance.TransactionTaskDone()

OUT = flexduct

Remove Parameters while Avoiding Built-In Parameters
#7

I don’t know anything about modeling ducts in Revit, so I can’t test the script. With the correct data types it should be no problem for ironpython to choose the correct overload. One last thing I can think of is to try to force the correct overload with something like this: (I dont remember exactly the correct syntax, you can try to do an internet search and see if anything meaningful shows)

flexduct = doc.Create.NewFlexDuct.Overloads.Functions[1](connector1, connector2, ducttype)

or

flexduct = doc.Create.NewFlexDuct.Overloads[Connector, Connector, FlexDuctType](connector1, connector2, ducttype)


#8

Finally got it to work, turns out you were right about feeding it wrong types: FlexDuctType input was wrong. I still had to specify the exact type of course.

your suggestion for using the overloads worked btw, I used this to get it to work:

flexduct = doc.Create.NewFlexDuct.Overloads[Autodesk.Revit.DB.Connector, Autodesk.Revit.DB.Connector, Autodesk.Revit.DB.Mechanical.FlexDuctType](connector1, connector2, ducttype)

and this one also worked:

flexduct = doc.Create.NewFlexDuct.Overloads.Functions[2](connector1, connector2, ducttype)

Thanks a lot!


#9

Glad you got it to work, the Overloads methods can be a nice feature sometimes, at least to get the correct warnings when you are trouble shooting.