This is unexpected. I have a custom application class called TheApp. In it I have a private bool property called IsAssembly. In my command I set this value to true then create a new document. In the event handler, I check to see if the IsAssembly is true but it returns false. The only places this property is set is in the command and the event handler.
public void NewAssembly()
IsAssembly = true;
I have a handler for DocumentCreated
private void OnNewDocument(object sender, DocumentCollectionEventArgs args)
IsAssembly = false;
Your CommandMethod is not static.
When a CommandMethod is not static (shared in VB), AutoCAD creates multiple instances of the class containing the command method, one for each document the command is used in, and invokes the method on the instance associated with the active document. In that case, the instance of the class which the command method is invoked on, is not an instance that you created yourself.
If you use non-static command methods in a class, you shouldn't create instances of the class yourself, because AutoCAD will do that for you when one of the commands is issued.
Well that is interesting. So, that defeats the purpose of my custom app class. I had the application class managing custom document classes that I was associating with the autocad Document through a dictionary. hmmm, need to redesign a little bit then.
Have you looked at this post ?
It can help in holding per document values.
That is interesting. It is almost exactly what I had written. Instead of a controller, I called the class AppData. That contained a Document/DocData dictionary and I used the Activated and ToBeDestroyed events to keep my dictionary "up-to-date". But, why would this be needed if the Document itself has a UserData property. The dictionary at that point is redundant. Not I simply create the custom DocData object and set the UserData property on the Document itself.
Thanks for the link though ...
It's quite possible that the blog post predated the addition of the UserData property.
Keep in mind that some of the material being posted on that blog is dated.
I also used a dictionary originally, but switched over to using the Document's UserData hashtable, using the type of the per-document data object as the key. I think it's preferable to a dedicated dictionary, because it makes the instance of the per-document data object easer to reach from any code that knows the type.
Start with some of our most frequented solutions to get help installing your software.