Turn custom Service on/off per Drawing

Turn custom Service on/off per Drawing

Anonymous
Not applicable
731 Views
2 Replies
Message 1 of 3

Turn custom Service on/off per Drawing

Anonymous
Not applicable

Hello,

I have a custom service that logs different events in a Document to a text file for review at a later date.

There is desire for this to be a toggle-able feature for any given document. We want the default to be off, and the user should be allowed to turn it on if it's desired for that given drawing. What is the best way to store whether or not the logging service should be used in a drawing?  Is this something that should be stored in XData/XRecord, or am I thinking along the wrong lines there? 

 

Thanks in advanced for any input on this 🙂

0 Likes
732 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor

It would depend on whether the on/off flag only takes effect within one AutoCAD session, or across multiple AutoCAD session (i.e. the drawing has to store/remember the on/off flag).

 

Obviously, if only in one AutoCAD session, things would be really easy: the logging app (AutoCAD add-in, I suppose) could simply keep a drawing list that user choose to run logging process against to. Or, as alternative, you can set flag as "per drawing" data, such as Document.UserData (a HashTable type), and let the logging process check each open drawing's UserData to decide if the flag is set or not, or, on or off.

 

If the flag has to take effect acrossing AutoCAD session, obviously, you need to save it with drawing. Since it is "per drawing" and most likely has nothing to do with the contents/individual entities, I'd use NamedDictionary (thus, the actual flag data would be XRecord to be added into your named dictionary).

 

I would do this roughly like this:

 

1. Make the Add-in implement IExtenstionApplication, so that when the app is loaded, the code would check each opened drawing's NamedDictionary. If the flag dictionary is found, retrieve the flag data from the dictionary to a custom class, then save the class in the Document.UserData;

2. If user chooses to set the flag on/off on a opened drawing, add/remove the custom flag data to/from Document.UserData;

3. Handle document event (DocumentToBeDestroyed, for example), where the Document.UserData is examined for the flag data, save it into flag named dictionary, or clear the dictionary, depending on the flag being on or off.

 

Since the flag is across drawing session and set by certain user, the flag data may want to also include user name/computer name..., so that when the drawing is opened by other user, he/she may have his/her own flag set on/off (if the business operation workflow has such requirement).

 

Just an idea. There could be many other options.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks for the reply.  The flag would definitely need to persist between sessions, and I think I was thinking along the same lines as that when i asked the question.  

 

A follow up question I have though is related to the flags.  I am not familiar with what you mean by the flag.  Is it simply a string or bool stored under a variable name in the User.Data?  Or is it a specific structure or Object I need to store in the drawing?  I am just not familiar with the terminology you used, so apologies if it's a lot simpler than I am making it.  

0 Likes