Hi, I’ve started use dynamo whit python, I create 3 rebars whit the API (Rebar.CreateFromCurves) in a python node, whit Output a lis of the rebar creates. Then I want to mirror it whit ElementTransformUtils.MirrorElements in othe python node taking the list of the previus node as Input. The dont get Any Error and show the Output but no rebar is showing in the model.
I’ve tried to use the same code in the first node and it worked, now i am whit the doubt of why doesnt work whit the second node. I prefer to do it in separate nodes in order to have a clean code whit my low knowledge.
This is the code for the second Node.
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import System
from System import Array
# Solo cuando voy a usar Ilist, averigiuar que libreria importar
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
# Preferible importar solo lo que se necesite
# from Autodesk.Revit.DB import Transform, XYZ
from Autodesk.Revit.DB import XYZ, ElementTransformUtils, Plane, ElementId
import Autodesk.Revit.DB.Structure as est
clr.AddReference('RevitNodes')
import Revit as rvt
import Revit.Elements as ele
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
m = 3.28084
mm = m/1000
cm = m/100
def fromElementToXYZ(element):
elementXYZ = XYZ(element.X*m, element.Y*m, element.Z*m)
return elementXYZ
doc= DocumentManager.Instance.CurrentDBDocument
vectorDirectionAdentro= UnwrapElement(IN[0])
pointArranque= UnwrapElement(IN[1])
elementLen=IN[2]*m
rebarList= UnwrapElement(IN[3])
# Inicio de transacción, solo si voy a editar elementos de revit
TransactionManager.Instance.EnsureInTransaction(doc)
# Escribir codigo
vectorXYZ = fromElementToXYZ(vectorDirectionAdentro)
vectorNorm = vectorXYZ.Normalize()
pointXYZ = fromElementToXYZ(pointArranque)
centerPoint = pointXYZ.Add(vectorNorm.Multiply(elementLen/2))
plane = Plane.CreateByNormalAndOrigin(vectorNorm, pointXYZ)
IdList = List[ElementId]()
for rebar in rebarList:
id = rebar.Id
IdList.Add(id)
#respuesta=ElementTransformUtils.CanMirrorElements(doc,IdList)
copiedBarsId=ElementTransformUtils.MirrorElements(doc, IdList, plane, True)
TransactionManager.Instance.TransactionTaskDone()
# Salida
OUT=copiedBarsId
there is a picture of the dynamo
Finaly there is the first node whit the same code.
for div in divisiones:
divSplit = div.split('@')
numero= divSplit[0]
espaciado= float(divSplit[1])*cm
desp = despAcom + espaciado
rebar:est.Rebar= est.Rebar.CreateFromCurves(doc, rebarStyle, rebarType, hookType, hookType, hostElement ,vectorXYZ, curvaList, hookOrientation, hookOrientation, True, True)
rebarList.append(rebar)
if numero == 'R':
#solo quedan los restantes, calcular la longitud que queda
lRestante = totalRebarLen/2 - despAcom
numeroResto = math.floor(lRestante/espaciado)
#set el layout
accesor= rebar.GetShapeDrivenAccessor()
accesor.SetLayoutAsNumberWithSpacing(numeroResto, espaciado, True, True, True)
elif numero == '1':
numero = int(numero)
despAcom += numero*espaciado
pass
else:
#set el layout
numero = int(numero)
accesor= rebar.GetShapeDrivenAccessor()
accesor.SetLayoutAsNumberWithSpacing(numero, espaciado, True, True, True)
despAcom += numero * espaciado
rebarMove = vectorXYZNorm.Multiply(desp)
ElementTransformUtils.MoveElement(doc, rebar.Id, rebarMove)
# Until this line the original node was code
#Star Mirror, is not in the first version
point = lineas[0].StartPoint
pointXYZ= XYZ(point.X*m, point.Y*m, point.Z*m)
plane= Plane.CreateByNormalAndOrigin(vectorXYZNorm, pointXYZ)
IdList = List[ElementId]()
for rebar in rebarList:
IdList.Add(rebar.Id)
copiedBarsId=ElementTransformUtils.MirrorElements(doc, IdList, plane, True)
# end of the Mirror
TransactionManager.Instance.TransactionTaskDone()
# Salida
OUT=rebarList