Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can a user store data that can be accessed through lisp for use between drawing sessions.

Storing Configuration Values

How can a user store data that can be accessed through lisp for use between drawing sessions.

by  Striker  Posted    (Edited  )
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
(progn
(setq a (read-line fn))
(close fn)
)
)
Save it here:

(setq fn (open "drawingname.cfg" "w"))
(if fn
(progn
(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:
(vl-load-com)

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:

(vl-load-com)
(setq a (vlax-ldata-get "ThisObject" "ThisKey"))


I hope this clears up how to store data for use between drawing sessions.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search