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()
1 Like

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