Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Modify Duct Length in Revit API Despite Read-Only Property Constraint

6 REPLIES 6
Reply
Message 1 of 7
bhavita_patil
512 Views, 6 Replies

Modify Duct Length in Revit API Despite Read-Only Property Constraint

Hello,
   I'm new to Revit api. I'm wondering if it's possible to alter the length of a duct in Revit through the API. Upon trying, I've noticed that the duct length property appears to be set as read-only. Is there a workaround to modify the duct length? Any assistance on this matter would be helpful.

Thanks,
Bhavita

 

 

6 REPLIES 6
Message 2 of 7

Yes it can be done. The API wraps the UI functionality, so the best way to address this is to determine the optimal workflow and best practices manually in the user interface first. How do you solve this in the UI?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 7

HI @bhavita_patil 

    As @jeremy_tammik  said we don't have API support to change the duct length. But I found a workaround that we can delete the existing one and create a new duct with a new length, then update the neighboring duct length according to that. Kindly refer to the below code for additional reference.

 

Reference Code

UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document doc = uiDoc.Document;

            Reference refer = uiDoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);

            Duct duct = doc.GetElement(refer) as Duct;

            ///New Length Dimension
            double newLength = UnitUtils.ConvertToInternalUnits(10000,UnitTypeId.Millimeters);

            ///Calculating New Length
            LocationCurve curve = duct.Location as LocationCurve;
            XYZ p1 = curve.Curve.GetEndPoint(0);
            XYZ p2 = p1 + ((curve.Curve as Line).Direction * newLength);

            using (Transaction deleteDuctAndCreateNew = new Transaction(doc, "Delete Existing Duct and Create New"))
            {
                deleteDuctAndCreateNew.Start();

                //Create New Duct
                Duct.Create(doc, duct.MEPSystem.GetTypeId(),duct.GetTypeId(), duct.ReferenceLevel.Id, p1, p2);

                doc.Delete(duct.Id);

                deleteDuctAndCreateNew.Commit();
            }

 

Reference Video

ChangeDuctLength.gif

 

Hope this Helps 🙂

Thanks & Regards,
Mohamed Arshad K
Message 4 of 7
Moustafa_K
in reply to: Mohamed_Arshad

@Mohamed_Arshad , your solution is great, and I admit i sometimes do it in this direction for certain cases. The issue you will face here, deleting an existing element means disconnecting it from the System, loosing all instance values such as mark or comment.

 

not sure if you would agree with me, I would be more inclined to  only increase the length of the MepCurve (Duct, pipe, conduit...etc.)

var locCurve = ductObject.Location as LocationCurve;
locCurve.Curve = extendedCurve;

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 5 of 7
jeremy_tammik
in reply to: Moustafa_K

If the duct is connected to neighbouring elements, you can let Revit modify and adapt its length automatically by moving those neighbours and their connection points. Look at an exploration of different approaches to modifying pipe length in the blog post series on implementing a rolling offset:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 6 of 7
Moustafa_K
in reply to: jeremy_tammik

Thanks, yep, that is the perfect approach, to just move the neighbor elements, and it will keep all the connections intact.

 

Just to add another approach, for those MEP curves without neighbor  connections. We may also extend the curve directly by its connector, which mean no line or assign location curve is needed.

Connector connector = getMyConnector();
double extendby = 1; // extend by 1 feet for example
XYZ direction = ductCurve.Direction; // assuming the duct is linear curve
connector.Origin = connector.Origin + direction * extendby;

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 7 of 7
jeremy_tammik
in reply to: Moustafa_K

Thank you for the suggestions and nice discussion. I shared it on the blog for future reference:

  

https://thebuildingcoder.typepad.com/blog/2024/05/lengthen-ducts-and-highlight-links.html#3

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report