Create electrical wire from linesCreate electrical wire from lines

hai.
anyone help me how to Create electrical wire from lines in Revit dynamo have created chamfare wire but i have to convert the line to electrical wire

hi
there is a code in revit api we can use it

api

i have for this example two socket with detail lines between them

this is my sample code you code start from it

the main code:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *


clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('System')
from System.Collections.Generic import List

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)


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

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


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

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

from System.Collections.Generic import *


wiretypeid=UnwrapElement(IN[0]).Id
viewid=UnwrapElement(IN[1]).Id
wiringtype= UnwrapElement(IN[2])
verpt= UnwrapElement(IN[3])
sconn= UnwrapElement(IN[4])
econn= UnwrapElement(IN[5])

verptxyz=[]
for v in verpt:
	verptxyz.append(v.ToXyz(True))

TransactionManager.Instance.EnsureInTransaction(doc)

errorReport=[]
try:
	wireN=[]
	wireN.append(Autodesk.Revit.DB.Electrical.Wire.Create(doc,wiretypeid,viewid,wiringtype,verptxyz,sconn,econn))
	OUT = wireN
except: 
	import traceback
	errorReport = traceback.format_exc()
	OUT = errorReport
TransactionManager.Instance.TransactionTaskDone()

for the wire type code:

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

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

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

import Autodesk
from Autodesk.Revit.DB.Electrical import *
import System

wt = FilteredElementCollector(doc).OfClass(WireType)
wtn=[]
wte=[]
for w in wt:
	wtn.append(Element.Name.GetValue(w))
	wte.append(w)
	
OUT = wtn,wte

for wiringtype code:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB.Electrical import *
import System


#Assign your output to the OUT variable
OUT = System.Enum.GetValues(WiringType)

and the final result is like this

3 Likes

Thank you so much.

I have modified something have look once is it okay?

find the attached dynamo script

best regards

Tanveer

in this way i strongly recommend to start the process run circuit by circuit … not for all categories at once … because it will be completed and hard to find errors … by practices you could find a better way to run all over the project

okay thank you

Hello,

I successfully used your scripts, feeding points for creating the wire vertices (by using detail lines, then a node to Group them if they touch, then turn them to PolyCurves to get the vertex order right), the only problem i have is when i actually connect the wire to a device:

when the wire connects to a device the vertices at the ends of the wire will jump around somewhere between the 3d symbol of the device and the 2d symbol .

When you draw a wire in revit, connect it to 2 devices, the end Vertices will jump on the 2d / in the air / i don’t know where.
If you manually drag them, you can place them ANYWHERE and the wire will still be connected.

So after the wire is created in the Python Scrip and the Start and End Vertices “jump” onto the 2d symbol I want to adjust their position using Wire.SetVertex(Index, XYZ) to place them near the ends of the PolyCurve which provided the Vertices for creating the Wire.

Something like:
have Start & End vertex be set at the position (X+0.5, Y, Z) of the Start & End points of the PolyCurve from which the wire was created. So the wire will keep true to the PolyCurve which “generated” it. And cabling will be very nice and tidy.

I can get these X,Y,Z values from StarPoint and EndPoint node applied to the source PolyCurve, and try to set them using the XYZ(Double, Double, Double) constructor.

Since i cannot overlap 2 vertices i add 0.5 to the X value of the Start, End vertices extracted from the PolyCurve.

so:
Wire.SetVertex(0, XYZ(X+0.5, Y, Z)) - for the Start Point of the wire, index 0, X,Y,Z from XYZ constructor are extracted from the Start Point node.

then:
Wire.SetVertex(count, XYZ(X+0.5, Y, Z)) - for the End Point of the wire, count = wire.NumberOfVertices - 1, X,Y,Z are extracted from End Point of PolyCurve wire vertices were made from.

The results are laughable… i think the start vertex does not move / i don’t know / it acts in the same manner, but the end one goes Crazy, they radiate out from my area of devices , far away from the building… SO…definitely NOT working…

I am a noob in Dyn, zero xp in Python, but with some programming basic knowledge in Java…
And i kept going at this and cannot sort it … so please, this sounds like it is so easy to achieve, this would be my greatest work (by using other peoples’ python code… shame on me :smiley: )…

Here is a pic of the custom node (cause i take a list of PolyCurves and I want to process each one from the list):

Here is the code with the Wire constructor, where i attempt setting the positions of Start + End wire vertices i am not very sure how to format it here… :

    import clr
    clr.AddReference('ProtoGeometry')
    from Autodesk.DesignScript.Geometry import *


    clr.AddReference("RevitServices")
    import RevitServices
    from RevitServices.Persistence import DocumentManager
    from RevitServices.Transactions import TransactionManager

    clr.AddReference('System')
    from System.Collections.Generic import List

    import sys
    pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
    sys.path.append(pyt_path)


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

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


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

    doc = DocumentManager.Instance.CurrentDBDocument
    uiapp = DocumentManager.Instance.CurrentUIApplication
    app = uiapp.Application

    from System.Collections.Generic import *


    wiretypeid=UnwrapElement(IN[0]).Id
    viewid=UnwrapElement(IN[1]).Id
    wiringtype= UnwrapElement(IN[2])
    verpt= UnwrapElement(IN[3])
    sconn= UnwrapElement(IN[4])
    econn= UnwrapElement(IN[5])

#IN[6] and below are all Lists…
newStartX = IN[6]
#the above X value has 0.5 already added to it
newStartY = IN[7]
newStartZ = IN[8]
newEndX = IN[9]
#the above X value has 0.5 already added to it
newEndY = IN[10]
newEndZ = IN[11]

    verptxyz=[]
    for v in verpt:
    	verptxyz.append(v.ToXyz(True))

    TransactionManager.Instance.EnsureInTransaction(doc)

    errorReport=[]
    try:
    	
    	
    	w = Autodesk.Revit.DB.Electrical.Wire.Create(doc,wiretypeid,viewid,wiringtype,verptxyz,sconn,econn)
    	
    	w.SetVertex(0, XYZ(newStartX[0],newStartY[0],newStartZ[0]))
    	
    	lastvertIndex = w.NumberOfVertices - 1
    	w.SetVertex(lastvertIndex, XYZ(newEndX[0],newEndY[0],newEndZ[0]))
    		
    	
    	OUT = w
    except: 
    	import traceback
    	errorReport = traceback.format_exc()
    	OUT = errorReport
    TransactionManager.Instance.TransactionTaskDone()
2 Likes

HI, I can’t find (Select Detail Item) in dynamo, please
thansks much

Hello,
use ‘Select Model Element’ OOTB node (the node has been renamed in the graph)

2 Likes

THANKS, select model element

Hi Khuzaimah,
Would you please share your dynamo sample for this code?

Dear Sir this code only suitable for convert only one line to wire.
I try to convert multiple lines to wire but it’s convert like new one wire create connect each line end points. I attached image for your reference kindly give me solution for it sir.

just you need to iterate the code like this

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('System')
from System.Collections.Generic import List

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

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

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


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

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

from System.Collections.Generic import *


wiretypeid=UnwrapElement(IN[0]).Id
viewid=UnwrapElement(IN[1]).Id
wiringtype= UnwrapElement(IN[2])
verpt= UnwrapElement(IN[3])
sconn= UnwrapElement(IN[4])
econn= UnwrapElement(IN[5])


OUTr=[]
TransactionManager.Instance.EnsureInTransaction(doc)

for i in range(0,len(verpt)):
	verptxyz=[]
	for v in verpt[i]:
		verptxyz.append(v.ToXyz(True))
	errorReport=[]
	try:
		wireN=[]
		wireN.append(Autodesk.Revit.DB.Electrical.Wire.Create(doc,wiretypeid,viewid,wiringtype,verptxyz,sconn[i],econn[i]))
		OUTr.append(wireN)
	except: 
		import traceback
		errorReport = traceback.format_exc()
		OUTr.append(errorReport)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = OUTr,len(verpt)
2 Likes

Dear Sir,
Line No. 59 have some issues. I given below,

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 54, in
TypeError: iteration over non-sequence of type Point.

This is line No. 59 - for v in verpt[i]:

Kindly help me to fix this warning sir

Dear Sir,

can you give the example dynamo code and nodes for converting detailed line to wire.

hi,
see the dyn below, make sure you set Dynamo to get the dyf files too.
image

how the script works:
select detail lines (ex. a lot of them, it takes the current selection so select all and filter “detail lines” of the type you use)
it will see which are touching (continuous lines)
convert them to polycurves
gets their vertices
uses wires constructor to generate wires from above vertices
finds 3d devices in a cuboid at start and end of polycurves
connect ends of wires to found devices
move start and end vertices of wires to start & end of polycurves.

the comments are in romanian but you should understand stuff just by watching the dynamo flow from left to right.
or translate the comments using google translate…

You will need some packages,like spring nodes, gorila 17, dynamo will complain, install them and it should be ok.

wires_from_detail_lines_rev1.dyn (61.1 KB)
WiresOnJointDetailLinePaths 9.dyf (57.3 KB)
moveWireEndVertices 4.dyf (28.8 KB)

1 Like