Alien
August 30, 2024, 2:33pm
1
So I’ve spent pretty much all day trying to overcome issue after issue with winforms in Revit 25…
The latest one is I can’t add a click event to a button…
Seems I can’t use WPF either…
So I’m guessing winforms in Python are not really a viable option with my Dynamo scripts any more?
I don’t think this is the case.
However using the native language for a library is pretty much always easier than having to deal with an interpreter.
If you use CPython3, need to update to Revit 2025.2 or use IronPython3
related solved issue
opened 12:47PM - 15 Nov 23 UTC
closed 04:16PM - 20 Jun 24 UTC
Python
### Dynamo Version
Dynamo 2.19.3
### Revit Version
Revit 2024.2
### … Operating System
Windows 11
### What did you do?
try to use events subscription with CPython3
### What did you expect to see?
No Error
### What did you see instead?
a Python error
```
Node Name: PythonScript
Package: Core.Scripting
Dynamo Version: 2.19.3.6394
Host: Dynamo Revit
Messages: PythonEvaluator.Evaluate operation failed.
The constructor on type 'System.Reflection.Emit.TypeBuilder' was not found.
Status: Warning
```
![image](https://github.com/DynamoDS/DynamoRevit/assets/53660624/1878fac8-906f-4e85-b521-516bdb669dd3)
Example 1
```
import clr
import System
from System import EventHandler
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *
class Form26(Form):
def __init__(self):
self.InitializeComponent()
def InitializeComponent(self):
self._button1 = System.Windows.Forms.Button()
self.SuspendLayout()
#
self._button1.Location = System.Drawing.Point(73, 103)
self._button1.Name = "button1"
self._button1.Size = System.Drawing.Size(142, 43)
self._button1.TabIndex = 0
self._button1.Text = "button1"
self._button1.UseVisualStyleBackColor = True
self._button1.Click += self.Button1Click
#
self.ClientSize = System.Drawing.Size(284, 261)
self.Controls.Add(self._button1)
self.Name = "Form26"
self.Text = "Form26"
self.ResumeLayout(False)
def Button1Click(self, sender, e):
pass
objForm = Form26()
objForm.ShowDialog()
```
Example 2
```
import clr
import System
from System import EventHandler
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Events import *
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
uiapp = uidoc.Application
def dismiss (sender, eventArgs):
if isinstance(eventArgs, TaskDialogShowingEventArgs):
eventArgs.OverrideResult(TaskDialogResult.No)
return
dialogEventHandler = EventHandler[DialogBoxShowingEventArgs](dismiss)
uiapp.DialogBoxShowing += dialogEventHandler
```
### Stacktrace/logs
_No response_
### Details
the error seems related to the build/compilation of PythonNet 2.5.2 (Python.Runtime) with Net.Standard 2.0 as target
there are potentially others PythonNet 2.5.2 issues due to this change (Net Framework -> Net.Standard 2.0),
_will probably be resolved in PythonNet 3.x.x_
1 Like
Alien
September 2, 2024, 8:20am
4
Thanks.
Maybe a really stupid question but… How would I find this information without asking on here?
Is there a list of stuff that doesn’t work that’s known somewhere?
I spent several hours trying option after option after option trying to get my event handler to work on my winform before posting on here in frustration…
Alien
September 2, 2024, 10:32am
5
Ooo, 25.2 the text has been shrunk again
1 Like
Personally, I try to keep track of changes on the Github Dynamo repos and specifically the issues and changelogs.
if you’re stuck with a CPython3/PythonNet2 engine script, I’d advise you to stick with IronPython (IronPython3 if you’re on Revit2025) until PythonNet3 arrives on the CPython3 engine.
while you’re waiting for PythonNet3, you can already solve the problems associated with migration to Net8
1 Like
Alien
September 2, 2024, 7:40pm
7
I had a look on git… but it seems really complicated.
I don’t think there is Iron Python in Revit 25?
I’ve decided it’s a blessing in disguise and am going to put a little more effort into learning C#.
accessible via the package manager
1 Like
Alien
September 2, 2024, 7:49pm
9
Ahhh! Thanks. I assumed as it only gives you the choice of Py3 in the OOTB node that you couldn’t have that any more.