From IronPython to Cpython 3

Hi,

Trying to collect all viewtemplates of active document but keep getting errors.
I’ve looked in RevitAPI 2023 but can’t se anything wrong on “IsTemplate”.

Dynamo version 2.16

from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
All_views = FilteredElementCollector(doc).OfClass(View).ToElements()

viewTemplates = []

for view in All_views:
	if view.**IsTemplate** and view.ViewType != ViewType.ThreeD:
		viewTemplates.append(view)
OUT = viewTemplates

@BIM_Mrbrango This code will work if you remove the asterisks :slight_smile:

from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
All_views = FilteredElementCollector(doc).OfClass(View).ToElements()

viewTemplates = []

for view in All_views:
	if view.IsTemplate and view.ViewType != ViewType.ThreeD:
		viewTemplates.append(view)
OUT = viewTemplates

Hi,

There are no asterisks in the original code, they were added when I used Bold before pistong.

I dont have DynamoIronpython 3 installed, could that be the case?

This theoretically should run in both IronPython2 and CPython3 … do you have a screenshot of the error that occurs? (Hover over the yellow icon that pop’s up to expand).

Does this help? Some View Templates not being found in Python/Dynamo - #10 by truevis
It has code to get 3D View Templates.

1 Like

Hi Solamour,
Everything seems to go bananas when I switch from IronPython to Cpython.
Here is another printscreen…

Going crazy cause I cant understand why??
I’m looking in Revit API but I cant see anything wrong with the code


Hi truevis

I can take a look, thanks

Hello @BIM_Mrbrango - My apologies, this slipped off my radar.

You can download and use the IronPython2 package if you like from the Package Manager, and we also have an IronPython3 package also (Albeit that’s a first pass) if you won’t want to go down the CPython route.

There are differences between IronPython and CPython that you can read about here.

For example, i.LookupParameter(<param>).AsValueString() is a .NET call that is only present in IronPython and not CPython.

2 Likes