Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
How do I store this big list into a dictionary?
« previous
next »
Print
Pages: [
1
] |
Go Down
Author
Topic: How do I store this big list into a dictionary? (Read 1537 times)
0 Members and 1 Guest are viewing this topic.
Grrr1337
Swamp Rat
Posts: 812
WWW
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]
(
defun
_Point
(
)
(
cdr
(
assoc
5
(
entget
(
entmakex
'
(
(
0
.
"POINT"
)
(
10
0.0
0.0
0.0
)
)
)
)
)
)
)
(
setq
r
; Sample to generate such list
(
(
lambda
(
/
L r
)
(
foreach
x '
(
"SS1"
"SS2"
"SS3"
"SS4"
"SS5"
)
(
repeat
15000
(
setq
L
(
cons
(
_Point
)
L
)
)
)
(
setq
r
(
cons
(
cons
x L
)
r
)
)
(
setq
L
nil
)
)
(
reverse
r
)
)
)
)
Which results into something like this -
Code - Auto/Visual Lisp:
[Select]
; Sample list to be stored into dictionaries (r) -
'
(
; (car) - SS's name ; (cdr) - List of handles
(
"SS1"
"26C"
"26B"
"26A"
"269"
...
)
(
"SS2"
"270"
"26F"
"26E"
"26D"
...
)
(
"SS3"
"274"
"273"
"272"
"271"
...
)
(
"SS4"
"278"
"277"
"276"
"275"
...
)
(
"SS5"
"27C"
"27B"
"27A"
"279"
...
)
)
Normally I use these subs from my library -
Code - Auto/Visual Lisp:
[Select]
; (IncludeDataIntoMainDic "MyXrec" nil)
; (IncludeDataIntoMainDic "MyXrec" '("Custom" 2 "data"))
; xRecName - xrecord name
; dataL - basically any type of data (usually its a list) if nil, then the xrecord will be deleted.
; http://www.theswamp.org/index.php?topic=5003.0
(
defun
IncludeDataIntoMainDic
(
xRecName dataL
/
maindic xrec
)
(
cond
(
(
not
(
eq
'STR
(
type
xRecName
)
)
)
(
prompt
"
\n
xRecName is not STR type."
)
)
(
(
vl-some
(
function
(
lambda
(
x
)
(
wcmatch
(
strcase
xRecName
)
x
)
)
)
'
(
"ACAD*"
"AEC*"
"Ac*"
)
)
; Being paranoid
(
prompt
"
\n
Invalid xRecord name."
)
)
(
t
(
setq
maindic
(
namedobjdict
)
)
(
if
(
setq
xrec
(
dictsearch
maindic xRecName
)
)
(
entdel
(
cdr
(
assoc
-
1
xrec
)
)
)
)
(
if
dataL
(
dictadd
maindic xRecName
(
entmakex
(
append
'
(
(
0
.
"XRECORD"
)
(
100
.
"AcDbXrecord"
)
)
(
list
(
cons
1
(
vl-prin1-to-string
dataL
)
)
)
)
)
)
)
)
; t
)
; cond
)
; defun IncludeDataIntoMainDic
; (GetDataFromMainDic "MyXrec")
; http://www.theswamp.org/index.php?topic=5003.0
(
defun
GetDataFromMainDic
(
xRecName
/
tmp r
)
(
and
(
setq
tmp
(
dictsearch
(
namedobjdict
)
xRecName
)
)
(
setq
tmp
(
cdr
(
assoc
1
tmp
)
)
)
(
setq
r
(
read
tmp
)
)
)
; and
r
)
; 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).
Logged
(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)
)
)
vevo.bg
VovKa
Water Moccasin
Posts: 1632
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
Logged
Grrr1337
Swamp Rat
Posts: 812
WWW
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]
;| http://www.theswamp.org/index.php?topic=55350.0
(setq r
(
(lambda ( / _Point L r )
(defun _Point ()(cdr (assoc 5 (entget (entmakex '((0 . "POINT")(10 0.0 0.0 0.0)))))))
(foreach x '("SS1" "SS2" "SS3" "SS4" "SS5")
(repeat 15000
(setq L (cons (_Point) L))
)
(setq r (cons (cons x L) r))
(setq L nil)
)
(reverse r)
)
)
)
; Sample list to be stored into dictionaries (r) -
'( ; (car) - SS's name ; (cdr) - List of handles
("SS1" "26C" "26B" "26A" "269" ...)
("SS2" "270" "26F" "26E" "26D" ...)
("SS3" "274" "273" "272" "271" ...)
("SS4" "278" "277" "276" "275" ...)
("SS5" "27C" "27B" "27A" "279" ...)
)
(setq Dic "MyDictionary")
(_IncludeDataIntoMainDic Dic r)
(_GetDataFromMainDic Dic)
_$ (mapcar 'length (_GetDataFromMainDic "MyDictionary"))
(15001 15001 15001 15001 15001)
_$ (mapcar 'length r)
(15001 15001 15001 15001 15001)
_$ (equal r (_GetDataFromMainDic "MyDictionary") 1e-1)
(_IncludeDataIntoMainDic Dic nil)
|;
; (_IncludeDataIntoMainDic "MyDictionary" r)
(
defun
_IncludeDataIntoMainDic
(
DicName dataL
/
maindic subdict dic
)
(
cond
(
(
not
(
eq
'STR
(
type
DicName
)
)
)
(
prompt
"
\n
DicName is not STR type."
)
)
(
(
vl-some
(
function
(
lambda
(
x
)
(
wcmatch
(
strcase
DicName
)
x
)
)
)
'
(
"ACAD*"
"AEC*"
"Ac*"
)
)
; Being paranoid
(
prompt
"
\n
Invalid Dictionary name."
)
)
(
t
(
setq
maindic
(
namedobjdict
)
)
(
if
(
setq
dic
(
dictsearch
maindic DicName
)
)
(
entdel
(
cdr
(
assoc
-
1
dic
)
)
)
)
(
if
dataL
(
progn
(
setq
subdict
(
entmakex
'
(
(
0
.
"DICTIONARY"
)
(
100
.
"AcDbDictionary"
)
)
)
)
(
setq
subdict
(
dictadd
maindic DicName subdict
)
)
(
mapcar
(
function
(
lambda
(
x
)
(
dictadd
subdict
(
car
x
)
(
entmakex
(
append
'
(
(
0
.
"XRECORD"
)
(
100
.
"AcDbXrecord"
)
)
(
mapcar
(
function
(
lambda
(
xx
)
(
cons
1
xx
)
)
)
(
cdr
x
)
)
)
)
)
)
; lambda
)
dataL
)
)
)
; if dataL
)
; t
)
; cond
)
; defun _IncludeDataIntoMainDic
; (_GetDataFromMainDic "MyDictionary")
(
defun
_GetDataFromMainDic
(
DicName
/
tmp e r
)
(
and
(
setq
tmp
(
dictsearch
(
namedobjdict
)
DicName
)
)
(
setq
e
(
cdr
(
assoc
-
1
tmp
)
)
)
(
setq
tmp
(
apply
(
function
append
)
(
mapcar
(
function
(
lambda
(
x
)
(
if
(
=
3
(
car
x
)
)
(
list
(
cdr
x
)
)
)
)
)
tmp
)
)
)
(
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
)
)
)
; and
r
)
; defun _GetDataFromMainDic
«
Last Edit: August 01, 2019, 07:26:34 AM by Grrr1337
»
Logged
(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)
)
)
vevo.bg
Print
Pages: [
1
] |
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
How do I store this big list into a dictionary?