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

What is happening in DocumentCreated?

5 REPLIES 5
Reply
Message 1 of 6
mbujak
632 Views, 5 Replies

What is happening in DocumentCreated?

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.

 

Any ideas?

 

[code]

[CommandMethod("IFX_NEW_ASSEMBLY", CommandFlags.Session)]

public void NewAssembly()

{

     IsAssembly = true;

     Application.DocumentManager.Add(null);

}

[/code]

 

I have a handler for DocumentCreated

[code]

private void OnNewDocument(object sender, DocumentCollectionEventArgs args)

{

       if(IsAssembly)

       {

            ....Do something.

            IsAssembly = false;

       }

}

[/code]

 

-Mike

5 REPLIES 5
Message 2 of 6
DiningPhilosopher
in reply to: mbujak

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.

 

 

Message 3 of 6
mbujak
in reply to: DiningPhilosopher

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.

 

Thanks

 

- Mike

Message 4 of 6
Balaji_Ram
in reply to: mbujak

Have you looked at this post ?

http://adndevblog.typepad.com/autocad/2012/08/managing-events-at-a-per-document-level.html

 

It can help in holding per document values.



Balaji
Developer Technical Services
Autodesk Developer Network

Message 5 of 6
mbujak
in reply to: Balaji_Ram

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 :)...

 

-Mike

 

 

Message 6 of 6
DiningPhilosopher
in reply to: mbujak

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.

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