tt-acm / DynamoForRebar

A Dynamo package for authoring geometrically complex rebar models in Revit 2016.
Other
39 stars 18 forks source link

Rebar.SetSolidInView does not work with elements selected in dynamo #72

Closed eibre closed 5 years ago

eibre commented 8 years ago

(Dynamo 1.0, Revit 2017, Win 10)

Rebar.SetSolidInView does only work with rebars created with Rebar.ByCurve. It might have something to do with the types of the elements. The rebar elements that are selected in Dynamo returns UnkownElement by the type node, but Rebar.ByCurve are returned as Rebar.

image

I use python script that works:

import clr

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

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument

#Preparing input from dynamo to revit
rebarElements = UnwrapElement(IN[0])
views = UnwrapElement(IN[1])

#Change rebar in transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for view in views:
    for rebarElement in rebarElements:
        rebarElement.SetSolidInView(view,1)
TransactionManager.Instance.TransactionTaskDone()

OUT = rebarElements
moethu commented 8 years ago

@eibre thanks for reporting this. Yes there is no element wrapper for Rebar because its not part of the DynamoRevit core. We will either move it there or I will supply a node that allows you to translate the elements into rebars.

eibre commented 8 years ago

@moethu Thank you, I guess it's the same with the other nodes that take rebar as input: image

eibre commented 7 years ago

The best option would be to create a Rebar wrapper in DynamoRevit.

For now I have followed your other suggestion and created a node for it. Is this the best way to do it? Unwrapping and rewrapping. image

        /// <summary>
        ///  By existiing Element
        /// </summary>
        /// <param name="element">Existing Rebar Element</param>
        public static Revit.Elements.Rebar ByExistingElement(Revit.Elements.Element element)
        {
            return Rebar.FromExisting((Autodesk.Revit.DB.Structure.Rebar) element.InternalElement,true);
        }
GiorgioBurbanelli89 commented 1 month ago

I tried with Iron python and the help of IA chat gpt to create a rebar reinforcement in beams in iron python but from where I leave in text the code I can not continue I have some problem why I can not continue the code if anyone has any example of a beam creating the rebar strirrup would be of great help thanks. import clr clr.AddReference('ProtoGeometry') clr.AddReference('RevitServices') clr.AddReference('RevitAPI') clr.AddReference('RevitAPIUI') clr.AddReference('RevitNodes') clr.AddReference("System")

import Revit clr.ImportExtensions(Revit.GeometryConversion) clr.ImportExtensions(Revit.Elements)

from Autodesk.DesignScript.Geometry import from Autodesk.Revit.DB import from Autodesk.Revit.DB.Structure import * from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager from System.Collections.Generic import List

Obtener el documento de Revit activo

doc = DocumentManager.Instance.CurrentDBDocument

Obtener el elemento seleccionado de la entrada (asegúrate de seleccionar un elemento en Dynamo)

element = UnwrapElement(IN[0])

Definir el diámetro del refuerzo y el espaciado entre estribos

diametro_refuerzo = 0.012 # Diámetro en metros espaciado_estribo = 0.1 # Espaciado en metros

Obtener la geometría del elemento y extraer las curvas

geometria_elemento = element.get_Geometry(Options()) curvas = [] for obj_geom in geometria_elemento: if isinstance(obj_geom, Solid): for borde in obj_geom.Edges: curva = borde.AsCurve() curvas.append(curva)

Suponiendo que la primera curva es la que se va a usar (ajustar según sea necesario)

curva = curvas[0] punto_inicial = curva.GetEndPoint(0) punto_final = curva.GetEndPoint(1)

Calcular la longitud del elemento

longitud_elemento = curva.Length

Crear estribos a lo largo del elemento

estribos = [] for i in range(int(longitud_elemento / espaciado_estribo) + 1): factor = i espaciado_estribo / longitud_elemento posicion_estribo = XYZ( punto_inicial.X + (punto_final.X - punto_inicial.X) factor, punto_inicial.Y + (punto_final.Y - punto_inicial.Y) factor, punto_inicial.Z + (punto_final.Z - punto_inicial.Z) factor ) estribos.append(posicion_estribo)

Paso 6: Crear estribos en Revit

TransactionManager.Instance.EnsureInTransaction(doc)

Obtener el tipo de barra de refuerzo

rebar_type = FilteredElementCollector(doc).OfClass(RebarBarType).FirstElement() """

Lista para almacenar los estribos creados

created_rebars = [] for pos in estribos: rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, rebar_type, None, None, element, pos, XYZ.BasisX, XYZ.BasisY, False, True) created_rebars.append(rebar)

TransactionManager.Instance.TransactionTaskDone()

Configurar los estribos para que se muestren como sólidos en las vistas

views = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc) for view in views: for rebarElement in created_rebars: rebarElement.SetSolidInView(view, 1) TransactionManager.Instance.TransactionTaskDone()

Salida: Estribos creados

OUT = created_rebars """