Hi, nice to see you on my page. If you are looking for tools that will help you in the daily work of an architect, engineer or designer, you have come to the right place. Below are the latest entries. If you are looking for something specific, you can do so using the search engine or post categories. If you want to know more about me, please visit the "about me" tab. Have you used my solutions? You can return the favour by buy me a virtual coffee using the "Buy me a coffe" button
Hi, nice to see you on my page. If you are looking for tools that will help you in the daily work of an architect, engineer or designer, you have come to the right place. Below are the latest entries. If you are looking for something specific, you can do so using the search engine or post categories. If you want to know more about me, please visit the "about me" tab. Have you used my solutions? You can return the favour by buy me a virtual coffee using the "Buy me a coffe" button
In this post, I will present the operation of a new function in my PYLAB add-in. This function is used to connect parallel pipes with a perpendicular section. Connect the pipes with one click!
The pipe joining program will help you in your daily design work. No more manual connection of pipes, all you need to do is select the elements you are interested in. When will you use it?
You draw new installations
You coordinate designed installations
You edit installations
Instruction how to install my extension you can find here.
How program work
You select the “Parallel pipe connect” function, then select two pipes and confirm with the “Finish” button.
After pressing this button, the program will insert a perpendicular segment to the selected pipes and connect them together.
Film with program use
Source code – Revit connect pipes
Below is the program code from the first version of the overlay. For more please visit mine GitHub, where new versions of the overlay will appear on a regular basis.
Python
Copyright(C)2023 Paweł Kińczyk## Importsimport mathfrom Autodesk.Revit.UI.Selection import*from Autodesk.Revit.DB import*from Autodesk.Revit.Creation import*from Autodesk.Revit.Exceptions import ArgumentExceptionfrom pyrevit import formsfrom pyrevit import revitimport clrclr.AddReference('RevitAPI')clr.AddReference('RevitAPIUI')# def / class# Custom filter to allow picking only the mentioned categoryclassCustomISelectionFilter(ISelectionFilter):def__init__(self,nom_categorie):self.nom_categorie = nom_categoriedefAllowElement(self,e):if e.Category.Name inself.nom_categorie:# if self.nom_categorie.Contains(e.Category.Name):# if e.Category.Name == self.nom_categorie:returnTrueelse:returnFalsedefAllowReference(self,ref,point):returnTrue# Pick object/objects with custom filterdefpick_objects(title="Pick",filter=""):with forms.WarningBar(title=title):return uidoc.Selection.PickObjects(ObjectType.Element,CustomISelectionFilter(filter))# Mesure distance between two pointsdefdistance(xyz1,xyz2): d =0.0 d = math.sqrt((xyz2[0]- xyz1[0])**2+(xyz2[1]- xyz1[1])**2+(xyz2[2]- xyz1[2])**2)return d# Pick right category and amount of pipes also write error when something is wrongclassPickElements:def__init__(self,title="",filter="",error_message="",max_pipes_number=100):self.title = titleself.filter =filterself.error_message = error_messageself.max_pipes_number = max_pipes_numberdefpick_pipes(self):try:self.pipes =pick_objects(title=self.title,filter=self.filter)iflen(self.pipes)>self.max_pipes_number: forms.alert(title="Program Error",msg="You picked more than {} pipes".format(self.max_pipes_number),exitscript=True)returnself.pipesexcept: forms.alert(title="Program Error",msg=self.error_message,exitscript=True)# Loop over the pipes and collect all connectorsclassGetPipeConnectors(object):def__init__(self,pipes_list):self.pipes_list = pipes_listself.connectors ={}self.connlist =[]defget_connectors(self):for pipe inself.pipes_list: pipe = doc.GetElement(pipe) conns = pipe.ConnectorManager.Connectorsfor conn in conns:if conn.IsConnected:# get only connectedcontinueself.connectors[conn]=Noneself.connlist.append(conn)# print(conn)returnself.connlist,self.connectors# Main function class that create new pipe and connect them togetherclassCreateParallelPipeAndConnect(GetPipeConnectors):def__init__(self,pipes_list,closest_distance=1000000):# Parent class is GetPipeConnectorssuper(CreateParallelPipeAndConnect,self).__init__(pipes_list=pipes_list)self.closest_distance = closest_distance# *** CODE FROM DYNAMO NODES WRITEEN BY Alban de Chasteigner https://github.com/albandechasteigner ***# Search for two closest connectors to draw pipe between themdefsearch_for_closest_connectors(self):self.closest_distance =1000000self.closest_connectors =[]for i inrange(len(self.connectors.items())):for j inrange(len(self.connectors.items())):if i != j: xyz1 =self.connectors.items()[i] xyz2 =self.connectors.items()[j] a =distance(xyz1[0].Origin, xyz2[0].Origin)# print(a)ifself.closest_distance > a:self.closest_distance = aself.closest_connectors ={ xyz1[0]:None, xyz2[0]:None}returnself.closest_connectors# *** ***# *** CODE FROM PYREVIT FORUM MANY THANKS TO Nicholas Miles https://github.com/Negazero and Jean-Marc https://github.com/jmcouffin ***# Create pipe parallel to two picked pipesdefcreate_parallel_pipe(self):# Get middle point p1 =self.closest_connectors.items()[0] p2 =self.closest_connectors.items()[1]# Create variable for connector to remove indexing and have more understandable code p1_connector = p1[0] p2_connector = p2[0]# This is the "Direction" of the connector p1_vector = p1_connector.CoordinateSystem.BasisZ p2_vector = p2_connector.CoordinateSystem.BasisZ vector_between_connectors = p1_connector.Origin.Subtract( p2_connector.Origin)# This will give us the scalar for the projected distance between connectors# Multiply 0.5 to get the midpoint of the distance between the vectors distance_between_connectors = p2_vector.DotProduct( vector_between_connectors)*0.5# Now we add the distance to both of the pipes endpointsself.p1_point = p1_connector.Origin.Add( p1_vector.Multiply(distance_between_connectors))self.p2_point = p2_connector.Origin.Add( p2_vector.Multiply(distance_between_connectors)) is_parallel =round(p1_vector.X * p2_vector.Y - p1_vector.Y * p2_vector.X)==0.0if(p1_connector.Origin.Z - p2_connector.Origin.Z)<0.0000001and is_parallel: transaction =Transaction(doc,'Create parallel pipe') transaction.Start()try: parent_pipe = doc.GetElement(self.pipes_list[0])self.new_pipe = Plumbing.Pipe.Create(doc, parent_pipe.MEPSystem.GetTypeId(), parent_pipe.GetTypeId(), parent_pipe.ReferenceLevel.Id,self.p1_point,self.p2_point) transaction.Commit()except ArgumentException: transaction.Commit() forms.alert(title="Program Error",msg="Please try to move pipes closer",exitscript=True)exceptExceptionas e: transaction.Commit()print(e)for conn inself.new_pipe.ConnectorManager.Connectors:self.closest_connectors[conn]=None# *** ***# *** CODE FROM DYNAMO NODES WRITEEN BY Alban de Chasteigner https://github.com/albandechasteigner ***# Connect all connectors togetherdefconnect_pipes(self): connlist =self.closest_connectors.keys()for k inself.closest_connectors.keys(): mindist =1000000 closest =Nonefor conn in connlist:if conn.Owner.Id.Equals(k.Owner.Id):continue dist = k.Origin.DistanceTo(conn.Origin)if dist < mindist: mindist = dist closest = connif mindist >1:continueself.closest_connectors[k]= closest connlist.remove(closest)try:delself.closest_connectors[closest]except:pass transaction =Transaction(doc,'Connect pipes - PYLAB') transaction.Start()for k, v in closest_connectors.items():try: fitting = doc.Create.NewElbowFitting(k, v) fittings.append(fitting.ToDSType(False))except:pass transaction.Commit()# *** ***doc = revit.docuidoc = revit.uidocpick_pipes =PickElements(title="Pick pipes to be connected",filter="Pipes",error_message="You didn't pick any pipe",max_pipes_number=2)pipes = pick_pipes.pick_pipes()get_pipe_connectors =CreateParallelPipeAndConnect(pipes_list=pipes,closest_distance=1000000)get_pipe_connectors.get_connectors()closest_connectors = get_pipe_connectors.search_for_closest_connectors()get_pipe_connectors.create_parallel_pipe()get_pipe_connectors.connect_pipes()
Please report any irregularities in the operation of the program that occur during use on my social accounts or account GitHub.