Ducts are disconnected after changing size using code

Ducts are disconnected after changing size using code

Anonymous
Not applicable
830 Views
4 Replies
Message 1 of 5

Ducts are disconnected after changing size using code

Anonymous
Not applicable

Hi everyone,

 

I am trying to create an automated script to generate duct from Air Terminal to Main Duct.  Following is my code: 

 

// Create first Duct
                                Duct firstduct = Duct.Create(document, filterelements2.Where(o => o.Name == selectedDuctType).First().Id, selectedDuct.ReferenceLevel.Id, AirTerminalConnector, B);


                                // Get unused connector of the first duct
                                ConnectorSet unusedConnector1 = firstduct.ConnectorManager.UnusedConnectors;
                                List<Connector> list3 = new List<Connector>();
                                foreach (Connector c in unusedConnector1)
                                {
                                    list3.Add(c);

                                }
                                Connector unused1 = list3.First();

                                // Create seconduct
                                Duct seconduct = Duct.Create(document, pipeSysTypeId, firstduct.DuctType.Id, selectedDuct.ReferenceLevel.Id, B, D);
                               

                                ConnectorSet seconductConnectors = seconduct.ConnectorManager.Connectors;
                                List<Connector> list4 = new List<Connector>();
                                foreach (Connector c in seconductConnectors)
                                {
                                    list4.Add(c);
                                }

									// Connect 2 connectors of 2 pipe to create the fitting
                                    unused1.ConnectTo(list4.First());
									
									
                                    // Create take off fitting
                                    document.Create.NewTakeoffFitting(list4.Last(), selectedDuct);
                                  //  seconduct.Document.Regenerate();

and the result is as following image: 

 

Capture.PNG

The problem is the Second Duct have difference size with the first Duct. Then I tried to change the size of the Second Duct equal to the First Duct by following Code: 

BuiltInParameter daimeterpara = BuiltInParameter.RBS_CURVE_DIAMETER_PARAM;
                                Parameter parameter = seconduct.get_Parameter(daimeterpara);
                                parameter.Set(Convert.ToDouble(firstduct.Diameter));
                                seconduct.Document.Regenerate();

But the result is the First Duct disconnected with the Second Duct as following image: 

Capture.PNG

If anyone had experience with this issue please help me, I would be very appreciated your help :).

Thank you.

 

Best Regards,

 

Cherry Truong

 

 

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

jlpgy
Advocate
Advocate
Accepted solution

Hi @Anonymous :

This is good post, and you stated your question clearly.

I did not completely test your smaple codes in my enrionment. But I am afraid that you did not correctly connet two ducts.

You did not invoke the method Create.NewElbowFitting() in your codes. For my experience, you should not get an elbow......Smiley Sad

You used this line to connect two ducts:

// Connect 2 connectors of 2 pipe to create the fitting
unused1.ConnectTo(list4.First());

You should try to invoke Create.NewElbowFitting() method instead of the above one.

According to your sample codes, I do believe that you are able to figure out how to use this method.!

Try it and let us know how you get Man Happy

 

In my solutions, I had tested ConnectTo method. And it sometimes leads to very wierd results or behaviours.

单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
Message 3 of 5

Anonymous
Not applicable

Hi @jlpgy,

 

Thank you so much for your great help and suggestion. I just revise the code and successfully to finish my code Smiley Very Happy. Here is the screenshot of the result, amazing fast auto routing for duct: 

Capture.PNG

Best Regards,

 

Cherry Truong

Message 4 of 5

jlpgy
Advocate
Advocate

Hi:

So great to hear that you accomplished it.

What's more, I do remember that there is a similar solution in Revit SDK samples.

It should be stored in %intallation directory%/Revit 201X SDK/Samples/AutoRoute/

It also implement an experimental automation to route Duct network from a Mechanical Facility to several Duct Terminals.

单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
0 Likes
Message 5 of 5

Anonymous
Not applicable

Hi @jlpgy,

 

Thank you for your suggestion. I will look through the sample script you mentioned. 

I am  trying to create more automation for MEP as possible for my team so it looks very promising :).

Have a nice day.

 

Best Regards,

 

Ninh Truong