Loading Macro Failed after Importing System.Windows.Forms

Loading Macro Failed after Importing System.Windows.Forms

luke_cunninghamE5NPR
Explorer Explorer
165 Views
2 Replies
Message 1 of 3

Loading Macro Failed after Importing System.Windows.Forms

luke_cunninghamE5NPR
Explorer
Explorer

Hello everyone,

 

Right now I'm having an issue with a Macro I'm building in SharpDevelop (in Revit 2024). After some time developing my Macro I decided I wanted to use the OpenFileDialog function of System.Windows.Forms so that the user can select multiple files from a folder. I added it to my Refences (along with System.Drawing) and added it into my code (see attached image).

 

luke_cunninghamE5NPR_0-1761250971268.png

 

The macro builds successfully but when I go back to Revit the Macro Manager does not let me run it, saying it failed to load.

 

luke_cunninghamE5NPR_2-1761252760917.png

[The text below the macro says 'Loading the macro failed. Rebuilding the module may resolve this issue.']

 

If I go back into my code, comment out the 'from System.Windows.Forms import *', and rebuild, the Macro Manager works just fine. Other than the code I've written, everything should be at its default setting. Any help would be appreciated!

0 Likes
166 Views
2 Replies
Replies (2)
Message 2 of 3

luke_cunninghamE5NPR
Explorer
Explorer

As an experiment I tried to import another reference called 'System.IO' using the same process as System.Windows.Forms and it worked just fine. I am able to access all it's functions and run the macro, so I'm not sure why the Forms reference is not working.

0 Likes
Message 3 of 3

luke_cunninghamE5NPR
Explorer
Explorer

I wanted to provide an update on this topic incase others had this issue. All I wanted to do was allow the user to select specific files from the file system. Unfortunately, I was never able to get this to work correctly but I found a workaround using Revit's native file explorer, which can be called using 'FileOpenDialog'. From there I can get the rest of the files in that directory using 'System.IO.Directory.GetFiles'. It's not ideal but at least it creates a user interface.

0 Likes