how to connect conduits in one conduitrun

how to connect conduits in one conduitrun

merijn3DJ77
Explorer Explorer
1,173 Views
5 Replies
Message 1 of 6

how to connect conduits in one conduitrun

merijn3DJ77
Explorer
Explorer

Dear Forum,

 

I want to create a conduitrun using dynamo, based on XYZ coordinates. So far I was able te generate separate conduits using a python script. But they appear in Revit as separate conduits, and they don't connect automatically.
I tried to loop over the connectors in each conduit and use the connectTo() command. but to no avail.
This is the python script I used:

 

 

 

import clr
import sys

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

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

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

toggle = ""
if isinstance(IN[0], list):
    runs = IN[0]
for run in runs:
    if isinstance(run, list):
    	lines = run
    else:
    	lines = [run]
    FirstPoint = [x.StartPoint for x in lines]
    SecondPoint = [x.EndPoint for x in lines]
    conduittype = UnwrapElement(IN[1])
    if isinstance(IN[2], list):
    	level = UnwrapElement(IN[2])
    	toggle += "0"
    else:
    	level = [UnwrapElement(IN[2])]
    if isinstance(IN[3], list):
    	diameter = IN[3]
    	toggle += "1"
    else:
    	diameter = [IN[3]]
    
    elements = []
    
    valid = Autodesk.Revit.DB.Electrical.Conduit.IsValidConduitType(doc,conduittype.Id)
    TransactionManager.Instance.EnsureInTransaction(doc)
    #conduit = Autodesk.Revit.DB.Electrical.Conduit.Create(doc,conduittype.Id,FirstPoint[0].ToXyz(),SecondPoint[0].ToXyz(),level[0].Id)
    #TransactionManager.Instance.TransactionTaskDone()
    startpoint = FirstPoint[0].ToXyz()

    
    for i,x in enumerate(SecondPoint):
        endpoint = x.ToXyz()
        conduit = Autodesk.Revit.DB.Electrical.Conduit.Create(doc,conduittype.Id,startpoint,endpoint,level[0].Id)
        param = conduit.get_Parameter(BuiltInParameter.RBS_CONDUIT_DIAMETER_PARAM);
        param.SetValueString(diameter[0])
        startpoint = endpoint
        # Set the new curve to the second conduit
        #locCure2.Curve = newCurve2
        elements.append(conduit)
    TransactionManager.Instance.TransactionTaskDone()
    TransactionManager.Instance.EnsureInTransaction(doc)
    for i in range(len(elements) - 1):
        iterator = elements[i].ConnectorManager.Connectors.GetEnumerator()
        iterator.MoveNext()
        iterator.MoveNext()
        connectorfirst = iterator.Current
        iterator = elements[i+1].ConnectorManager.Connectors.GetEnumerator()
        
        iterator.MoveNext()
        connectorsecond = iterator.Current
        connectorfirst.ConnectTo(connectorsecond)

    TransactionManager.Instance.TransactionTaskDone()

    
    
OUT = elements

 

 

 

merijn3DJ77_0-1717191128337.png

As you can see in the picture, all the conduits are connected on their endpoints, but in a conduit run i get only separated conduits:

merijn3DJ77_1-1717191233449.png

 

 

Thanks in advance for your help.

 

 

 

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
1,174 Views
5 Replies
Replies (5)
Message 2 of 6

Moustafa_K
Collaborator
Collaborator
Accepted solution

no it will not do things without being told 🙂 ..  you need to connect them using something like this

Doc.Create.NewElbowFitting(connectorA, connectorB);
Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 3 of 6

merijn3DJ77
Explorer
Explorer

Thanks for the solution. That worked. I could place the elbows and the runs aren't split up any more.

 

One related question though, I have some collinear conduits that i have to connect with a Union fitting.

I used the command NewUnionFitting(conn A, conn B) and the fitting was placed accordingly, but the conduitruns were still separated in 2 runs. Any ideas why that might be?

 

Kind Regards,

 

Merijn 

0 Likes
Message 4 of 6

Moustafa_K
Collaborator
Collaborator

the purpose of adding a connection fitting is to simulate what actually going to be constructed on Site. if you need a single pipe run, then you can extend one of the connectors to the desired position and delete the 2nd run, (but is that what going to be done on Site?). and by then you don't need any fitting to couple them. 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 5 of 6

bogdan.petrescu63URX
Participant
Participant

hi, could you please re-upload the script with the solution implemented? can't get my head around how to implement it.

0 Likes
Message 6 of 6

bogdan.petrescu63URX
Participant
Participant

hi moustafa, could you please show the whole code - where do you use that connector magic?

0 Likes