# Python script doesn't work in Revit 2023

**URL:** <https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909>\
**Category:** Uncategorized\
**Created:** [December 8, 2022, 11:02am UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909 "2022-12-08T11:02:28Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [December 8, 2022, 11:02am UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/1 "2022-12-08T11:02:28Z")

</div>

Hi guys,

Is there something change inside Revit 2023 at the BuiltinCategorys?  
This script works fine in R20-22 but it is broken in R23.

I created this script in IronPython2.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/5/65a9744e236d7bb2c30d86226b9538bc549455a6.png)

```auto
import clr #.NET Laden
import sys #sys is de fundamentele Python bibliotheek
#de standaard IronPython-bibliotheken
#sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib') #Imports the
#standaard IronPython-bibliotheken, die alles dekken, van servers en
#encryptie tot reguliere expressies.
import System #The System namespace in de hoofdmap .NET
from System import Array #.NET class voor het verwerken van array-informatie
import System.Collections.Generic as MGen #Module kan nu benaderd worden met MGen.xxxx
#from System.Collections.Generic import * #Hiermee kunt u generieke afhandelen. Revit's API
#soms wil hard-getypte 'generieke' lijsten, genaamd ILists. Als je niet nodig hebt
#deze kunt u deze regel verwijderen.
clr.AddReference('ProtoGeometry') #Een Dynamo-bibliotheek voor zijn proxygeometrie
#classes. Je hebt dit alleen nodig als je interactie hebt met geometrie.
import Autodesk.DesignScript.Geometry as AGeo #Module kan worden opgeroepen a=met AGeo.xxxx
#from Autodesk.DesignScript.Geometry import * #Laadt alles in Dynamo's
#geometriebibliotheek
clr.AddReference("RevitNodes") #Dynamo's nodes voor Revit
import Revit #Laad in de Revit-namespaces in RevitNodes
clr.ImportExtensions(Revit.Elements) #Meer laden van Dynamo's Revit-bibliotheken
clr.ImportExtensions(Revit.GeometryConversion) #Meer laden van Dynamo's
#Revit-bibliotheken. Je hebt dit alleen nodig als je interactie hebt met geometrie.
clr.AddReference("RevitServices") #Dynamo's classes voor het omgaan met Revit-documenten
import RevitServices 
from RevitServices.Persistence import DocumentManager #Een interne Dynamo class
#dat het document bijhoudt waaraan Dynamo momenteel is gekoppeld
from RevitServices.Transactions import TransactionManager #Een Dynamo class voor
#transacties openen en sluiten om de database van het Revit-document te wijzigen

clr.AddReference("RevitAPI") #Verwijzing naar Revit's API DLL's toevoegen
clr.AddReference("RevitAPIUI") #Verwijzing naar Revit's APIUI DLL's toevoegen

import Autodesk #Loads the Autodesk namespace
import Autodesk.Revit.DB as RDB #Loading Revit's API UI classes module kan nu worden aangeroepen met RDB.xxxx
#from Autodesk.Revit.DB import * #Loading Revit's API UI classes
import Autodesk.Revit.UI as RUI # Loading Revit's API UI classes als RUI.xxxx
#from Autodesk.Revit.UI import * #Loading Revit's API UI classes

doc = DocumentManager.Instance.CurrentDBDocument #Dit is het actieve Revit document
uiapp = DocumentManager.Instance.CurrentUIApplication #Een handle instellen voor het actieve Revit UI-document
app = uiapp.Application #Een handle instellen op de momenteel geopende instantie van de Revit-toepassing
uidoc = uiapp.ActiveUIDocument #Een handle instellen op de momenteel geopende instantie van de Revit UI-toepassing

# einde code omrekenen revit feet naar huidig ingestelde document units
# Hieronder kan je dan gaan programmeren
# Gebruik boiler template

cat_list = [RDB.BuiltInCategory.OST_ElectricalFixtureTags, RDB.BuiltInCategory.OST_DataDeviceTags, RDB.BuiltInCategory.OST_CommunicationDeviceTags]
typed_list = MGen.List[RDB.BuiltInCategory](cat_list)
filter = RDB.ElementMulticategoryFilter(typed_list)
elementen = RDB.FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType().ToElements()

EFT = RDB.FilteredElementCollector(doc).OfCategory(RDB.BuiltInCategory.OST_ElectricalFixtureTags).WhereElementIsNotElementType().ToElements() #ElectricalFixtureTags ophalen in filter

#Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

#bestemming tags
EFTag_bestemming = []
for e in elementen:
	familynaam_type = e.get_Parameter(RDB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString()
	if familynaam_type == "63_EFT_UN_MC_1.8_t: bestemming" or familynaam_type == "64_DDT_UN_MC_1.8_t: bestemming" or familynaam_type == "64_CDT_UN_MC_1.8_t: bestemming" : 
		EFTag_bestemming.append(e)
#circuitnumber tags
EFTag_circuitnumber = []
for e in elementen:
	familynaam_type = e.get_Parameter(RDB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString()
	if familynaam_type == "63_EFT_UN_MC_1.8_t: circuit number" or familynaam_type == "63_LFT_UN_MC_1.8_t: circuit number": 
		EFTag_circuitnumber.append(e)
#montagehoogte tags		
EFTag_montagehoogte = []
for e in elementen:
	familynaam_type = e.get_Parameter(RDB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString()
	if familynaam_type == "63_EFT_UN_MC_1.8_t: montagehoogte" or familynaam_type == "63_LFT_UN_MC_1.8_t: montagehoogte": 
		EFTag_montagehoogte.append(e)

	
#Eind Transactie
TransactionManager.Instance.TransactionTaskDone()

OUT = EFTag_bestemming, EFTag_circuitnumber, EFTag_montagehoogte 

```

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [December 8, 2022, 11:29am UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/2 "2022-12-08T11:29:53Z")

</div>

Hi,

> [@jw.vanasselt](#):
>
> `elementen = RDB.FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType().ToElements()`

There is an error or your `elementen` list is empty ?

---

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [December 8, 2022, 12:13pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/3 "2022-12-08T12:13:24Z")

</div>

Hi @c.poupin ,

The elementen list is okay:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/6/46333bf684c6c3e77a31b9531afc59288877e782.png)

The script is not giving any error.

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [December 8, 2022, 9:55pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/4 "2022-12-08T21:55:00Z")

</div>

seems to work fine 🤔

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/1/611b64929368da97921ad678168be0cf8fd33e62.png)

the only API change regarding Tags that I know of is this property ( deprecated )

> **[TaggedElementId Property](https://www.revitapidocs.com/2022/12ff75b5-2893-dee9-7321-85c3439e40f7.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

but this property is not used in your code snippet

---

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [December 8, 2022, 10:18pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/5 "2022-12-08T22:18:35Z")

</div>

> [@c.poupin](#):
>
> the only API change regarding Tags that I know of is this property ( deprecated )

@c.poupin

I have seen it, i use it in an other part of the script but this is strange.

Any thoughts what I can do?

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [December 9, 2022, 8:19am UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/6 "2022-12-09T08:19:01Z")

</div>

if you have an empty OUT list with this code, there may be a problem with your equality comparators (check values)

> **Code**
>
> ```auto
> import clr #.NET Laden
> import sys #sys is de fundamentele Python bibliotheek
> #de standaard IronPython-bibliotheken
> #sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib') #Imports the
> #standaard IronPython-bibliotheken, die alles dekken, van servers en
> #encryptie tot reguliere expressies.
> import System #The System namespace in de hoofdmap .NET
> from System import Array #.NET class voor het verwerken van array-informatie
> import System.Collections.Generic as MGen #Module kan nu benaderd worden met MGen.xxxx
> #from System.Collections.Generic import * #Hiermee kunt u generieke afhandelen. Revit's API
> #soms wil hard-getypte 'generieke' lijsten, genaamd ILists. Als je niet nodig hebt
> #deze kunt u deze regel verwijderen.
> clr.AddReference('ProtoGeometry') #Een Dynamo-bibliotheek voor zijn proxygeometrie
> #classes. Je hebt dit alleen nodig als je interactie hebt met geometrie.
> import Autodesk.DesignScript.Geometry as AGeo #Module kan worden opgeroepen a=met AGeo.xxxx
> #from Autodesk.DesignScript.Geometry import * #Laadt alles in Dynamo's
> #geometriebibliotheek
> clr.AddReference("RevitNodes") #Dynamo's nodes voor Revit
> import Revit #Laad in de Revit-namespaces in RevitNodes
> clr.ImportExtensions(Revit.Elements) #Meer laden van Dynamo's Revit-bibliotheken
> clr.ImportExtensions(Revit.GeometryConversion) #Meer laden van Dynamo's
> #Revit-bibliotheken. Je hebt dit alleen nodig als je interactie hebt met geometrie.
> clr.AddReference("RevitServices") #Dynamo's classes voor het omgaan met Revit-documenten
> import RevitServices 
> from RevitServices.Persistence import DocumentManager #Een interne Dynamo class
> #dat het document bijhoudt waaraan Dynamo momenteel is gekoppeld
> from RevitServices.Transactions import TransactionManager #Een Dynamo class voor
> #transacties openen en sluiten om de database van het Revit-document te wijzigen
> 
> clr.AddReference("RevitAPI") #Verwijzing naar Revit's API DLL's toevoegen
> clr.AddReference("RevitAPIUI") #Verwijzing naar Revit's APIUI DLL's toevoegen
> 
> import Autodesk #Loads the Autodesk namespace
> import Autodesk.Revit.DB as RDB #Loading Revit's API UI classes module kan nu worden aangeroepen met RDB.xxxx
> #from Autodesk.Revit.DB import * #Loading Revit's API UI classes
> import Autodesk.Revit.UI as RUI # Loading Revit's API UI classes als RUI.xxxx
> #from Autodesk.Revit.UI import * #Loading Revit's API UI classes
> 
> doc = DocumentManager.Instance.CurrentDBDocument #Dit is het actieve Revit document
> uiapp = DocumentManager.Instance.CurrentUIApplication #Een handle instellen voor het actieve Revit UI-document
> app = uiapp.Application #Een handle instellen op de momenteel geopende instantie van de Revit-toepassing
> uidoc = uiapp.ActiveUIDocument #Een handle instellen op de momenteel geopende instantie van de Revit UI-toepassing
> 
> # einde code omrekenen revit feet naar huidig ingestelde document units
> # Hieronder kan je dan gaan programmeren
> # Gebruik boiler template
> 
> cat_list = [RDB.BuiltInCategory.OST_ElectricalFixtureTags, RDB.BuiltInCategory.OST_DataDeviceTags, RDB.BuiltInCategory.OST_CommunicationDeviceTags]
> typed_list = MGen.List[RDB.BuiltInCategory](cat_list)
> filter = RDB.ElementMulticategoryFilter(typed_list)
> elementen = RDB.FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType().ToElements()
> 
> EFT = RDB.FilteredElementCollector(doc).OfCategory(RDB.BuiltInCategory.OST_ElectricalFixtureTags).WhereElementIsNotElementType().ToElements() #ElectricalFixtureTags ophalen in filter
> 
> #Start Transaction
> TransactionManager.Instance.EnsureInTransaction(doc)
> 
> #bestemming tags
> EFTag_bestemming = []
> for e in elementen:
> familynaam_type = e.get_Parameter(RDB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString()
> if familynaam_type == "63_EFT_UN_MC_1.8_t: bestemming" or familynaam_type == "64_DDT_UN_MC_1.8_t: bestemming" or familynaam_type == "64_CDT_UN_MC_1.8_t: bestemming" : 
> EFTag_bestemming.append(e)
> #circuitnumber tags
> EFTag_circuitnumber = []
> for e in elementen:
> familynaam_type = e.get_Parameter(RDB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString()
> if familynaam_type == "63_EFT_UN_MC_1.8_t: circuit number" or familynaam_type == "63_LFT_UN_MC_1.8_t: circuit number": 
> EFTag_circuitnumber.append(e)
> #montagehoogte tags		
> EFTag_montagehoogte = []
> for e in elementen:
> familynaam_type = e.get_Parameter(RDB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsValueString()
> if familynaam_type == "63_EFT_UN_MC_1.8_t: montagehoogte" or familynaam_type == "63_LFT_UN_MC_1.8_t: montagehoogte": 
> EFTag_montagehoogte.append(e)
> 
> 	
> #Eind Transactie
> TransactionManager.Instance.TransactionTaskDone()
> 
> OUT = EFTag_bestemming, EFTag_circuitnumber, EFTag_montagehoogte
> 
> ```

---

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [December 9, 2022, 9:10am UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/7 "2022-12-09T09:10:23Z")

</div>

@c.poupin

That’s the strange thing, this works for me. As soon as I apply the for loop and want to append the elements, then I suddenly get an empty list. The family has not changed from r20

---

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [December 9, 2022, 1:58pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/8 "2022-12-09T13:58:29Z")

</div>

Really strange, nothing is changed but when I use the .Contains() it works fine…  
Well fixed for now, next point is this.

> [@c.poupin](#):
>
> the only API change regarding Tags that I know of is this property ( deprecated )

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [December 9, 2022, 2:02pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/9 "2022-12-09T14:02:54Z")

</div>

> [@jw.vanasselt](#):
>
> I use the .Contains() it works fine…

maybe you have an extra space character (at the end) in your Type Family Name

---

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [December 9, 2022, 2:05pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/10 "2022-12-09T14:05:39Z")

</div>

@c.poupin , No I don’t have, but this way is alot saver.  
I take all the duplicated tags also with .Contains()

---

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [December 9, 2022, 3:32pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/12 "2022-12-09T15:32:16Z")

</div>

Solution for the TaggedElementId Property:

```auto
revit_version = int(doc.Application.VersionNumber)

def TaggedElement(tag):
    if revit_version >= 2022:  	
    	return tag.GetTaggedLocalElements()
    else:
    	return tag.GetTaggedLocalElement()

```

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [December 9, 2022, 3:40pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/13 "2022-12-09T15:40:36Z")

</div>

A little improvement 😉

```auto
revit_version = int(doc.Application.VersionNumber)

def TaggedElements(tag):
	"""
	-description:
		Get the tagged local elements
	-Parameters:
		tag : RDB.IndependentTag
	-Return:
		Collection of Elements
	"""
	if revit_version >= 2022:  	
		return tag.GetTaggedLocalElements()
	else:
		return List[RDB.Element]([tag.GetTaggedLocalElement()])

```

---

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [December 10, 2022, 7:39am UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/14 "2022-12-10T07:39:02Z")

</div>

@c.poupin Haha yes you are alright, I had seen the ICollection function, but it did work without it 🙈

Can you explain me what the IList and ICollection do in the Revit API?

---

<div class="post-metadata">

**Author:** ![aaronrumple](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/aaronrumple/32/195292_2.png) [@aaronrumple](https://forum.dynamobim.com/u/aaronrumple)\
**Post date:** [December 12, 2022, 6:30pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/15 "2022-12-12T18:30:35Z")

</div>

IList and ICollection are part of .Net. They are not really part of Revit - just the way .Net manages lists and collections.

[ICollection Interface (System.Collections.Generic) | Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.icollection-1?view=net-7.0)

[IList Interface (System.Collections) | Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/api/system.collections.ilist?view=net-7.0)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [December 12, 2022, 7:47pm UTC](https://forum.dynamobim.com/t/python-script-doesnt-work-in-revit-2023/83909/16 "2022-12-12T19:47:04Z")

</div>

> [@jw.vanasselt](#):
>
> Haha yes you are alright, I had seen the ICollection function, but it did work without it

yes, but this improvement allows you to return a collection all the time regardless of the version of Revit, this avoids testing the returned object later in the code (list or element ?)
