Hope someone can help with what is probably a naive question from someone just starting out on the path of programming.
I have been working on a small app for Revit 2016 and have managed to retrieve the required data from the database and display this in a ListView. Clicking a form button then creates a list of the selected items and then invokes a method (located on the form) in which the Transaction is started. It is intended that this would then action the list of selected items. The programme compiles without error or Warnings but during debugging Revit closes upon reaching the transaction with an “Access Violation” I have also noticed that the doc reference within the Transaction reference within comes up “null” during debugging.
Am I missing something with the above or is the problem as I suspect that I have left the API call and therefore need to look at External Events? For clarity the Form is Model not Modeless.
In preparation I have been exploring the code within the SDK samples on ModelessForms as well as created a simple app utilising the External Events code within the Revit 2016 Help and unfortunately I seem to run into the same problem when running them and other sample external event code I have downloaded.
Revit Error Dialog displays stating “Object reference not set to an instance of an object”
I have not amended the sample code in any way and keep getting the same error no matter which sample External events programme I try. Please enlighten me as the only way I find I really learn how to programme is through exploring working sample code.
Solved! Go to Solution.
Hope someone can help with what is probably a naive question from someone just starting out on the path of programming.
I have been working on a small app for Revit 2016 and have managed to retrieve the required data from the database and display this in a ListView. Clicking a form button then creates a list of the selected items and then invokes a method (located on the form) in which the Transaction is started. It is intended that this would then action the list of selected items. The programme compiles without error or Warnings but during debugging Revit closes upon reaching the transaction with an “Access Violation” I have also noticed that the doc reference within the Transaction reference within comes up “null” during debugging.
Am I missing something with the above or is the problem as I suspect that I have left the API call and therefore need to look at External Events? For clarity the Form is Model not Modeless.
In preparation I have been exploring the code within the SDK samples on ModelessForms as well as created a simple app utilising the External Events code within the Revit 2016 Help and unfortunately I seem to run into the same problem when running them and other sample external event code I have downloaded.
Revit Error Dialog displays stating “Object reference not set to an instance of an object”
I have not amended the sample code in any way and keep getting the same error no matter which sample External events programme I try. Please enlighten me as the only way I find I really learn how to programme is through exploring working sample code.
Solved! Go to Solution.
Solved by arnostlobel. Go to Solution.
Stephen:
Please let me understand the problem more. Do you claim that if you use one of the Modeless Dialog samples in as provided in the SDK without any further changes that it crashes when used in Revit? If so, can yuo please tell me at what line exactly does it crash?
Thank you
Stephen:
Please let me understand the problem more. Do you claim that if you use one of the Modeless Dialog samples in as provided in the SDK without any further changes that it crashes when used in Revit? If so, can yuo please tell me at what line exactly does it crash?
Thank you
To clarify my Question was in two parts
1) I have created a windows Model form that populates a List view with data from the open Revit document. I wish to then select items from this list and then through clicking a button on the form action the selected items. Unfortunately everything I seem to try doesn’t work. Is this because I have to utilise External Events in order invoke a transaction either within the Button Click or from a method resultant from the Button Click?
2) I have encountered “Object reference not set to an instance of an object” error when utilising the Revit 2016 SDK samples on ModelessForms. Happily I have identified my error and resolved this question.
After re-coding my original project in anticipation that Event Handlers are the solution to Question 1 this unfortunately has resulted in additional Questions.
The form and Event Handlers appear to work but unfortunately the code to populate the listView currently resides on the form and I have been unable to access the Method from outside the Form class. I have tried relocating the code to the Command class but unfortunately these attempts have raised the following questions:
iii) How to reference a Method on the form?
For clarity the code I have utilised to create the form and EventHandler classes is primarily that shown within the Revit 2016 Help.
Apologies for what probably is a basic coding question but this is my first time utilising event handlers which from the examples I have seen result in the form being created and shown from the Application class called from the Command class (Revit 2016 Help EventHandler code) and my usual techniques for referencing the form don’t appear to work.
Any help and examples of code would be much appreciated.
To clarify my Question was in two parts
1) I have created a windows Model form that populates a List view with data from the open Revit document. I wish to then select items from this list and then through clicking a button on the form action the selected items. Unfortunately everything I seem to try doesn’t work. Is this because I have to utilise External Events in order invoke a transaction either within the Button Click or from a method resultant from the Button Click?
2) I have encountered “Object reference not set to an instance of an object” error when utilising the Revit 2016 SDK samples on ModelessForms. Happily I have identified my error and resolved this question.
After re-coding my original project in anticipation that Event Handlers are the solution to Question 1 this unfortunately has resulted in additional Questions.
The form and Event Handlers appear to work but unfortunately the code to populate the listView currently resides on the form and I have been unable to access the Method from outside the Form class. I have tried relocating the code to the Command class but unfortunately these attempts have raised the following questions:
iii) How to reference a Method on the form?
For clarity the code I have utilised to create the form and EventHandler classes is primarily that shown within the Revit 2016 Help.
Apologies for what probably is a basic coding question but this is my first time utilising event handlers which from the examples I have seen result in the form being created and shown from the Application class called from the Command class (Revit 2016 Help EventHandler code) and my usual techniques for referencing the form don’t appear to work.
Any help and examples of code would be much appreciated.
Hi Stephen!
I am afraid it'll be rather hard helping you with specifics without seeing at least fragments of your code. However, to save you some time at least with the basic design, here're some notes:
That's pretty much it. I suggest you start with some very simple version of your dialog. Do not worry first about what you will have in the dialog eventually. Create a simplistic dialog with just two buttons - OK and Cancel. On the OK event do start a transaction, make some trivial change in the document, and close the transaction. That's it. Once you have that figured out, than you'll start adding more controls and actions to the dialog, There ought to be plenty of examples of modal dialogs in the samples provided in the SDK. (Not the two samples under the Modeless Dialog folder, though).
Good luck
Hi Stephen!
I am afraid it'll be rather hard helping you with specifics without seeing at least fragments of your code. However, to save you some time at least with the basic design, here're some notes:
That's pretty much it. I suggest you start with some very simple version of your dialog. Do not worry first about what you will have in the dialog eventually. Create a simplistic dialog with just two buttons - OK and Cancel. On the OK event do start a transaction, make some trivial change in the document, and close the transaction. That's it. Once you have that figured out, than you'll start adding more controls and actions to the dialog, There ought to be plenty of examples of modal dialogs in the samples provided in the SDK. (Not the two samples under the Modeless Dialog folder, though).
Good luck
Thanks you for the guidance. It helped confirm that I was on the right track with my initial programme (i.e. without Event Handlers). So much so that the programme was working within a couple of minutes.
Thanks you for the guidance. It helped confirm that I was on the right track with my initial programme (i.e. without Event Handlers). So much so that the programme was working within a couple of minutes.
Can't find what you're looking for? Ask the community or share your knowledge.