Aftertouch Posted January 2, 2017 Share Posted January 2, 2017 Hello all, Is there a way to store a bunch of custom variables? I know about the 'UserI1' etc. But i got like 20 variables... is it possible to store a whole list or something? Suomething like '("1")("2")("2")("1") ?? i have been searching for a while but cant find anything usefull. :-( Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 2, 2017 Share Posted January 2, 2017 Write the data to a text file / drawing dictionary. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted January 2, 2017 Share Posted January 2, 2017 ... Or use the registry. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted January 2, 2017 Share Posted January 2, 2017 As I believe the OP is/speaks Dutch this may be of interest: http://www.cadsite.be/smf/index.php?topic=6383.msg33377#msg33377 Quote Link to comment Share on other sites More sharing options...
Grrr Posted January 2, 2017 Share Posted January 2, 2017 As I believe the OP is/speaks Dutch this may be of interest:http://www.cadsite.be/smf/index.php?topic=6383.msg33377#msg33377 Nice functions you got there, Roy! I'll try to learn something from them, since dealing with dictionaries is not my best thing. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 2, 2017 Share Posted January 2, 2017 ... Or use the registry. ...Sparingly. I would hope that the OP would use a single key to store multiple values if pursuing this route, rather than bloat the registry with 20 separate keys per app... Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 3, 2017 Share Posted January 3, 2017 (edited) Here is another dictionary example, you can make as many variables as you want I would use something like a Var1 Var2 etc. ; xdata sample code ; By Alan H ; sample (setq varx "item1")(setq valx 23)(get-or-make-Xrecord) (defun get-or-create-Dict (/ adict) ;;test if "BIGAL" is already present in the main dictionary (if (not (setq adict (dictsearch (namedobjdict) "BIGAL"))) ;;if not present then create a new one and set the main ;; dictionary as owner (progn (setq adict (entmakex '((0 . "DICTIONARY")(100 . "AcDbDictionary")))) ;;if succesfully created, add it to the main dictionary (if adict (setq adict (dictadd (namedobjdict) "BIGAL" adict))) ) ;;if present then just return its entity name (setq adict (cdr (assoc -1 adict))) ) ) (defun get-or-make-Xrecord ( / adict anXrec) (cond ;;first get our dictionary. Notice that "BIGAL" will be ;;created here in case it doesn't exist ((setq adict (get-or-create-Dict)) (cond ;;if "BIGAL" is now valid then look for "BIGALVARS" Xrecord ((not (setq anXrec (dictsearch adict varx))) ;the variable BIGALvars is name of xrecord so need to be a variable to add lots ;;if "BIGALVARS" was not found then create it ;(setq anXrec (entmakex '((0 . "XRECORD") (setq anXrec (entmakex (list (cons 0 "XRECORD") (cons 100 "AcDbXrecord") (cons 1 varx) (cons 40 valx) ) ) ) ;;if creation succeeded then add it to our dictionary (if anXrec (setq anXrec (dictadd adict varx anXrec))) ) ;;if it's already present then just return its entity name (setq anXrec (cdr (assoc -1 (dictsearch adict varx))) ) ) ) ) ) ; sample (setq varx "item1")(setq valx 0)(getBIGALvars) (defun getBIGALvars ( / vars varlist) ;;retrieve XRecord "varx" from dictionary "BIGAL" ;;which in turn calls both functions above (setq vars (get-or-make-Xrecord)) ;;if our Xrecord is found, then get values in group code (cond (vars (setq varlist (entget vars)) (setq Itemx (cdr (assoc 1 varlist))) (setq Itemans (cdr (assoc 40 varlist))) ) ;;otherwise return nil (T nil) ) (alert (strcat "Var name " itemx "\nItem value " (rtos itemans 2 0))) ) Edited January 5, 2017 by BIGAL Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted January 3, 2017 Share Posted January 3, 2017 This topic may be of interest : https://www.theswamp.org/index.php?topic=50628.msg557923#msg557923 M.R. Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted January 3, 2017 Author Share Posted January 3, 2017 Thanks for all your replies. I think a dictionary will work best for me. :-) @BIGAL: i cannot seen to get your code to work? Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted January 3, 2017 Share Posted January 3, 2017 ...Sparingly. I would hope that the OP would use a single key to store multiple values if pursuing this route, rather than bloat the registry with 20 separate keys per app... I have a BricsCAD .arg file here with 1725 lines. Adding a mere 20 keys to the registry hardly constitutes bloat. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 4, 2017 Share Posted January 4, 2017 Aftertouch I will check it, I changed a couple of things for copyright reasons may have upset it somewhere. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 5, 2017 Share Posted January 5, 2017 (edited) Sorted it out needed an example how to use code, I wrote it as part of a bigger program. Re did code to make it a bit more generic next rev would be dictionary name. (setq itemx "val1") (setq valx 20) (get-or-make-Xrecord) (setq itemx "val2") (setq valx 40) (get-or-make-Xrecord) ; ok to retrieve a value (setq varx "val2") (setq va1 0) ; dummy value required so use 0 (getBIGALvars) ;this returns answer which is 40 (setq varx "val1") (setq valx 0) (getBIGALvars) ; this returns answer 20 ; not tested ;For your example '("1")("2")("2")("1") need a repeat loop of the 3 lines use (setq lst (list 1 2 2 1)) (repeat (setq x (length lst)) (setq varx (strcat "Val" (rtos x 2 0))) (setq valx (nth (setq x (- x 1)) lst)) (get-or-make-Xrecord) ) ; to retrieve do repeat again or single (setq varx "val1") (setq valx 0) (getBIGALvars) returns value for variable val1 Edited January 5, 2017 by BIGAL Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted January 5, 2017 Author Share Posted January 5, 2017 Thanks BIGAL, Ill see if i can get this to work. I hope i got some time this week to work with it. Thanks for the code! Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted January 5, 2017 Share Posted January 5, 2017 I am no expert when it comes to dictionaries or Xdata / Xrecords, but aren't they document dependent? If I wanted to store variables I would have previously used setcfg and getcfg, but being that those functions are going to the wayside even Autodesk recommends using the registry. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 6, 2017 Share Posted January 6, 2017 Hippe013 your correct and as Lee answered in a very early post write an external file is simplest way, if you want a variable to be same across all drawings. So the choice is with Aftertouch. Having been involved in something like this with house walls the widths change depending on materials so I am half way through go home and continue next day with correct wall sizes set, open another dwg again correct wall sizes set for that wall material type in that dwg. Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted January 6, 2017 Author Share Posted January 6, 2017 In my case, i want all my 'custom' variables to be drawing dependent. So the dictionary is a perfect solution for me. :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.