User String variable not saved in drawing

I was wondering if someone knows of a way to save a string value inside a drawing, which can later be recalled when the drawing is reopened. The USERi1~5 and USERr1~5 system variables are saved with the drawing, but the string ones, USERs1~5 are not. I would appreciate if someone knows of a work-around.

Thanks!

Comments

  • Hi Brian,

    The Dictionary functions will do this very well and are less likely to be accidentally overwritten than the the user variables.

    The thread below is helpful:

    http://discussion.autodesk.com/forums/thread.jspa?messageID=5058361&#5058361

    Otherwise you can use attributes stored in a block.

    Regards

    Dan

  • Thanks Dan for your useful reply. The Dictionary might not be the best vehicle for my needs. You see, I need to store a couple of unique string values inside each given drawing. When a particular drawing is opened, a lisp routine checks for the existence of these variables, and performs certain tasks, if found. I used to write these variables to INI files, using the same drawing name, but the drawback to that is house-keeping - if the drawing is deleted, its matching INI file is still lingering on, cluttering the file system.

  • Brian, I think Dan pointed you in a good direction. With a dictionary you can store your data and retrive it with lisp. You can create a dictionary directly in the Named Object Dictionary (NOD) in a manner it will not get purged and it is not attached to any entity so it will not get deleted. There are plenty of examples around of utility functions for creating and accessing dictionaries and xrecords.

    IMHO they are pretty cool!

  • XData is another alternative. XData attached to Layer 0 is secure, easily accessible, highly discreet, and perhaps slightly easier to program in Lisp than Dictionaries. While not saving User Strings is compatible with ACAD, I could never understand why Reals and Integers are saved, but not Strings.

  • Bonjour,

    I'm just starting digging into dictionaries (buzy on layers management).

    1. Greg Skelhorn said there are plenty of resources for creating and accessing dictionaries and xrecords.

    Could you suggest some best best bets, among these resources (webSites?) for such generic functions?

    2. As a newbie, despite some reading gone throuhgh already,  I'm looking for a good explanation of the difference/complementarity/dependencies among dictionaries/ Xdatas / Xrecords, and respective use-cases.

    Does someone have a good reference about this?

    On forward, thank you

     

     

  • I don't have much time at the moment but here are a couple of resources:

    http://www.afralisp.net/lisp/dict.htm  (note this site does not like Firefox for me use IE or veiw with no page style in ffox)

    In general theswamp.org is a really useful community.

    http://www.theswamp.org/index.php?topic=23294.msg281005#msg281005  (examples of xrecord and xdata functions)

    http://www.theswamp.org/index.php?topic=26380.msg318347#msg318347 (application using dictionary and xrecord to store data, you may need to register to see the file link)

    Post back if you need more...

  • Thanks for quick answer

  • I had the Afralisp reference, very good indeed.

    I can start trsts with that.

    At swamp,the propsed code is in VisualLisp.

    Did I misunderstand, or VisualLispis only on Autocad package, not on Bricscad?

     

    Greetings

  • If you are using the latest version of Bricscad there is support for a wide range of visual lisp functionality. The referenced length reactor code seems to work in my v10 installation.

    Use LengthReactorAdd to connect a line with a text entity. Change the line by grip editing and the text will update.

    Close, save and re-open the drawing, load the lisp again and run (LengthReactorStartup T) to recreate the reactors based on data saved in the dictionary.

    Below are a few functions from my library that may provide some ideas if not using VLisp. I am not a great coder so take it all with a rather large grain of salt and there may be other dependencies I missed in the copy / paste.

    defun nss:get_dict (dname parent_dict / dict)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Function to get a dictionary by name from a given parent. A new dictionary
    ;;; will be created if one cannot be found.
    ;;; Input: dname <-- string name of dictionary to get or make
    ;;; if it does not exist.
    ;;; parent_dict <-- the dictionary entity the dictionary of interest
    ;;; is in. Use (namedobjdict) to insert in the NOD.
    ;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;test if dictionary is already present in the main dictionary
    (if (not (setq dict (dictsearch parent_dict dname)))
    ;;if not found create a new one
    (progn
    (setq dict
    (entmakex
    (list
    '(0 . "DICTIONARY")
    '(100 . "AcDbDictionary")
    )
    )
    )
    ;and add it to the parent dictionary
    (setq dict
    (dictadd parent_dict dname dict)
    )
    );_ end progn
    (progn
    ;;else return its entity name
    (setq dict (cdr (assoc -1 dict)))
    );_ end else progn
    );_ end if
    );_ end defun
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


    (defun nss:put_xrec_in_dict (xrec dict / name )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Function to add or replace an xrecord in a dictionary.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (setq name (cdr (assoc 2 (cdr (entget xrec)))))
    (if (dictsearch dict name)
    (progn
    (dictremove dict name)
    )
    )
    (dictadd dict name xrec)
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun nss:make_pt_xrec (k x y z d )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; 2009-09-20: GDS: Pulled out of txt_pt_to_xrec for wider use.
    ;;; Should generalize this more and move into NSDict.lsp
    ;;; All error checking must be done higher up.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (entmakex
    (list
    '(0 . "XRECORD")
    '(100 . "AcDbXrecord")
    (cons 2 k)
    (list 10 x y z)
    (cons 1 d)
    )
    )
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun nss:txt_pt_to_xrec ( pt_list / k x y z d)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Function to create an xrecord entity from a text point list given as:
    ;;; (name northing easting elevation decription)
    ;;; e.g.: ("3" "4957089.60950" "5568211.18416" "99.20000" "DH")
    ;;;
    ;;; 20009-09-20: GDS: extracted the code for xrec creation.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (setq k (car pt_list) ; The point name is the key
    y (atof (cadr pt_list)) ; The northing is the y
    x (atof (caddr pt_list)) ; The easting is the x
    z (atof (cadddr pt_list)) ; The elevation is the z
    d (last pt_list) ; The description
    )

    (nss:make_pt_xrec k x y z d)
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun nss:remove_all_points ( / nss_dict)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Function to clear the POINTS dictionary. (del and recreate dictionary)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (dictremove (nss:rootdict) "POINTS")
    (setq nss:*ptdict* NIL)
    (nss:ptdict)
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun nss:remove_point (pt_name / points_dict)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Function to remove a point from the POINTS dictionary by name.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (dictremove (nss:ptdict) pt_name)
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun nss:get_point ( pt_name / )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Function to get point information from an xrecord.
    ;;; The xrecord is expected to contain:
    ;;; - code 2 = point name
    ;;; - code 10 = 3d coordinates of the point
    ;;; - code 1 = point decription
    ;;;
    ;;; 2009-09-20:GDS: changed to return the cdr of the dictsearch
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (cdr (dictsearch (nss:ptdict) pt_name))
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
This discussion has been closed.