here is the code but when run have nothing happen
import clr
clr.AddReference(‘RevitAPI’)
clr.AddReference(‘RevitAPIUI’)
from Autodesk.Revit.DB import *
clr.AddReference(‘RevitServices’)
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
Inputs
componentTypeIds = UnwrapElement(IN[0]) # The ElementIds of the Legend Component types
legendView = UnwrapElement(IN[1]) # The Legend view element
coordinates = UnwrapElement(IN[2]) # The XYZ coordinates for placing the Legend Components
Output
outLegendView = None # The modified Legend view element with the Legend Components placed
Start transaction
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
Get the appropriate Legend view
if isinstance(legendView, View):
legendView = doc.GetElement(legendView.Id)
else:
# Handle the case when the specified Legend view is not valid
pass
Set the view direction parameter to “Elevation:Front”
paramName = “View direction” # Adjust the parameter name as per your component type
paramValue = “Elevation:Front” # Adjust the parameter value as per your component type
Add the Legend Components to the Legend view
if legendView and componentTypeIds and coordinates:
if isinstance(componentTypeIds, list) or isinstance(componentTypeIds, System.Array):
for i in range(len(componentTypeIds)):
typeId = componentTypeIds[i]
if isinstance(typeId, ElementId):
# Retrieve the FamilySymbol from the ElementId
componentType = doc.GetElement(typeId)
if isinstance(componentType, FamilySymbol):
# Set the “View direction” parameter to “Elevation:Front”
if componentType.LookupParameter(paramName):
componentType.LookupParameter(paramName).Set(paramValue)
# Create a placement point for the FamilyInstance
position = coordinates[i] if i < len(coordinates) else XYZ.Zero
# Place the existing Legend Component in the Legend view
legendView.AddLegendComponent(componentType, position)
elif isinstance(componentTypeIds, ElementId):
# Retrieve the FamilySymbol from the single ElementId
componentType = doc.GetElement(componentTypeIds)
if isinstance(componentType, FamilySymbol):
# Set the "View direction" parameter to "Elevation:Front"
if componentType.LookupParameter(paramName):
componentType.LookupParameter(paramName).Set(paramValue)
# Create a placement point for the FamilyInstance
position = coordinates[0] if coordinates else XYZ.Zero
# Place the existing Legend Component in the Legend view
legendView.AddLegendComponent(componentType, position)
Commit transaction
TransactionManager.Instance.TransactionTaskDone()
Assign modified Legend view element to output
outLegendView = legendView
Return output
OUT = outLegendView, componentTypeIds