Python error: Creating Chamfered Wires with python

python

#1

Hi

I am trying to create chamfered wires with dynamo, inputing connectors, and vertexpoints etc.
I have made the python script to create the wires myself, and I cannot get it to work.
When I try to run the script I get a peculiar error.

image

What causes this error, and is it possible to work around it?

Here is the python script (code pasted in bottom of post), along with the relevant inputs from the graph:

 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
 from System.Collections.Generic import *

 clr.AddReference('RevitNodes')
 import Revit
 clr.ImportExtensions(Revit.Elements)

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

 clr.AddReference('DSCoreNodes')
 import DSCore
 from DSCore.List import *

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

 connectors = IN[0]
 vrtxpts = UnwrapElement(IN[1])
 wiretyp = UnwrapElement(IN[2])
 curview = UnwrapElement(IN[3])

 doc = DocumentManager.Instance.CurrentDBDocument
 wireTypeId = wiretyp[0].Id
 view = curview.Id
 wiringType = WiringType.Chamfer
 vertexPts = vrtxpts
 sConnector = connectors[0]
 eConnector = connectors[1]

 TransactionManager.Instance.EnsureInTransaction(doc)
 OUT = Wire.Create(doc,wireTypeId,view,wiringType,vertexPts,sConnector,eConnector)
 TransactionManager.Instance.TransactionTaskDone()

Thanks for your inputs :slight_smile:


Create a Chamfered Wire with Pythom
#2

Without look at the rest of your code I would say that it might be because the OUT is caught in a transaction. I would put the OUT part after the transaction. assign the Wire.Create to a variable instead of OUT.


#3

Thanks. Tried to do that, but I still get the same error, on the same line.


#4

It seems that it expects a generic collection List as input for the vertex points. Also you need to convert the Dynamo points to Revit points. You could try this for the vertextpoints:

from System.Collections.Generic import List

 #convert the dynamo points to Revit XYZ points:
 points = [x.ToXyz() for x in IN[0]]
 #put the points in a generic List:
 vertexpoints = List[XYZ](points)

#6

It worked! :smiley: Thank you!
I just forgot to import geometry conversions.


#7

What would be the node based approach to this task instead of using Python script?
I am not a code writer


#8

The RIE package has a node for drawing wires. There is also a node for chamfered wires with input vertexpoints, but I am not sure if that one is working optimally.