aloy Posted September 23, 2017 Share Posted September 23, 2017 Hello everybody, How can I save data accumulated by a variable at the end of running a lisp routine and save it along with the drawing to be used at a later session. In my case the data relates to a list of lists (about fifty) each with about twenty pairs of real numbers which again can be considered as lists. Thanking in advance, Aloy Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 23, 2017 Share Posted September 23, 2017 If the data is drawing-specific, you could store the data in a drawing dictionary. Quote Link to comment Share on other sites More sharing options...
aloy Posted September 23, 2017 Author Share Posted September 23, 2017 Hi Lee Mac, Actually I searched this topic before writing this post. I came across some discussions you had with industry specialists way back in 2009 where setenv and getenv were discussed. Since it did not give me a clue I searched further and came across the dictionary and Xrecords by AfraLisp. I found it too lengthy and thought there would be a ready made answer for the problem I have. Say, just one line of code, just like the solution to one of my problems previously. Thanks for the reply. Aloy Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted September 23, 2017 Share Posted September 23, 2017 Study this topic : https://www.theswamp.org/index.php?topic=50628.msg557923#msg557923 M.R. Quote Link to comment Share on other sites More sharing options...
aloy Posted September 23, 2017 Author Share Posted September 23, 2017 Actually my data is not drawing specific as can be seen from my above description. I understand that a dictionary is a container that holds the data thst relate to various entities in the drawing. A layer has the code 8 and it can be retrieved by its name. What is the code for a variable that does not describe an entity. I will study AfraLisp's tutorial further as the process seem a bit complicates as can be seen from Marco's post. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 24, 2017 Share Posted September 24, 2017 Setting up the dictionary should be feasible you could take each list and say make it into a csv text so can be easily pulled apart, just repeat for each inside list like L1 l2 l3 would be data variable name. The code is a bit rough as I have not cleaned it up but shows how you can save a sequence of variables. It uses the afralisps core code. But is easy to understand as it saves some variables. traffic-dictionary.lsp Quote Link to comment Share on other sites More sharing options...
aloy Posted September 24, 2017 Author Share Posted September 24, 2017 Hi Bigal, No luck yet. I get the error message as: ; error: bad argument type: stringp ((0.0 10.5) (3.0 7.0) (6.0 6.0) (9.0 5.5) (12.0 7.6) (15.0 4.0) (18.0 6.5) (21.0 5.0) (24.0 2. (28.0 3.5)) What is given is my list that I want to save. When I change it to string "myname" it again gives error message to say that incorrect group code 40. But 40, I know is for text. How to solve this problem. I know the easiest way out is the cut and paste method which is manual. (sorry cannot get rid of the smiley which has replace .8 and ') ' ) Thanks, Aloy Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 25, 2017 Share Posted September 25, 2017 Had a play with this code but need to look more into Vl-Ldata (setq lst (List (list 0.0 10.5) (list 3.0 7.0) (list 6.0 6.0) (list 9.0 5.5) (list 12.0 7.6) (list 15.0 4.0) (list 18.0 6.5) (list 21.0 5.0) (list 24.0 2.0) (list 28.0 3.5))) (setq lst (reverse lst)) ; so next bit does from 1st to last. (defun savepts-dict (lst / y xy pt itemnum) (if (not get-or-create-Dict)(Load "Dictionary example 2")) (setq y 1) ; use with item+1 (repeat (setq x (length lst)) (setq pt (nth (setq x (- x 1)) lst)) (setq xy (list (car pt) (cadr pt) 0.0 )) (setq itemnum (strcat "Item" (rtos y 2 0))) (get-or-make-Xrecord itemnum xy) (setq y (+ y 1)) ) ) ; defun savepts-dict ; for testing ; now do reverse and get points ; need some help here how many in dictionary last point crashes (setq Y 1) (setq itemnum (strcat "Item" (rtos y 2 0))) (while (/= nil (getBIGALvars itemnum 0)) (princ "\n") (setq y (+ y 1)) (setq itemnum (strcat "Item" (rtos y 2 0))) ) ; xdata sample code dictionary example 2 ; By Alan H ; sample (setq varx "Item1")(setq valx "2,3") ; (get-or-make-Xrecord varx valx) (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 (varx valx / 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 10 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 (getBIGALvars "Item1" 0) (defun getBIGALvars (varx valx / vars varlist) ;;retrieve XRecord "varx" from dictionary "BIGAL" ;;which in turn calls both functions above (setq vars (get-or-make-Xrecord varx valx)) ;;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 10 varlist))) ) ;;otherwise return nil (T nil) ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 25, 2017 Share Posted September 25, 2017 After all of the above code try this 2 line answer. (vlax-ldata-put "BIGAL" "PTS" lst) (setq pts (vlax-ldata-get "BIGAL" "PTS")) ; just for reference if you have multiple entries under say "BIGAL" multiple pt sets. PTS1 PTS2 etc (vlax-ldata-list "BIGAL" ) Quote Link to comment Share on other sites More sharing options...
aloy Posted September 25, 2017 Author Share Posted September 25, 2017 Hi Bigal, I get the following error message when trying to load the first set of codes (point list lst): ; error: bad DXF group: (10 . 0) Aloy Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted September 25, 2017 Share Posted September 25, 2017 Actually my data is not drawing specificIf that is still the case: why do you now attempt to store it in a drawing? Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 25, 2017 Share Posted September 25, 2017 I will check did have that during testing may have posted incorrect version very subtle changes to dxf codes, but use the second post 1 line does the same as about 20 lines of code. I know which I will use in future. Quote Link to comment Share on other sites More sharing options...
aloy Posted September 25, 2017 Author Share Posted September 25, 2017 Roy_043, The list I have given in my previous post is a typical one to be generated by my program which makes use of large number of 3D points in the drawing. The 3D points are used to make a TIN surface as in Civil 3D. At the end I have a list of such lists. The dictionary I believe is autocad's contraption to save the the entities in the drawing which has DXF codes for each, but there is no way of keeping Xrecord for variable other than strings. This is what I am trying to solve with Bigal. Of course I can cut and paste to a new file. I need to save it and reuse over and over again with revised vertical alignments to generate cross section. Sorry you may not get it if you are not familiar with road design. Regards, Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 25, 2017 Share Posted September 25, 2017 The dictionary I believe is autocad's contraption to save the the entities in the drawing which has DXF codes for each, but there is no way of keeping Xrecord for variable other than strings. I would suggest that you study Dictionaries in more detail... Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted September 25, 2017 Share Posted September 25, 2017 I also use dictionaries for both strings and ints. (defun GetOrAddDict ( parentDict dictName ) (cond ((cdr (assoc -1 (dictsearch parentDict dictName))))((dictadd parentDict dictName (entmakex '( (0 . "DICTIONARY")(100 . "AcDbDictionary")))))) ) (defun AddOrReplaceXrec ( parentDict xrecName xrecData / xrec ) (if (setq xrec (dictsearch parentDict xrecName)) (entdel (cdr (assoc -1 xrec)))) (dictadd parentDict xrecName (entmakex (append '((0 . "XRECORD")(100 . "AcDbXrecord")) xrecData))) ) (defun GetXrec ( xrec parentDict / dict) (setq dict (GetOrAddDict (namedobjdict) parentDict)) (setq data (dictsearch dict xrec )) ; Entity list. (setq data (cdr (member (assoc 280 data) data))) (setq data (cdr (assoc 1 data))) ) (defun BuildDictionary ( / dict1 dictfase fasecounter ribbonvalue ) (if (not (setq dict (dictsearch (namedobjdict) "YOUR_DICT"))) (progn (setq dict (GetOrAddDict (namedobjdict) "YOUR_DICT")) (AddOrReplaceXrec dict "SETTINGS" (list (cons 1 "SOMETHING"))) ) (progn (princ "Drawing has a dictionary.") ) ) ) (BuildDictionary) I stored a variable named SETTINGS in 'YOUR DICT") Command: (getxrec "settings" "your_dict") "SOMETHING" Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 25, 2017 Share Posted September 25, 2017 I also use dictionaries for both strings and ints. (defun GetOrAddDict ( parentDict dictName ) ... ) (defun AddOrReplaceXrec ( parentDict xrecName xrecData / xrec ) ... ) Original source: https://www.theswamp.org/index.php?topic=5003.msg60453#msg60453 Quote Link to comment Share on other sites More sharing options...
aloy Posted September 26, 2017 Author Share Posted September 26, 2017 Hi, Aftertouch, Yes, it would return "SOMETHING" when tested, however does not work with my list. I do not know which group code to use with the list. Regards, Aloy. Quote Link to comment Share on other sites More sharing options...
aloy Posted September 26, 2017 Author Share Posted September 26, 2017 Hi, Lee Mac, Had a look at the code given in the 'SWAMP'. Yes the sample test given with code returns the entity lists of the two sub-dictioneries and the two predefined xrecords titled "KOOL". It doesn't seems to give a way out as to how to attache characters and spaces involved in my list with a code. Hence I am still at square number one. Regards, Aloy Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted September 26, 2017 Share Posted September 26, 2017 @ Lee Mac, Correct, thats most of the source code. Also found the GetXRec somewhere else, dunno where anymore. @ Aloy The groupcode doesnt matter at all. You can use any number for that, i always make many XRecords, with only a groupcode 1, and the content. Code below is just a quick example. Just to give your the idea. (AddOrReplaceXrec dict "Variable1" (list (cons 1 "2"))) (AddOrReplaceXrec dict "Variable2" (list (cons 1 "0"))) (AddOrReplaceXrec dict "Variable3" (list (cons 1 "1"))) (AddOrReplaceXrec dict "Variable4" (list (cons 1 "3"))) (setvar "LTSCALE" (GetXrec "YOUR_DICT" "Variable1")) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 26, 2017 Share Posted September 26, 2017 Aloy did you not look at this one line solution the lst I used for testing was your LST ; saves a list (setq lst (List (list 0.0 10.5) (list 3.0 7.0) (list 6.0 6.0) (list 9.0 5.5) (list 12.0 7.6) (list 15.0 4.0) (list 18.0 6.5) (list 21.0 5.0) (list 24.0 2.0) (list 28.0 3.5))) (setq lst (reverse lst)) ; so next bit does from 1st to last. (vlax-ldata-put "ALOY" "PTS" lst) ; saves lst2 (vlax-ldata-put "ALOY" "PTS2" LST2) ; get a list (setq lst (vlax-ldata-get "ALOY" LST2 )) 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.