ModelessForm_ExternalEvent SDK sample

ModelessForm_ExternalEvent SDK sample

Anonymous
Not applicable
1,656 Views
5 Replies
Message 1 of 6

ModelessForm_ExternalEvent SDK sample

Anonymous
Not applicable

 

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";
}
}

0 Likes
Accepted solutions (2)
1,657 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Aziz,

 

Welcome to Revit API programming!

 

Please start with something simpler first, e.g., work through the getting started tutorials:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

Alternatively, work through the hello world samples in the developer guide:

 

http://help.autodesk.com/view/RVT/2018/ENU/?guid=GUID-93BC4416-FA94-44B3-AA66-931839DA44B4

 

Good luck and have fun!

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 6

Anonymous
Not applicable
Accepted solution

 

Hi Jeremy,

 

Thank you for your warm welcome and advice.

 

Yes, I am working through the getting started tutorials and all is going well until reaching this Modeless Form SDK sample where I got stuck. However, after more trials I tried to change something and it did magically work, I created a class instance from but not assigning it a null value. I am sharing it below in case someone else is experiencing the same issue:

 

 

// class instance
Public static Application thisApp = new Application();

 

Cheers,

Aziz

 

 

Message 4 of 6

shibuchellappan
Participant
Participant

Can you please sent me the code. i am new in revit api. 

0 Likes
Message 5 of 6

jeremytammik
Autodesk
Autodesk

Welcome to Revit programming!

 

Work through the getting started material:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

Install the Revit SDK.

 

The code is included there.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 6

tiagofrbr
Contributor
Contributor

It worked for me too, thanks!

0 Likes