Creates a new duct from two points with revit 2019 api

Creates a new duct from two points with revit 2019 api

congvietbk
Explorer Explorer
2,396 Views
4 Replies
Message 1 of 5

Creates a new duct from two points with revit 2019 api

congvietbk
Explorer
Explorer

Hi everyone,

I have a little problem. I could not get the systemTypeId to create the wind pipe from 2 points (XYZ) with a new project. I use the function following:

public static Duct Create(
	Document document,
	ElementId systemTypeId,
	ElementId ductTypeId,
	ElementId levelId,
	XYZ startPoint,
	XYZ endPoint
)

In the 2016 revit version I used the a function very easily but i can't found this function in above Revit 2017 version.

public Duct NewDuct(
	XYZ point1,
	XYZ point2,
	DuctType ductType
)

Please help me. Thank you.

Best regards

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
2,397 Views
4 Replies
Replies (4)
Message 2 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @congvietbk ,

try using the below code

MEPSystemType mepSystemType = new FilteredElementCollector(doc)
        .OfClass(typeof(MEPSystemType))
        .Cast<MEPSystemType>()
        .FirstOrDefault(sysType => sysType.SystemClassification == MEPSystemClassification.SupplyAir);

MEPSystemClassification classify MEP connectors and systems and drives certain behavior for a particular system type

MEPSystemClassification 

 

I hope this helps.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

congvietbk
Explorer
Explorer

Autodesk.Revit.DB.Mechanical.DuctType ductType = GetDuctType();
ElementId levelId=GetLevelId();
XYZ startPoint = new XYZ();
XYZ endPoint = new XYZ(100, 100,0);

var mecSystem = new FilteredElementCollector(doc)
.OfClass(typeof(MEPSystem))
.Cast<MEPSystem>()
.FirstOrDefault(sysType => sysType.GetType() == typeof(MechanicalSystem));
ElementId systemTypeId = mecSystem.GetTypeId();
Duct duct = Duct.Create(doc,systemTypeId, ductType.Id,levelId,startPoint,endPoint);

in the project if I have not set the equipment, air terminals, ducts then mecSystem = null

Is there a way to still create a duct with the Duct.Create function without having to draw the duct first in the revit?

 

 

 

 

 

0 Likes
Message 4 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @congvietbk ,

Yes, it is possible to create a duct with the Duct.Create() without having to draw the duct first in the Revit.

Here is the complete code to draw a duct in Revit using Revit API

 

Level L;

                FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(DuctType)).WhereElementIsElementType();
                DuctType DT = collector.First() as DuctType;

                MEPSystemType mepSystemType = new FilteredElementCollector(doc)
         .OfClass(typeof(MEPSystemType))
         .Cast<MEPSystemType>()
         .FirstOrDefault(sysType => sysType.SystemClassification == MEPSystemClassification.SupplyAir);

                Duct duct = Duct.Create(doc,mepSystemType.Id ,DT.Id, L.Id,new XYZ(0, 0, 0), new XYZ(100, 100, 0));

If you still have any questions...can you please explain briefly?

 

 

Please note:sys.SystemClassification and sys.GetType() are doing different operations here.

Here we are filtering duct type and duct system type from the project not from the placed elements.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

Anonymous
Not applicable

I'm having a similar problem, and when I try to use this method for finding the SystemTypeId I get an error from Revit that says, "The systemTypeId is not a valid HVAC system type". Does anyone know how to fix this error?

 

Not sure how to delete this.. but I solved this. 

0 Likes