Hi,
Tried to implement code as mentioned at dynamopythonprimer book, but faced with a following issue. Do somebody know what’s wrong?
import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import ISelectionFilter
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
class MySelectionFilter(ISelectionFilter):
def __init__(self):
pass
def AllowElement(self, element):
if element.Category.Name == "Walls":
return True
else:
return False
def AllowReference(self, element):
return False
selection_filter = MySelectionFilter()
walls = uidoc.Selection.PickElementsByRectangle(selection_filter)
OUT = walls
@denisyukj ,
at first look “Walls” seems to be wrong you need “OST_Walls”
KR
Andreas
Hello, look at this message you have the why
Hi All,
I’ve been getting a weird error where the selection filters aren’t being implemented for the pickobjects method. Can anyone advise / replicate / confirm? CPython3
[image]
Node Name: Python Script
Package: Core.Scripting
Dynamo Version: 2.16.1.2727
Host: Dynamo Revit
Messages: TypeError : object does not implement ISelectionFilter [’ File “”, line 34, in \n’]
State: Warning
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
f…
edit:
you have this library node (written in C# I think)
for landing
cordially
christian.stan
2 Likes
For a ‘one time use’ make sure that your class has a namespace assigned.
1 Like
@christian.stan
Thank you. I know about this selection nodes, just trying to dive into programing
So right now it’s a PythonNET issue, am I correct?
1 Like
yes as pointed out by Mr. Poupin and in Mr. Solamour’s bag which must be heavy
from what I understood
Cordially
christian.stan
There are some explanations about this issue
here
pythonnet:master
← mcneel:pr/newtypes
opened 09:51PM - 19 Dec 22 UTC
### What does this implement/fix? Explain your changes.
This PR addresses the… se issues:
- Current pythonnet does not allow subclassing from CLR Abstract classes
- Running python script with types containing `__namespace__`, more than once, would throw `Type Exists` exception
- Calling `super().VirtualMethod()` inside a python-derived virtual method, would result in an infinite loop
Due to the nature of the changes, this is a single PR instead of multiple smaller ones.
After PR merge:
- Python types can derive from CLR abstract classes. As before, abstract methods that are not implemented on the python type, will dynamically throw `NotImplemented` exception.
- Specifying `__namespace__` is not required to created a `ClassDerived` anymore. All python derived classes are now represented by `ClassDerived` in managed memory.
- `ClassDerived` now caches generated types based on namespace, type name, and chain of base classes. This avoids regenerating types or throwing `Type Already Exists` exceptions. A new format for generated type names include full name of base class and interfaces in the typename. The naming format still ends in the python type name to be backward compatible and passes the unit tests
- **Example:** Full name of derived clr type for python type named `SubClass`, deriving from `BaseClass` and implementing `BaseInterface1` and `BaseInterface2`:
`Python.Runtime.Dynamic.BaseClass__BaseInterface1__BaseInterface2__main__SubClass`
- Support for one base class and multiple interfaces (Merged some ideas and code from #2028 - Potential merge conflicts)
- Derived class can call chosen constructors using `super().__init__()` pattern.
```python
class SubClass(BaseClassA):
def __init__(self, v):
super().__init__(v)
```
- Derived class can call base virtual methods using `super().method()` pattern.
```python
class SubClass(BaseClassA):
def DoWorkWith(self, value):
r = super().DoWorkWith(value) + 10
return r
```
- Improved virtual method and getter/setter routing. Custom attributes (`OriginalMethod` and `RedirectedMethod`) are now used to mark the original and redirected virtual methods. The method name format for `OriginalMethod ` is changed to `$"_BASEVIRTUAL__{name}"` so it can handle calling original methods on base classes that does not match the name of current class. Previously this was not working.
- Other misc refactoring and improvements. No change in behavior.
### Does this close any currently open issues?
Potentially (no tests have been done to ensure these issues are resolved)
- #1945
- #1107
- #1787
### Any other comments?
...
### Checklist
Check all those that are applicable and complete.
- [X] Make sure to include one or more tests for your change
- [X] If an enhancement PR, please create docs and at best an example
- [X] Ensure you have signed the [.NET Foundation CLA](https://cla.dotnetfoundation.org/pythonnet/pythonnet)
- [X] Add yourself to [`AUTHORS`](../blob/master/AUTHORS.md)
- [X] Updated the [`CHANGELOG`](../blob/master/CHANGELOG.md)
and here
pythonnet:master
← rmadsen-ks:1783-ImplementInterfaceAndInheritClass
opened 02:11PM - 29 Nov 22 UTC
Added support for multiple inheritance when inheriting from one base class and/o… r multiple interfaces.
Added a unit test verifying that it works with a simple class and interface. This unit test would previously have failed since multiple types are in the class super class list.
Close #1783
### Checklist
Check all those that are applicable and complete.
- [X] Make sure to include one or more tests for your change
- [X] If an enhancement PR, please create docs and at best an example
- [X] Ensure you have signed the [.NET Foundation CLA](https://cla.dotnetfoundation.org/pythonnet/pythonnet)
- [X] Add yourself to [`AUTHORS`](../blob/master/AUTHORS.md)
- [X] Updated the [`CHANGELOG`](../blob/master/CHANGELOG.md)
this should be fixed in the next version of PythonNet (3.1.0)
3 Likes
Unfortunately not, the arrival of Net 7-8 will complicate things with PythonNet 2.5.2. I currently recommend Ironpython2 (or better still IronPython3), or else to make a c# library.
2 Likes