# Cant place Door Legend component into Legend view with Python script

**URL:** <https://forum.dynamobim.com/t/cant-place-door-legend-component-into-legend-view-with-python-script/91005>\
**Category:** Revit\
**Tags:** revit, python, dynamo\
**Created:** [June 22, 2023, 4:52am UTC](https://forum.dynamobim.com/t/cant-place-door-legend-component-into-legend-view-with-python-script/91005 "2023-06-22T04:52:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericke1](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@ericke1](https://forum.dynamobim.com/u/ericke1)\
**Post date:** [June 22, 2023, 4:52am UTC](https://forum.dynamobim.com/t/cant-place-door-legend-component-into-legend-view-with-python-script/91005/1 "2023-06-22T04:52:19Z")

</div>

here is the code but when run have nothing happen

 ![1687409509821](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/6/962adda1b85d73c136b49b073cc48e95c9ada780.jpeg)

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

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [June 22, 2023, 6:48am UTC](https://forum.dynamobim.com/t/cant-place-door-legend-component-into-legend-view-with-python-script/91005/2 "2023-06-22T06:48:34Z")

</div>

@ericke1 ,

i have not a solution i cleaned up your code as good as possible

```auto
import clr
import sys
import System

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI 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
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#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
transaction = Transaction(doc, "Place Legendcomponent on Legend")
transaction.Start()

#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 the transaction
transaction.Commit()

outLegendView = legendView
#Return output

OUT = outLegendView, componentTypeIds

```

there are issues with blocks

KR

Andreas

---

<div class="post-metadata">

**Author:** ![ericke1](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@ericke1](https://forum.dynamobim.com/u/ericke1)\
**Post date:** [June 22, 2023, 7:20am UTC](https://forum.dynamobim.com/t/cant-place-door-legend-component-into-legend-view-with-python-script/91005/3 "2023-06-22T07:20:54Z")

</div>

I give up

---

<div class="post-metadata">

**Author:** ![ericke1](https://avatars.discourse-cdn.com/v4/letter/e/ebca7d/32.png) [@ericke1](https://forum.dynamobim.com/u/ericke1)\
**Post date:** [June 22, 2023, 7:29am UTC](https://forum.dynamobim.com/t/cant-place-door-legend-component-into-legend-view-with-python-script/91005/4 "2023-06-22T07:29:03Z")

</div>

```auto
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
familyTypes = UnwrapElement(IN[0]) # The Family types (FamilySymbol instances)
legendView = UnwrapElement(IN[1]) # The Legend view element

# Output
outLegendView = None # The modified Legend view element with the Detail Items 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

# Add the Detail Items to the Legend view
if legendView and familyTypes:
    if isinstance(familyTypes, list) or isinstance(familyTypes, System.Array):
        for familyType in familyTypes:
            if isinstance(familyType, FamilySymbol):
                # Create a FamilyInstance of the FamilySymbol
                detailItemElement = doc.Create.NewFamilyInstance(XYZ.Zero, familyType, legendView)
    elif isinstance(familyTypes, FamilySymbol):
        # Create a FamilyInstance of the FamilySymbol
        detailItemElement = doc.Create.NewFamilyInstance(XYZ.Zero, familyTypes, legendView)

# Commit transaction
TransactionManager.Instance.TransactionTaskDone()

# Assign modified Legend view element to output
outLegendView = legendView

# Return output
OUT = outLegendView, familyTypes

```

For this code it can place Item component to legend view i dont know why
