Jump to content
MastroLube

xrecord in dictionary management

Recommended Posts

MastroLube

Hello guys, I'm about to update my code in order to make it more efficient.
A long time ago I wrote this function to save my custom values in an XRECORD inside a dictionary.

 

Is it possible to have the number of parameters (300-301-302- and so on) depending on the length of the list?

 

(DEFUN CP:salva_dati (name nomedizionario lst / dict_name anXrec)
  (SETQ dict_name (CP:get-or-create-Dict "C_plan"))
         ;(CDR (ASSOC -1 (DICTSEARCH (NAMEDOBJDICT) nomedizionario))))
  (SETQ
    anXrec (ENTMAKEX
             (LIST '(0 . "XRECORD") '(100 . "AcDbXrecord")
                   (CONS 300 (nth 0 lst)) ;percorso
                   (CONS 301 (nth 1 lst)) ;unità
                   (CONS 302 (nth 2 lst)) ;scala
                   (CONS 303 (nth 3 lst)) ;scala colore
                   (cons 304 (nth 4 lst)) ;moltiplicatore
                   (cons 305 (nth 5 lst)) ;ang_rot
                   )
           )
  )
  (DICTADD dict_name name anXrec)
)


(defun CP:get-or-create-Dict ( nome / adict)
  (if (not (setq adict (dictsearch (namedobjdict) nome)))
    (progn
 
      (setq adict (entmakex '((0 . "DICTIONARY")(100 . "AcDbDictionary"))))
 
      (if adict (setq adict (dictadd (namedobjdict) nome adict)))
    )
 
    (setq adict (cdr (assoc -1 adict)))
 
  )
 
)

In this case, I can save 6 values. I want to use this function to save even only one value or 10 values without creating other dedicated functions. Is it possible?

 

Any suggestion to accomplish that?

 

Another question:

to edit these xrecord I usually get values that don't modify and createa list of them plus values that I want to change.

(setq lst (list (CP:leggi_dati "Costanti" "C_plan" 300)
					"M"
					"1"
					"1000"
					"0.01"
					(CP:leggi_dati "Costanti" "C_plan" 305)
					)
					)
  (dictremove (cdr (assoc -1 (dictsearch (namedobjdict) "C_plan"))) "Costanti")
  (CP:salva_dati "Costanti" "C_plan" lst)


(DEFUN CP:leggi_dati (name nomedizionario valore / dict_name)
  (SETQ dict_name (CDR (ASSOC -1 (DICTSEARCH (NAMEDOBJDICT) nomedizionario))))
  (CDR (ASSOC valore (DICTSEARCH dict_name name)))
  )

There is a better method? (modify only the element I want without collect the others)

 

Thanks for your help!

Dennis

 

 

Share this post


Link to post
Share on other sites
BIGAL
Posted (edited)

It should work but you should be able to do a repeat for the 300's section

(setq x 301 y 0)
(list '(0 . "Xrecord ...............
(repeat howmany
(cons x (nth y lst))
(setq x (+ x 1))
(setq y (+ y 1))
)

)

Edited by BIGAL

Share this post


Link to post
Share on other sites
Roy_043
Posted (edited)

First of all I think it is strange to store numbers as strings.

Second: you can use group codes 300-309 for strings. But not 310-319.

Third: consider formatting your data. Example:

(... (1 . "MyString") (2 . "ABC") (1 . "MyReal") (40 . 1.23) (1 . "MyOtherReal") (40 . 4.56) (1 . "MyInt") (90 . 1))

 

Edited by Roy_043

Share this post


Link to post
Share on other sites
MastroLube

Sorry for reply only now, I've been busy with work and had to stop to develop my lisps :(

Thank you both for the answers!!

 

On 4/27/2019 at 10:04 AM, Roy_043 said:

First of all I think it is strange to store numbers as strings.

Second: you can use group codes 300-309 for strings. But not 310-319.

Third: consider formatting your data. Example:


(... (1 . "MyString") (2 . "ABC") (1 . "MyReal") (40 . 1.23) (1 . "MyOtherReal") (40 . 4.56) (1 . "MyInt") (90 . 1))

 

1

 

Can you please tell me how I can accomplish that? I mean formatting my data in a clever way. I think my code will improve so much if I understand how to do that instead of doing all in a raw way :)

 

Just a little example using my code (or a part of it) so I can start learning something..

 

Thank you very very much!

Dennis

 

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...