ViewType property issue

Hi, when I try to use ViewType property unexpected result is appearing. Can someone tell me what am I doing wrong? I expect result according enum.

views = UnwrapElement(IN[0])

# Place your code below this line
types = []
for v in views:
    types.append(str(v.ViewType))

# Assign your output to the OUT variable.
OUT = types

Hello,
here is a clue

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *


views=UnwrapElement(IN[0])
col=[]
col1=[]
for v in views:
    c=v.GetType()
    c1=v.Name
    col.append(c.Name)
    col1.append(c1)

OUT = col,col1

Cordially
christian.stan

1 Like

Also, Clockwork has View.Type node that works correctly. You may can look at that to see the issue with your code.

3 Likes

Your code is correct.
It’s a CPython3/Pythonnet 2.5.x issue, .NET enums are automatically converted to Python int

A temporary fix with CPython3/PythonNet 2.x

import sys
import clr
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

views = UnwrapElement(IN[0])

# Place your code below this line
dictViewType = dict(zip(System.Enum.GetValues(ViewType), System.Enum.GetNames(ViewType)))
types = []
for v in views:
    types.append(dictViewType.get(v.ViewType))

# Assign your output to the OUT variable.
OUT = types

result in comparison with the as yet unofficial IronPython3 engine

5 Likes

Hello, I know you are a magician :wink: but how do you do under IronPython 3 without adding to the clr (RevitAPI)
is it already included?

Cordially
christian.stan

to read some properties (like Enum), loading .NET assemblies is not necessarily necessary

1 Like

@c.poupin, thank you.
Where can I get IronPython3 executor?

It’s a work in progress package

1 Like

You could also use System.Enum.GetName(ViewType, v.ViewType) after filtering for nulls

2 Likes