.NET

Reply
Distinguished Contributor
Dale.Bartlett
Posts: 175
Registered: ‎01-06-2003
Message 1 of 4 (205 Views)
Accepted Solution

Save command defaults

205 Views, 3 Replies
01-02-2012 12:52 AM

Hi All, I have exhausted my searching, so here goes. I am looking for "best practice" example code for saving/re-using command default values from previous user input. Similar to lisp globals, but for C# (or VB.net); ie next time the command is run in a given session, the user's previous input is the default <>. I am currently using Properties.Settings to persist these values. Thanks, Dale 

In our apps we have solved this by the default app.config of the dll.

 

In VS right-click on the Project -> Properties -> Settings.

 

That way you will store your settings and have them back when you start Acad again.

 

Then you insert in your code :

 

using [YourNamespace].Properties;

 

// start input gathering

      PromptDoubleOptions LenghtOptions = new PromptDoubleOptions( "Enter lenght : " );
      LenghtOptions.UseDefaultValue = true;
      LenghtOptions.DefaultValue = Settings.Default.MyLenght;
      PromptDoubleResult LenghtResult = Ed.GetDouble( LenghtOptions );
      if ( LenghtResult.Status != PromptStatus.OK )
      {
        return;
      }
      Settings.Default.MyLenght= LenghtResult.Value;

      Settings.Default.Save( );

 

ADN Support Specialist
StephenPreston
Posts: 429
Registered: ‎05-22-2006
Message 2 of 4 (197 Views)

Re: Save command defaults

01-02-2012 08:53 AM in reply to: Dale.Bartlett

I wouldn't say there is a definite best practice. There are several ways of doing this.

 

If you're not defining all your CommandClass CommandMethods as static/shared functions, then an instance of your class is created by AutoCAD for each document your command is run in. In that scenario, you can simply store your default values as member variables of your class. That way you're storing 'per document' data.

 

Alternatively, you can store 'per document' data using the Document.UserData property. 

 

Or if you want global (cross document) data, you can simply store settings in static/shared member variables for your class. 

 

Finally, if you're happy to use an installer that requires admin privileges to deploy your app, then you can make use of the Variable class from the Runtime namespace to create your own AutoCAD sysvars. (My recollection is that the registry data for this class has to be setup before AutoCAD launches, but you should check that).

 

 

Cheers,

Stephen Preston
Autodesk Developer Network
Valued Contributor
ognyandim
Posts: 59
Registered: ‎05-21-2008
Message 3 of 4 (182 Views)

Re: Save command defaults

01-02-2012 11:45 PM in reply to: Dale.Bartlett

In our apps we have solved this by the default app.config of the dll.

 

In VS right-click on the Project -> Properties -> Settings.

 

That way you will store your settings and have them back when you start Acad again.

 

Then you insert in your code :

 

using [YourNamespace].Properties;

 

// start input gathering

      PromptDoubleOptions LenghtOptions = new PromptDoubleOptions( "Enter lenght : " );
      LenghtOptions.UseDefaultValue = true;
      LenghtOptions.DefaultValue = Settings.Default.MyLenght;
      PromptDoubleResult LenghtResult = Ed.GetDouble( LenghtOptions );
      if ( LenghtResult.Status != PromptStatus.OK )
      {
        return;
      }
      Settings.Default.MyLenght= LenghtResult.Value;

      Settings.Default.Save( );

 

Distinguished Contributor
Dale.Bartlett
Posts: 175
Registered: ‎01-06-2003
Message 4 of 4 (156 Views)

Re: Save command defaults

01-03-2012 09:30 PM in reply to: Dale.Bartlett

Thanks for the replies. That is exactly the information I needed. I am currently using Settings.Default.Save to persist between sessions, which seems more logical to the user rather than "start again". The code sample will help me tidy mine a little. Regards, Dale  

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.