Message 1 of 5

Not applicable
10-20-2017
08:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone. I'm trying to make an add-in which uses a windows form. For that, I copied the code used in the "Getting Started" walkthrough in the Revit API guide, and modifided it. I'm always getting the same error message: "SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.". Here is the code that I've tried to use.
CsAddPanel.cs:
using System;using System.Reflection; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System.Windows.Media.Imaging; using System.Windows.Forms; namespace Walkthrough { /// <remarks> /// This application's main class. The class must be Public. /// </remarks> public class CsAddPanel : IExternalApplication { // Both OnStartup and OnShutdown must be implemented as public method public Result OnStartup(UIControlledApplication application) { // Add a new ribbon panel RibbonPanel ribbonPanel = application.CreateRibbonPanel("NewRibbonPanel"); // Create a push button to trigger a command add it to the ribbon panel. string thisAssemblyPath = Assembly.GetExecutingAssembly().Location; PushButtonData buttonData = new PushButtonData("cmdHelloWorld", "Hello World", thisAssemblyPath, "Walkthrough.HelloWorld"); PushButton pushButton = ribbonPanel.AddItem(buttonData) as PushButton; // Optionally, other properties may be assigned to the button // a) tool-tip pushButton.ToolTip = "Say hello to the entire world."; // b) large bitmap Uri uriImage = new Uri(@"C:\globe.png"); BitmapImage largeImage = new BitmapImage(uriImage); pushButton.LargeImage = largeImage; return Result.Succeeded; } public Result OnShutdown(UIControlledApplication application) { // nothing to clean up in this simple case return Result.Succeeded; } } /// <remarks> /// The "HelloWorld" external command. The class must be Public. /// </remarks> [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class HelloWorld : IExternalCommand { // The main Execute method (inherited from IExternalCommand) must be public public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements) { Form1 form1 = new Form1(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); form1.ShowDialog(); //TaskDialog.Show("Revit", "Hello World"); return Autodesk.Revit.UI.Result.Succeeded; } } }
Here's a screenshot of the form that I'm trying to use (and of the SharpDevelop views):
Finally, here's a screenshot of the error message in revit:
Thank you
Leandro
Solved! Go to Solution.