Author Topic: vlax-ldata-put question  (Read 3228 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
vlax-ldata-put question
« on: December 07, 2007, 02:07:32 PM »
anyone had this experience ?

Code: [Select]
(vlax-ldata-put "dict" "Nat" "TEST1")
(vlax-ldata-put "dict" "Bat" "TEST2")
(vlax-ldata-put "dict" "Fat" "TEST3")

result :

Code: [Select]
(vlax-ldata-list "dict")

_$

(("N" . "TEST2") ("F" . "TEST3") ("B" . "TEST1"))
_$

it take always the first caracter of the dictionnary name..
do i miss something ?
Keep smile...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: vlax-ldata-put question
« Reply #1 on: December 07, 2007, 02:15:51 PM »
Works in 2K0
Code: [Select]
Command: (vlax-ldata-put "dict" "Nat" "TEST1")
"TEST1"

Command: (vlax-ldata-put "dict" "Bat" "TEST2")
"TEST2"

Command: (vlax-ldata-put "dict" "Fat" "TEST3")
"TEST3"

Command: (vlax-ldata-list "dict")
(("Nat" . "TEST1") ("Fat" . "TEST3") ("Bat" . "TEST2"))

Did you try All Caps?
Code: [Select]
Command: (vlax-ldata-put "dict" "NAT" "TEST1")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: vlax-ldata-put question
« Reply #2 on: December 07, 2007, 02:40:28 PM »


Code: [Select]
(vlax-ldata-put "dict" "NAT" "TEST2")
(vlax-ldata-list "dict")


_$

(("N" . "TEST2"))
_$

?

 :oops:
Keep smile...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: vlax-ldata-put question
« Reply #3 on: December 07, 2007, 02:51:52 PM »
Maybe this is one reason why so many people don't like to use ldata.  I have never used it, so I don't have first hand knowledge, but I have read other threads about ldata and xdata.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2084
Re: vlax-ldata-put question
« Reply #4 on: December 07, 2007, 04:27:10 PM »
Maybe this is one reason why so many people don't like to use ldata.  I have never used it, so I don't have first hand knowledge, but I have read other threads about ldata and xdata.

Peter Jamtgaard from the waun.org site is an expect on ldata usage.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vlax-ldata-put question
« Reply #5 on: December 07, 2007, 04:34:25 PM »
Maybe this is one reason why so many people don't like to use ldata.  I have never used it, so I don't have first hand knowledge, but I have read other threads about ldata and xdata.

http://www.theswamp.org/index.php?topic=18054.msg218567#msg218567
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: vlax-ldata-put question
« Reply #6 on: December 07, 2007, 04:34:42 PM »
Andrea, I suppose you're using acad2007.

It's a bug with this version (see this thread CADxp)
Speaking English as a French Frog

Andrea

  • Water Moccasin
  • Posts: 2372
Re: vlax-ldata-put question
« Reply #7 on: December 08, 2007, 08:27:33 AM »
Well,....its true..
the bug exist in 2007.  that what i'm using.


but in fact it work...

Code: [Select]
(vlax-ldata-put "dict" "Dominic" "Hello DomDom")
(vlax-ldata-put "dict" "Denis" "Hi Denis")


(vlax-ldata-list "dict")

result:
_$

(("D" . "Hello DomDom") ("D" . "Hi Denis") )
_$




(vlax-ldata-get "dict" "Dominic")
(vlax-ldata-get "dict" "Denis")

result:
_$

"Hello DomDom"
"Hi Denis"
_$

thanks all
Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: vlax-ldata-put question
« Reply #8 on: December 08, 2007, 12:37:15 PM »
Andrea -- please run, run away from ldata. As noted abundantly on discussion forums here, there, everywhere -- use other data storage methods, like dictionaries, xdictionaies, xrecords etc. Historically ldata has brought programmers nothing but grief. Do you expect a different outcome?
« Last Edit: December 08, 2007, 12:48:49 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: vlax-ldata-put question
« Reply #9 on: December 08, 2007, 03:50:24 PM »
Hi Michael,

I didn't know that before reading this post (and the other one you gave a link).
I often used the vlax-ldata-* functions because there're easy to use to store datas in the drawing.
So, if I want to change my way I have to write some routine so that I can replace the vlax-ldata* callings in my programs by dict-data* (for example).

I tried to do something which can be used the same way, am I right or have I reproduce the same thing as ldatas ?

Code: [Select]
;; DICT-DATA-PUT
;;
;; Stores a data in a dictionary
;;
;; Arguments:
;; dict = dictionary name (string)
;; key = dictionary key (string)
;; data = data value (string, integer real, list or ename)
;;
;; Return: data value or nil
;;
;; Examples :
;; (dict-data-put "mon_dico" "txt" "test") -> "test"
;; (dict-data-put "mon_dico" "lst" '(1 2 3)) -> (1 2 3)
;; (dict-data-put "mon_dico" "num" 1) -> 1

(defun dict-data-put (dict key data)
  (if
    (and
      (snvalid dict)
      (snvalid key)
      (member (type data) '(ENAME LIST INT REAL STR))
      (if (dictsearch (namedobjdict) dict)
(setq dict (cdr (assoc -1 (dictsearch (namedobjdict) dict))))
(setq dict (dictadd
     (namedobjdict)
     dict
     (entmakex '((0 . "DICTIONARY") (100 . "AcDbDictionary")))
   )
)
      )
      (if (dictsearch dict key)
(entdel (cdr (assoc -1 (dictsearch dict key))))
T
      )
      (dictadd
dict
key
(entmakex
  (list '(0 . "XRECORD")
'(100 . "AcDbXrecord")
(cond
  ((and (= (type data) 'LIST)
(< 1 (length data) 4)
(vl-every 'numberp data)
   )
   (cons 10 data)
  )
  ((= (type data) 'REAL) (cons 40 data))
  ((= (type data) 'ENAME) (cons 350 data))
  (T (cons 300 (vl-prin1-to-string data)))
)
  )
)
      )
    )
     data
  )
)


;; DICT-DATA-LIST
;;
;; Lists the datas of a dictionary
;;
;; Argument:
;; dict = dictionary name (string)
;;
;; Return: a list of dotted pair (key . value)
;;
;; Example :
;; (dict-data-list "mon_dico") -> (("lst" 1 2 3) ("num" . 1) ("txt" . "test"))

(defun dict-data-list (dict / elst key val lst)
  (if (and (setq dict (dictsearch (namedobjdict) dict))
   (setq elst (member (assoc 3 dict) dict))
      )
    (progn
      (while elst
(setq key  (cdar elst)
      val  (last (dictsearch (cdr (assoc -1 dict)) key))
      lst  (cons
     (cons key
   (if (= 300 (car val))
     (read (cdr val))
     (cdr val)
   )
     )
     lst
   )
      elst (cddr elst)
)
      )
      (reverse lst)
    )
  )
)


;; DICT-DATA-DELETE
;;
;; deletes dat from a dictionary
;;
;; Arguments
;; dict = dictionary name (string)
;; key = dictionary key (string)
;;
;; Return: T or nil
;;
;; Example :
;; (dict-data-delete "mon_dico" "lst") -> T

(defun dict-data-delete (dict key)
  (and (setq dict (dictsearch (namedobjdict) dict))
       (setq key (dictsearch (cdr (assoc -1 dict)) key))
       (entdel (cdr (assoc -1 key)))
  )
)


;; DICT-DATA-GET
;;
;; Retrieves data from a dictionary
;;
;; Arguments
;; dict = dictionary name (string)
;; key = dictionary key (string)
;;
;; Return: data value or nil
;;
;; Examples :
;; (dict-data-get "mon_dico" "txt") -> "test"
;; (dict-data-get "mon_dico" "num") -> 1
;; (dict-data-get "mon_dico" "lst") -> nil

(defun dict-data-get (dict key)
  (if (and (setq dict (dictsearch (namedobjdict) dict))
   (setq key (dictsearch (cdr (assoc -1 dict)) key))
      )
    (if (= 300 (car (last key)))
      (read (cdr (last key)))
      (cdr (last key))
    )
  )
)
« Last Edit: December 08, 2007, 03:56:40 PM by gile »
Speaking English as a French Frog