# Create electrical wire from linesCreate electrical wire from lines

**URL:** <https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259>\
**Category:** Revit\
**Tags:** dynamo\
**Created:** [July 12, 2019, 2:36pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259 "2019-07-12T14:36:04Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thanveer\_Magicad](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@Thanveer\_Magicad](https://forum.dynamobim.com/u/Thanveer_Magicad)\
**Post date:** [July 12, 2019, 2:36pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/1 "2019-07-12T14:36:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![khuzaimah.ElecEng](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/khuzaimah.eleceng/32/92768_2.png) [@khuzaimah.ElecEng](https://forum.dynamobim.com/u/khuzaimah.ElecEng)\
**Post date:** [July 14, 2019, 8:46pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/2 "2019-07-14T20:46:02Z")

</div>

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

![api](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/5/b5c0367d9819c6e8b169f0ccf3722f367602d937.png)

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

 ![smaple%20b](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/b/7bf77f1a88e66c22b1c7ad8853f4b7844e7406db.png)

this is my sample code you code start from it

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/3/633b167fa8a7fe8cf815d5ad8c61cfc25856c2d5.png)

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

 ![smaple%20a](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/2/7205e2f2696aaf90f96ff0138c89738bac66e7fa.png)

---

<div class="post-metadata">

**Author:** ![Thanveer\_Magicad](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@Thanveer\_Magicad](https://forum.dynamobim.com/u/Thanveer_Magicad)\
**Post date:** [July 21, 2019, 9:43am UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/3 "2019-07-21T09:43:58Z")

</div>

Thank you so much.

I have modified something have look once is it okay?

find the attached dynamo script

best regards

Tanveer

---

<div class="post-metadata">

**Author:** ![khuzaimah.ElecEng](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/khuzaimah.eleceng/32/92768_2.png) [@khuzaimah.ElecEng](https://forum.dynamobim.com/u/khuzaimah.ElecEng)\
**Post date:** [July 22, 2019, 6:25am UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/4 "2019-07-22T06:25:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thanveer\_Magicad](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@Thanveer\_Magicad](https://forum.dynamobim.com/u/Thanveer_Magicad)\
**Post date:** [July 26, 2019, 5:33pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/5 "2019-07-26T17:33:19Z")

</div>

okay thank you

---

<div class="post-metadata">

**Author:** ![bogdan.petrescu63URX](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bogdan.petrescu63URX](https://forum.dynamobim.com/u/bogdan.petrescu63URX)\
**Post date:** [April 15, 2021, 8:32pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/7 "2021-04-15T20:32:12Z")

</div>

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 😃 )…

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):

 ![Custom Node](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/7/e7c67fd77d4aa019067060ec485af80cfafc4d7a.png)

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()
```

---

<div class="post-metadata">

**Author:** ![saber.monia](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@saber.monia](https://forum.dynamobim.com/u/saber.monia)\
**Post date:** [November 12, 2021, 12:07pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/8 "2021-11-12T12:07:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [November 12, 2021, 12:40pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/9 "2021-11-12T12:40:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![saber.monia](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@saber.monia](https://forum.dynamobim.com/u/saber.monia)\
**Post date:** [November 12, 2021, 1:28pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/10 "2021-11-12T13:28:55Z")

</div>

THANKS, select model element

---

<div class="post-metadata">

**Author:** ![Nature](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@Nature](https://forum.dynamobim.com/u/Nature)\
**Post date:** [December 18, 2021, 8:23am UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/12 "2021-12-18T08:23:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ranjitranju87](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@ranjitranju87](https://forum.dynamobim.com/u/ranjitranju87)\
**Post date:** [February 13, 2023, 1:02pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/13 "2023-02-13T13:02:28Z")

</div>

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.

 ![Line to wire](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/4/e440ddfa6b71d16107d27885eb40182c3a55db09.png)

---

<div class="post-metadata">

**Author:** ![khuzaimah.ElecEng](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/khuzaimah.eleceng/32/92768_2.png) [@khuzaimah.ElecEng](https://forum.dynamobim.com/u/khuzaimah.ElecEng)\
**Post date:** [February 13, 2023, 2:18pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/14 "2023-02-13T14:18:32Z")

</div>

just you need to iterate the code like this

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![ranjitranju87](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@ranjitranju87](https://forum.dynamobim.com/u/ranjitranju87)\
**Post date:** [February 14, 2023, 7:10am UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/15 "2023-02-14T07:10:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ranjitranju87](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@ranjitranju87](https://forum.dynamobim.com/u/ranjitranju87)\
**Post date:** [February 15, 2023, 12:13pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/16 "2023-02-15T12:13:34Z")

</div>

Dear Sir,

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

---

<div class="post-metadata">

**Author:** ![bogdan.petrescu63URX](https://avatars.discourse-cdn.com/v4/letter/b/839c29/32.png) [@bogdan.petrescu63URX](https://forum.dynamobim.com/u/bogdan.petrescu63URX)\
**Post date:** [February 15, 2023, 12:59pm UTC](https://forum.dynamobim.com/t/create-electrical-wire-from-linescreate-electrical-wire-from-lines/38259/17 "2023-02-15T12:59:08Z")

</div>

> [@ranjitranju87](#):
>
> des for converting detailed line to

hi,  
see the dyn below, make sure you set Dynamo to get the dyf files too.  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/a/2a47ed3dd63f920b1067d76bb83138267948cbfb.png)

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](https://forum.dynamobim.com/uploads/short-url/6w5JmMc0kvgHfcwxOlKDgMsL2J1.dyn) (61.1 KB)  
[WiresOnJointDetailLinePaths 9.dyf](https://forum.dynamobim.com/uploads/short-url/2dAYrubvqJhZUjgPF9kpwuzUcUG.dyf) (57.3 KB)  
[moveWireEndVertices 4.dyf](https://forum.dynamobim.com/uploads/short-url/d1EymKPVa850zj4YugYONRHJ2H5.dyf) (28.8 KB)
