Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Storing Configuration Values

How can a user store data that can be accessed through lisp for use between drawing sessions. by Striker
Posted: 12 Jan 02

Ok, there are actually a few different ways you can do it.

**** OPTION 1 ****

There is a little used function in lisp that allows you to set and retrieves configuration values. To use this function, use this syntax.

To save an individual value for each drawing:

(setq vname "variablename")
(setq apname "put your program name here")
(setcfg (strcat "AppData/" apname "/" vname) "any string value")

To retrieve that data:

(setq vname "variablename")
(setq apname "put your program name here")
(setq val (getcfg (strcat "AppData/" apname "/" vname)))

The value to save must be a string value, and the retrieved value is a string as well. We convert real numbers to a string then back again. This way will only hold the required value for the current workstation.

**** OPTION 2 ****

Another way to do this is a little less secure, but allows the value to be attached with the drawing.

Using a system variable USERRx the x represents a number from 1 to 5. USERIx stores integer values and USERSx stores string values.

To save the value:
(setvar "USERR1" a)

To retrieve the value:
(setq a (getvar "USERR1"))

**** OPTION 3 ****

Place a hidden attributed block in the drawing. Create a block that will be inserted by your program, or you could alternatively have the program create an anonymous one for you automatically if the value is not found.

**** OPTION 4 ****

Register your application with the lisp function REGAPP then attach an XDATA value to an object that will not be deleted, such as title block, in that XDATA, store the data.

**** OPTION 5 ****

Create a short VBA routine that sets configuration data, and retrieves it as well. In your lisp, have the USERxx variable set to your value, then on exit of the program, have a VBA command reactor retrieve the value and save it to the registry, similar to the following:

Private Sub SaveValue()
RetVal = object.GetVariable ("USERxx")

If (RetVal <> 0) Then
SaveSetting appname:="Your Program", section:="Drawingname", _
Key:="Value", setting:=RetVal

End If

End Sub

Of course if you don't already know VBA then this will be one of the most difficult ways.

**** OPTION 6 ****

Save the value to a program configuration file:

Retrieve the value here if it exists:

(setq fn (open "drawingname.cfg" "r"))
(if fn
(setq a (read-line fn))
(close fn)
Save it here:

(setq fn (open "drawingname.cfg" "w"))
(if fn
(write-line a fn)
(close fn)

**** OPTION 7 ****

Use the Visual Lisp functions VLAX-LDATA-PUT and VLAX-LDATA-GET to store and retrieve data that will be stored as an object in the drawing. Of course this only works with R14 with Visual Lisp addon or A2k and A2k2.

Load the Visual Lisp com object:

Put the value in:

(vlax-ldata-put "ThisObject" "ThisKey" a)

Retrieve the value:

If vl-load-com is already loaded then you do not need to reload it, otherwise:

(setq a (vlax-ldata-get "ThisObject" "ThisKey"))

I hope this clears up how to store data for use between drawing sessions.

Back to Autodesk: AutoCAD FAQ Index
Back to Autodesk: AutoCAD Forum

My Archive


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close