Author Topic: How do I store this big list into a dictionary?  (Read 293 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 710
How do I store this big list into a dictionary?
« on: August 01, 2019, 04:48:50 AM »
Hello everyone,
I have this big, associative list of handles.. i.e.:

Code - Auto/Visual Lisp: [Select]
  1. (defun _Point ()(cdr (assoc 5 (entget (entmakex '(( 0 . "POINT")(10 0.0 0.0 0.0)))))))
  2.  
  3. (setq r ; Sample to generate such list
  4.   (
  5.     (lambda ( / L r )
  6.       (foreach x '("SS1" "SS2" "SS3" "SS4" "SS5")
  7.         (repeat 15000
  8.           (setq L (cons (_Point) L))
  9.         )
  10.         (setq r (cons (cons x L) r))
  11.         (setq L nil)
  12.       )
  13.       (reverse r)
  14.     )
  15.   )
  16. )

Which results into something like this -
Code - Auto/Visual Lisp: [Select]
  1. ; Sample list to be stored into dictionaries (r) -
  2. '( ; (car) - SS's name ; (cdr) - List of handles
  3.   ("SS1" "26C" "26B" "26A" "269" ...)
  4.   ("SS2" "270" "26F" "26E" "26D" ...)
  5.   ("SS3" "274" "273" "272" "271" ...)
  6.   ("SS4" "278" "277" "276" "275" ...)
  7.   ("SS5" "27C" "27B" "27A" "279" ...)
  8. )

Normally I use these subs from my library -
Code - Auto/Visual Lisp: [Select]
  1. ; (IncludeDataIntoMainDic "MyXrec" nil)
  2. ; (IncludeDataIntoMainDic "MyXrec" '("Custom" 2 "data"))
  3. ; xRecName - xrecord name
  4. ; dataL - basically any type of data (usually its a list) if nil, then the xrecord will be deleted.
  5. ; http://www.theswamp.org/index.php?topic=5003.0
  6. (defun IncludeDataIntoMainDic ( xRecName dataL / maindic xrec )
  7.   (cond
  8.     ( (not (eq 'STR (type xRecName))) (prompt "\nxRecName is not STR type.") )
  9.     ( (vl-some (function (lambda (x) (wcmatch (strcase xRecName) x))) '("ACAD*" "AEC*" "Ac*")) ; Being paranoid
  10.       (prompt "\nInvalid xRecord name.")
  11.     )
  12.     (t
  13.       (setq maindic (namedobjdict))
  14.       (if (setq xrec (dictsearch maindic xRecName)) (entdel (cdr (assoc -1 xrec))))
  15.       (if dataL (dictadd maindic xRecName (entmakex (append '((0 . "XRECORD") (100 . "AcDbXrecord")) (list (cons 1 (vl-prin1-to-string dataL)))))))
  16.     ); t
  17.   ); cond
  18. ); defun IncludeDataIntoMainDic
  19.  
  20.  
  21. ; (GetDataFromMainDic "MyXrec")
  22. ; http://www.theswamp.org/index.php?topic=5003.0
  23. (defun GetDataFromMainDic ( xRecName / tmp r )
  24.   (and
  25.     (setq tmp (dictsearch (namedobjdict) xRecName))
  26.     (setq tmp (cdr (assoc 1 tmp)))
  27.     (setq r (read tmp))
  28.   ); and
  29.   r
  30. ); defun GetDataFromMainDic

Where the whole list of data is converted into a string and cons-ed to the DXF 1 of the xrecord entity.
But with this approach it seems that the string is too big so the character length is exceeded (it gets up to like 27617 characters and results into malformed list on input).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)

VovKa

  • Swamp Rat
  • Posts: 1174
  • Ukraine
Re: How do I store this big list into a dictionary?
« Reply #1 on: August 01, 2019, 05:40:12 AM »
variant 1. xrecord can contain multiple 1's pairs. split the list
variant 2. use vlax-ldata-put
variant 3. do not save the handles, save GROUPs

Grrr1337

  • Swamp Rat
  • Posts: 710
Re: How do I store this big list into a dictionary?
« Reply #2 on: August 01, 2019, 07:22:43 AM »
Thanks VovKa,
Did the solution for variant 1:
Code - Auto/Visual Lisp: [Select]
  1. ;| http://www.theswamp.org/index.php?topic=55350.0
  2.  
  3. (setq r
  4.   (
  5.     (lambda ( / _Point L r )
  6.       (defun _Point ()(cdr (assoc 5 (entget (entmakex '((0 . "POINT")(10 0.0 0.0 0.0)))))))
  7.       (foreach x '("SS1" "SS2" "SS3" "SS4" "SS5")
  8.         (repeat 15000
  9.           (setq L (cons (_Point) L))
  10.         )
  11.         (setq r (cons (cons x L) r))
  12.         (setq L nil)
  13.       )
  14.       (reverse r)
  15.     )
  16.   )
  17. )
  18.  
  19. ; Sample list to be stored into dictionaries (r) -
  20. '( ; (car) - SS's name ; (cdr) - List of handles
  21.   ("SS1" "26C" "26B" "26A" "269" ...)
  22.   ("SS2" "270" "26F" "26E" "26D" ...)
  23.   ("SS3" "274" "273" "272" "271" ...)
  24.   ("SS4" "278" "277" "276" "275" ...)
  25.   ("SS5" "27C" "27B" "27A" "279" ...)
  26. )
  27.  
  28. (setq Dic "MyDictionary")
  29. (_IncludeDataIntoMainDic Dic r)
  30. (_GetDataFromMainDic Dic)
  31.  
  32. _$ (mapcar 'length (_GetDataFromMainDic "MyDictionary"))
  33. (15001 15001 15001 15001 15001)
  34. _$ (mapcar 'length r)
  35. (15001 15001 15001 15001 15001)
  36. _$ (equal r (_GetDataFromMainDic "MyDictionary") 1e-1)
  37.  
  38. (_IncludeDataIntoMainDic Dic nil)
  39. |;
  40.  
  41. ; (_IncludeDataIntoMainDic "MyDictionary" r)
  42. (defun _IncludeDataIntoMainDic ( DicName dataL / maindic subdict dic )
  43.   (cond
  44.     ( (not (eq 'STR (type DicName))) (prompt "\nDicName is not STR type.") )
  45.     ( (vl-some (function (lambda (x) (wcmatch (strcase DicName) x))) '("ACAD*" "AEC*" "Ac*")) ; Being paranoid
  46.       (prompt "\nInvalid Dictionary name.")
  47.     )
  48.     (t
  49.       (setq maindic (namedobjdict))
  50.       (if (setq dic (dictsearch maindic DicName)) (entdel (cdr (assoc -1 dic))))
  51.       (if dataL
  52.         (progn
  53.           (setq subdict (entmakex '((0 . "DICTIONARY")(100 . "AcDbDictionary"))))
  54.           (setq subdict (dictadd maindic DicName subdict))
  55.           (mapcar
  56.             (function
  57.               (lambda (x)
  58.                 (dictadd subdict (car x)
  59.                   (entmakex
  60.                     (append
  61.                       '((0 . "XRECORD") (100 . "AcDbXrecord"))
  62.                       (mapcar (function (lambda (xx) (cons 1 xx))) (cdr x))
  63.                     )
  64.                   )
  65.                 )
  66.               ); lambda
  67.             )
  68.             dataL
  69.           )
  70.         )
  71.       ); if dataL
  72.     ); t
  73.   ); cond
  74. ); defun _IncludeDataIntoMainDic
  75.  
  76. ; (_GetDataFromMainDic "MyDictionary")
  77. (defun _GetDataFromMainDic ( DicName / tmp e r )
  78.   (and
  79.     (setq tmp (dictsearch (namedobjdict) DicName))
  80.     (setq e (cdr (assoc -1 tmp)))
  81.     (setq tmp (apply (function append) (mapcar (function (lambda (x) (if (= 3 (car x)) (list (cdr x))))) tmp)))
  82.     (setq r (mapcar (function (lambda (k) (cons k (mapcar (function cdr) (vl-remove-if-not (function (lambda (x) (= 1 (car x)))) (dictsearch e k)))))) tmp))
  83.   ); and
  84.   r
  85. ); defun _GetDataFromMainDic
« Last Edit: August 01, 2019, 07:26:34 AM by Grrr1337 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)