Pyrevit: CPython FilteredElementCollector failed to init

Created on 9 Sep 2019  路  1Comment  路  Source: eirannejad/pyRevit

This is my code written to run with CPython:

#! python3

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

uiapp = __revit__
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
doc = uidoc.Document

selected_ids = uidoc.Selection.GetElementIds()
if selected_ids:
    c = FilteredElementCollector(doc, selected_ids)
else:
    c = FilteredElementCollector(doc)

c.OfClass(FamilyInstance)
c.WhereElementIsNotElementType()

if doc.IsWorkshared:
    ws_table = doc.GetWorksetTable()
    active_ws_id = ws_table.GetActiveWorksetId()
    ws_filter = ElementWorksetFilter(active_ws_id)
    c.WherePasses(ws_filter)

elements = [e for e in c if e.Symbol.Family.IsInPlace]
if elements:
    print("List all In-Place Element Ids in ACTIVE WORKSET:")
    print([e.Id.IntegerValue for e in elements])
else:
    print("No In-Place Element in ACTIVE WORKSET")

To Reproduce

  1. Open a project
  2. Select several model elements
  3. Run the script with pyRevit 4.7-beta 2 & CPython engine

Expected behavior
The script run normally with IronPython

Output Error:

CPython Traceback:
TypeError : no constructor matches given arguments
 File "E:\Setup\UCE\Autodesk\Revit\pyRevit extensions\htl.extension\HTL.tab\Test.panel\views.stack\Test1.pushbutton\script.py", line 15, in <module>
 c = FilteredElementCollector(doc, selected_ids)

pyRevitLabs.PythonNet
at pyRevitLabs.PythonNet.Runtime.CheckExceptionOccurred()
 at pyRevitLabs.PythonNet.PythonEngine.RunString(String code, Nullable`1 globals, Nullable`1 locals, RunFlagType flag, Encoding encoding)
 at pyRevitLabs.PythonNet.PythonEngine.ExecUTF8(String code, Nullable`1 globals, Nullable`1 locals)
 at PyRevitLabs.PyRevit.Runtime.CPythonEngine.Execute(ScriptRuntime& runtime)

Desktop:

  • OS: Windows 7 x64
  • pyRevit Version 4.7-beta 2
  • pyRevit Environment:
C:\Users\HTL>pyrevit env
==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.7-beta2" | Path: "C:\Users\HTL\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "2018 First Customer Ship" | Engine: 277 | Path: "C:\Users\HTL\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\HTL\AppData\Roa
ming\Autodesk\Revit\Addins\2018\pyRevit.addin"
==> Installed Extensions
htl | Type: Unknown | Repo: "[email protected]:hoangthanhlong/pyrevitscripts.git" | Installed: "E:\Setup\UCE\Autodesk\Revit\pyRevit extensions\htl.extens
ion"
==> Default Extension Search Path
C:\Users\HTL\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
E:\Setup\UCE\Autodesk\Revit\pyRevit extensions
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
2018 First Customer Ship | Version: 18.0.0.420 | Build: 20170223_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2018"
==> Running Revit Instances
PID: 3040 | 2018 First Customer Ship | Version: 18.0.0.420 | Build: 20170223_1515(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2018"
==> User Environment
Microsoft Windows 7 [Version 6.1.7601]
Executing User: HTL-PC\HTL
Active User: HTL-PC\HTL
Adming Access: Yes
%APPDATA%: "C:\Users\HTL\AppData\Roaming"
Latest Installed .Net Framework: 4.8
Installed .Net Target Packs: v3.5 v4.0 v4.5 v4.5.1 v4.5.2 v4.6 v4.6.1 v4.7.1 v4.7.2 v4.X
Installed .Net-Core Target Packs: v2.2.203 v3.0.100-preview8-013656
pyRevit CLI 0.14.0.0
Question cpython

Most helpful comment

Manually create the dotnet lists. IronPython is kind of nice in that it does these conversions automatically.

#! python3

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

from System.Collections.Generic import List

uiapp = __revit__
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
doc = uidoc.Document

selected_ids = uidoc.Selection.GetElementIds()

selected_ids_list = List[ElementId]()
for eid in selected_ids:
    selected_ids_list.Add(eid)

if selected_ids:
    c = FilteredElementCollector(doc, selected_ids_list)
else:
    c = FilteredElementCollector(doc)

c.OfClass(FamilyInstance)
c.WhereElementIsNotElementType()

if doc.IsWorkshared:
    ws_table = doc.GetWorksetTable()
    active_ws_id = ws_table.GetActiveWorksetId()
    ws_filter = ElementWorksetFilter(active_ws_id)
    c.WherePasses(ws_filter)

elements = [e for e in c if e.Symbol.Family.IsInPlace]
if elements:
    print("List all In-Place Element Ids in ACTIVE WORKSET:")
    print([e.Id.IntegerValue for e in elements])
else:
    print("No In-Place Element in ACTIVE WORKSET")

>All comments

Manually create the dotnet lists. IronPython is kind of nice in that it does these conversions automatically.

#! python3

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

from System.Collections.Generic import List

uiapp = __revit__
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
doc = uidoc.Document

selected_ids = uidoc.Selection.GetElementIds()

selected_ids_list = List[ElementId]()
for eid in selected_ids:
    selected_ids_list.Add(eid)

if selected_ids:
    c = FilteredElementCollector(doc, selected_ids_list)
else:
    c = FilteredElementCollector(doc)

c.OfClass(FamilyInstance)
c.WhereElementIsNotElementType()

if doc.IsWorkshared:
    ws_table = doc.GetWorksetTable()
    active_ws_id = ws_table.GetActiveWorksetId()
    ws_filter = ElementWorksetFilter(active_ws_id)
    c.WherePasses(ws_filter)

elements = [e for e in c if e.Symbol.Family.IsInPlace]
if elements:
    print("List all In-Place Element Ids in ACTIVE WORKSET:")
    print([e.Id.IntegerValue for e in elements])
else:
    print("No In-Place Element in ACTIVE WORKSET")
Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanBoghean picture DanBoghean  路  3Comments

amastrobera picture amastrobera  路  3Comments

thumDer picture thumDer  路  4Comments

TheBIMsider picture TheBIMsider  路  5Comments

Robbo1234 picture Robbo1234  路  4Comments