Dynamo script run in revit 2020 but cannot run in revit 2024

I have Dynamo script work normal in revit 2020, but dont know why cannot run in revit 2024, it said unable to find assembly “System.Windows.Forms.DataVisualization”
Maybe the problem is between ironPython and CPython3?


Interaction with winform_1.dyn (13.8 KB)

Yes.

You’ll need to revise the Python, provide the script here so others can help, or continue to use the IronPython2 package and love with the security issues / consequences thereof.

@jacob.small Thank you for your reply. I have attached the dyn file above for your reference. Or you can review script below:

Script
import clr
import System
 
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import*
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import Selection
from  Autodesk.Revit.UI.Selection import ISelectionFilter

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
#########################################################################
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms.DataVisualization')
import System.Windows.Forms
import System.Drawing
from System.Drawing import *
from System.Windows.Forms import *
from System.Collections.Generic import *
#########################################################################
doc = DocumentManager.Instance.CurrentDBDocument
View = doc.ActiveView
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#########################################################################
naCate = [i.Name for i in doc.Settings.Categories]
fil = "Schedules"
getIndex_Item = naCate.index(fil)
catebyName = UnwrapElement(Revit.Elements.Category.ByName(naCate[getIndex_Item]))
bic = System.Enum.ToObject(BuiltInCategory, catebyName.Id.IntegerValue)
filters = FilteredElementCollector(doc).OfCategory(bic).ToElements()
sche_Name = filters

class MainForm(Form):
	def __init__(self):
		self.InitializeComponent()
	
	def InitializeComponent(self):
		self._groupBox1 = System.Windows.Forms.GroupBox()
		self._groupBox2 = System.Windows.Forms.GroupBox()
		self._clbNaSchedule = System.Windows.Forms.CheckedListBox()
		self._txtbTotalItems = System.Windows.Forms.TextBox()
		self._cbxAllNone = System.Windows.Forms.CheckBox()
		self._label1 = System.Windows.Forms.Label()
		self._label2 = System.Windows.Forms.Label()
		self._txtbBrowser = System.Windows.Forms.TextBox()
		self._bttBrowser = System.Windows.Forms.Button()
		self._bttExport = System.Windows.Forms.Button()
		self._bttCancel = System.Windows.Forms.Button()
		self._label3 = System.Windows.Forms.Label()
		self._groupBox1.SuspendLayout()
		self._groupBox2.SuspendLayout()
		self.SuspendLayout()
		# 
		# groupBox1
		# 
		self._groupBox1.Controls.Add(self._label1)
		self._groupBox1.Controls.Add(self._cbxAllNone)
		self._groupBox1.Controls.Add(self._txtbTotalItems)
		self._groupBox1.Controls.Add(self._clbNaSchedule)
		self._groupBox1.Location = System.Drawing.Point(12, 4)
		self._groupBox1.Name = "groupBox1"
		self._groupBox1.Size = System.Drawing.Size(494, 159)
		self._groupBox1.TabIndex = 0
		self._groupBox1.TabStop = False
		self._groupBox1.Text = "Schedules"
		# 
		# groupBox2
		# 
		self._groupBox2.Controls.Add(self._bttBrowser)
		self._groupBox2.Controls.Add(self._txtbBrowser)
		self._groupBox2.Controls.Add(self._label2)
		self._groupBox2.Location = System.Drawing.Point(12, 167)
		self._groupBox2.Name = "groupBox2"
		self._groupBox2.Size = System.Drawing.Size(494, 57)
		self._groupBox2.TabIndex = 1
		self._groupBox2.TabStop = False
		self._groupBox2.Text = "Export Options"
		# 
		# clbNaSchedule
		# 
		self._clbNaSchedule.AllowDrop = True
		self._clbNaSchedule.CheckOnClick = True
		self._clbNaSchedule.DisplayMember = "Name"
		self._clbNaSchedule.FormattingEnabled = True
		self._clbNaSchedule.Location = System.Drawing.Point(6, 19)
		self._clbNaSchedule.Name = "clbNaSchedule"
		self._clbNaSchedule.Size = System.Drawing.Size(482, 109)
		self._clbNaSchedule.TabIndex = 0
		self._clbNaSchedule.SelectedIndexChanged += self.ClbNaScheduleSelectedIndexChanged
		for i in sche_Name:
			self._clbNaSchedule.Items.Add(i)	
		# 
		# txtbTotalItems
		# 
		self._txtbTotalItems.Location = System.Drawing.Point(404, 132)
		self._txtbTotalItems.Name = "txtbTotalItems"
		self._txtbTotalItems.Size = System.Drawing.Size(72, 20)
		self._txtbTotalItems.TabIndex = 1
		self._txtbTotalItems.TextChanged += self.TxtbTotalItemsTextChanged
		# 
		# cbxAllNone
		# 
		self._cbxAllNone.Location = System.Drawing.Point(6, 131)
		self._cbxAllNone.Name = "cbxAllNone"
		self._cbxAllNone.Size = System.Drawing.Size(107, 22)
		self._cbxAllNone.TabIndex = 2
		self._cbxAllNone.Text = "Select All/None"
		self._cbxAllNone.UseVisualStyleBackColor = True
		self._cbxAllNone.CheckedChanged += self.CbxAllNoneCheckedChanged
		# 
		# label1
		# 
		self._label1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
		self._label1.Location = System.Drawing.Point(316, 135)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(82, 20)
		self._label1.TabIndex = 3
		self._label1.Text = "Total Items:"
		# 
		# label2
		# 
		self._label2.Location = System.Drawing.Point(6, 26)
		self._label2.Name = "label2"
		self._label2.Size = System.Drawing.Size(100, 23)
		self._label2.TabIndex = 0
		self._label2.Text = "Output Folder:"
		# 
		# txtbBrowser
		# 
		self._txtbBrowser.Location = System.Drawing.Point(85, 23)
		self._txtbBrowser.Name = "txtbBrowser"
		self._txtbBrowser.Size = System.Drawing.Size(313, 20)
		self._txtbBrowser.TabIndex = 1
		self._txtbBrowser.TextChanged += self.TxtbBrowserTextChanged
		# 
		# bttBrowser
		# 
		self._bttBrowser.Location = System.Drawing.Point(413, 21)
		self._bttBrowser.Name = "bttBrowser"
		self._bttBrowser.Size = System.Drawing.Size(75, 23)
		self._bttBrowser.TabIndex = 2
		self._bttBrowser.Text = "Browser"
		self._bttBrowser.UseVisualStyleBackColor = True
		self._bttBrowser.Click += self.BttBrowserClick
		# 
		# bttExport
		# 
		self._bttExport.Location = System.Drawing.Point(348, 230)
		self._bttExport.Name = "bttExport"
		self._bttExport.Size = System.Drawing.Size(75, 23)
		self._bttExport.TabIndex = 2
		self._bttExport.Text = "Export"
		self._bttExport.UseVisualStyleBackColor = True
		self._bttExport.Click += self.BttExportClick
		# 
		# bttCancel
		# 
		self._bttCancel.Location = System.Drawing.Point(425, 230)
		self._bttCancel.Name = "bttCancel"
		self._bttCancel.Size = System.Drawing.Size(75, 23)
		self._bttCancel.TabIndex = 3
		self._bttCancel.Text = "Cancel"
		self._bttCancel.UseVisualStyleBackColor = True
		self._bttCancel.Click += self.BttCancelClick
		# 
		# label3
		# 
		self._label3.Font = System.Drawing.Font("Microsoft Sans Serif", 8.25, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, 0)
		self._label3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
		self._label3.Location = System.Drawing.Point(18, 230)
		self._label3.Name = "label3"
		self._label3.Size = System.Drawing.Size(295, 23)
		self._label3.TabIndex = 4
		self._label3.Text = "Dynamo API"
		# 
		# MainForm
		# 
		self.BackColor = System.Drawing.SystemColors.ButtonHighlight
		self.ClientSize = System.Drawing.Size(518, 260)
		self.Controls.Add(self._label3)
		self.Controls.Add(self._bttCancel)
		self.Controls.Add(self._bttExport)
		self.Controls.Add(self._groupBox2)
		self.Controls.Add(self._groupBox1)
		self.Name = "MainForm"
		self.ShowIcon = False
		self.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		self.Text = "Export Schedules"
		self._groupBox1.ResumeLayout(False)
		self._groupBox1.PerformLayout()
		self._groupBox2.ResumeLayout(False)
		self._groupBox2.PerformLayout()
		self.ResumeLayout(False)


	def ClbNaScheduleSelectedIndexChanged(self, sender, e):
		pass

	def CbxAllNoneCheckedChanged(self, sender, e):
		var =self._clbNaSchedule.Items.Count
		self._txtbTotalItems.Text = str(var)
		rangers = range(var)
		for i in rangers:
			if self._cbxAllNone.Checked == True:
				self._clbNaSchedule.SetItemChecked(i, True)
			else:
				self._clbNaSchedule.SetItemChecked(i, False)
		pass

	def TxtbTotalItemsTextChanged(self, sender, e):
		pass

	def TxtbBrowserTextChanged(self, sender, e):
		pass

	def BttBrowserClick(self, sender, e):
		fileDialog = FolderBrowserDialog()
		fileDialog.ShowDialog()
		self._txtbBrowser.Text = fileDialog.SelectedPath
		pass

	def BttCancelClick(self, sender, e):
		self.Close()
		pass
	def BttExportClick(self, sender, e):
		selected = []
		for i in self._clbNaSchedule.CheckedItems:
			selected.append(i)
#____________________________________________________________#
		nameSched = []
		for i in selected:
			nameSched.append(i.Name + ".xls")
		path = self._txtbBrowser.Text
#____________________________________________________________#
		self.result_list = []
		for index, sched in enumerate(selected):
			schedule = UnwrapElement(sched)
			fileName = nameSched[index]
			try:
				export_options = ViewScheduleExportOptions()
				schedule.Export(path, fileName, export_options)
				self.result_list.append("Schedule Exported")
			except:
				self.result_list.append("Export Failure")
		self.Close()
		
		pass

f = MainForm()
Application.Run(f)

Looks it be a CPython interop issue. Try IronPython2 as a start. Alternatively I recommend moving to C# and building this as a zero touch node.

1 Like

Hi @HAQ to use that in CPython3 try just deleting the highlighted line, because I don’t see anywhere the data visualization class is used. it might solve the issue.

there are some bugs with PythonNet 2.5x and Winforms/Wpf event handlers (in Revit 2024.2)

for now, I recommend to use Ironpython (2 or 3) or C# instead

2 Likes