Errors When Batch Creating Elevation Views

I have built a script to batch create elevation views for exterior windows/doors. The script determines which way the element(s) are facing and positions the views appropriately, then it crops the views to match the elements’ bounding box, sets the view template for each view, and renames the views to match the mark value of the elements.

The script works on two projects that I have tested it on, but on a third project I receive errors stating that the view names are already in use. Once these errors appear the script stops. I have confirmed that elevations with those names don’t already exist before running the script, and I’ve even tried deleting every elevation view in the project prior to running it as well. But I still receive the same errors.

Does anybody have any idea what could be causing this? Any help is greatly appreciated!

image

Hey,

It’s hard to tell without a sample file, if you have successfully run the graph, then it is likely to be due to extra complexity in the project file…

Perhaps you have 2 elements with the same Mark? So then it tries to create 2 views with the same name? I don’t think your graph checks for that?

Hopefully that is useful :slight_smile:

Mark

Thanks Mark.

You are correct that my graph doesn’t check for elements with the same Mark value. (To be added later.) But I do not think that is what is causing the errors since the elevation views are created first and then renamed. Also, the errors I am receiving seem to be having issues with the default elevation names being the same. You are probably right about it being something to do with the project itself since I am only seeing these errors in this specific project so far.

1 Like

Hi,

Yeah, it think I would try and work back, freezing nodes as you go… Output lots of values and identify 1 view that is causing the error… Then iteratively work out potential solutions… It will probably be a slog but I’m sure you’ll get there :slight_smile:

Cheers,

Mark

Hi Everybody.
In regards to the same situation, i have the img nodes script programmed. The goal of this script, is to create elevation views aligned to some selected walls.
However, the final nodo (a pythonscript one), creates the elevation views, on the middle point of the walls, but not aligned to the wall.

Can anybody help me to understand why this is happening? Thanks in advance.

Python script:
import clr
import sys
clr.AddReference(‘RevitAPI’)
clr.AddReference(‘RevitServices’)
clr.AddReference(‘RevitNodes’)

from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Revit.GeometryConversion import *

Entradas

walls = UnwrapElement(IN[0])
model_lines = UnwrapElement(IN[1]) # Las líneas de modelo asociadas a cada muro

Depuración: Verificar tipo de center_points

print(“Tipo de IN[2]:”, type(IN[2]))
print(“Contenido de IN[2]:”, IN[2])

Asegurarse de que los puntos se convierten correctamente

center_points =
for p in IN[2]:
print(“Tipo de punto:”, type(p))
if hasattr(p, ‘ToXyz’):
center_points.append(p.ToXyz())
else:
center_points.append(XYZ(p.X, p.Y, p.Z))

view_names = IN[3] # Lista de strings
view_type = UnwrapElement(IN[4])

Documento de Revit

doc = DocumentManager.Instance.CurrentDBDocument

Depuración: Imprimir los tipos de entradas y su longitud

print(“walls:”, type(walls), len(walls))
print(“model_lines:”, type(model_lines), len(model_lines))
print(“center_points:”, type(center_points), len(center_points))
print(“view_names:”, type(view_names), len(view_names))
print(“view_type:”, type(view_type))

Función para crear una vista de elevación ortogonal al muro

def create_elevation_view(wall, model_line, center, name, type_id):
try:
location_curve = wall.Location.Curve
mid_point = location_curve.Evaluate(0.5, True)

    # Crear un marcador de elevación
    elevation_marker = ElevationMarker.CreateElevationMarker(doc, type_id, mid_point, 100)
    
    # Crear la vista de elevación
    view = elevation_marker.CreateElevation(doc, doc.ActiveView.Id, 0)
    view.Name = name
    
    # Calcular la dirección de la vista a partir de la línea de modelo
    start_point = model_line.GeometryCurve.GetEndPoint(0)
    end_point = model_line.GeometryCurve.GetEndPoint(1)
    direction = (end_point - start_point).Normalize()

    # Ajustar la dirección de la vista
    transform = Transform.Identity
    transform.Origin = center
    transform.BasisZ = direction

    # Posicionar la vista en el marcador
    elevation_marker.Location.Point = transform.Origin

    # Activar el recorte de la vista
    view.CropBoxActive = True

    return view
except Exception as e:
    print("Error en create_elevation_view:", e)
    return None

Iniciar transacción

TransactionManager.Instance.EnsureInTransaction(doc)

Crear vistas para cada muro

views =
for i, wall in enumerate(walls):
try:
model_line = model_lines[i]
center = center_points[i]
name = view_names[i]
view = create_elevation_view(wall, model_line, center, name, view_type.Id)
if view:
views.append(view)
except Exception as e:
print(“Error en bucle principal:”, e)

Finalizar transacción

TransactionManager.Instance.TransactionTaskDone()

Salida

OUT = views

Elevation Views Creation.dyn (80.4 KB)

Also, i attached the dyn file. It have to work with any file with walls selected. Take into account the IN4 imput of the pythonscript, is a type of elevation that you need to have created on the RVT file for test.

Thanks