.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SetValue Method Blows Up

2 REPLIES 2
Reply
Message 1 of 3
LialAtArnold
227 Views, 2 Replies

SetValue Method Blows Up

When I execute the code below, the "useThisEntityResult.SetValue(e.Result.ObjectId, 0);" line blows up and causes AutoCAD to abort.
Why??
I want to use the objectId from the Command prompt selection and pass it to an existing method that uses the ObjectId array.

{code}

static ObjectId[] useThisEntityResult = null;

private static void callback_promptEntityResult(object sender, PromptEntityResultEventArgs e)
{
MessageBox.Show("Starting callback:: promptEntityResult");

//Set up a reference to the AutoCAD editor
Autodesk.AutoCAD.EditorInput.Editor Ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

//Get the objectID of the selected object and place in the global var
useThisEntityResult.SetValue(e.Result.ObjectId, 0);

MessageBox.Show("Selection result: " + e.Result.ObjectId.ToString());

//Remove the event handler
Ed.PromptedForEntity -= new PromptEntityResultEventHandler(callback_promptEntityResult);

} //End Method callback_promptEntityResult
{code}
2 REPLIES 2
Message 2 of 3


I think you're getting a Null Reference Exception because your array has no size. if you Redim useThisEntityResult(0) before calling .SetValue. {I write in VB, but I recall being chastised about this before, in c# i think that would be Redim useThisEntityResult(1)}

Dave O.                                                                  Sig-Logos32.png
Message 3 of 3
LialAtArnold
in reply to: LialAtArnold

Chief,
Thanks for the feedback!

I ended up making the following changes to get it to work:

In the declaration I newed up the array and gave it 5 entries.
static ObjectId[] useThisEntityResult = new ObjectId[5];

Then in the method I initialized the array to clear it:

useThisEntityResult.Initialize();

Then was able to assign a value to it using the SetValue() method.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost