Collect.Sheets (Springs) to CPython

Hi,

I converted the node Collect.Sheets (Springs) to CPython 3 but i get an error, and i am not familiar with python code.

The error is
afbeelding

#Copyright(c) 2016, Dimitar Venkov
# @5devene, dimitar.ven@gmail.com

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
isRvt2018 = int(app.VersionNumber) < 2019

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

def tolist(obj1):
        if hasattr(obj1,"__iter__"): return obj1
        else: return [obj1]

fn = list(map(str,tolist(IN[0]) ))
NameNumber = IN[1]
result, similar, names = [], [], []

fec = FilteredElementCollector(doc).OfClass(View)
ds_type = "DrawingSheet"
for i in fec:
        if i.ViewType.ToString() == ds_type:
                if NameNumber: n1 = i.ViewName if isRvt2018 else i.Name
                else: n1 = i.SheetNumber
                names.append(n1)
                if any(fn1 == n1 for fn1 in fn):
                        result.append(i.ToDSType(True))
                elif any(fn1.lower() in n1.lower() for fn1 in fn):
                        similar.append(i.ToDSType(True))
if len(result) > 0:
        OUT = result,similar
if len(result) == 0 and len(similar) > 0:
        OUT = "No exact match found. Check partial below:",similar
if len(result) == 0 and len(similar) == 0:
        OUT = "No match found! Check values below:", names

Hi,
in CPython3/PythonNet 2.5.x the representation of .NET enums are automatically converted to Python int
see these posts

1 Like

Hi,

Thanks, but i don’t understand Python code so i don’t know how to rewrite it to CPython.
I think that everything above
“# Place your code below this line”
is to add it.

But i don’t know how to write everything else.

Just use standard nodes then. You can get all sheets as a class or category, then number and name have nodes too.

4 Likes

Unfortunately, copying and pasting code without understanding never made progress (I myself made this mistake when I started), plus there are other issues with the code currently that doesn’t work well with CPython3/PythonNet 2.5
(example : hasattr(obj1,"__iter__"))

+1 for the @GavinCrump solution

1 Like

Thanks,

I solved it with OOTB nodes, i guess i have to start to learn Python too :smile:

1 Like