
Hello everyone,
I am new to develop in Revit API and started with SDK samples.
I am just trying to implement ModelessForm_ExternalEvent sample, but it keeps throwing me an exception stating that "Object reference not set to an instance of an object", I am not sure whether the problem is my software version or something else, please can anyone advise !
Many thanks,
Aziz
BELOW IS THE CODE:
public class Class1 : IExternalApplication
{
public static Class1 thisApp = null;
private ExternalEventExampleDialog m_MyForm;
public Result OnShutdown(UIControlledApplication application)
{
if (m_MyForm != null && m_MyForm.Visible)
{
m_MyForm.Close();
}
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
m_MyForm = null;
thisApp = this;
return Result.Succeeded;
}
public void ShowForm(UIApplication uiapp)
{
if (m_MyForm == null || m_MyForm.IsDisposed)
{
ExternalEventExample handler = new ExternalEventExample();
ExternalEvent exEvent = ExternalEvent.Create(handler);
m_MyForm = new ExternalEventExampleDialog (exEvent, handler);
m_MyForm.Show();
}
}
}
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class Command : IExternalCommand
{
public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
Class1.thisApp.ShowForm(commandData.Application);
return Result.Succeeded;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
}
}
public class ExternalEventExample : IExternalEventHandler
{
public void Execute(UIApplication app)
{
TaskDialog.Show("External Event", "Click Close to close.");
}
public string GetName()
{
return "External Event Example";
}
}
已解决! 转到解答。