User Input as a List

User Input as a List

thabit79BL3
Enthusiast Enthusiast
1,712 Views
18 Replies
Message 1 of 19

User Input as a List

thabit79BL3
Enthusiast
Enthusiast

Hi Lisp wizards,

 

I am developing a tool to accept the input from the user, the user's input is a block's attributes, so i've to save the input as variable in a list (to facilitate the process).

 

Unfortunately, I was not able to do it. The problem is that AutoLisp treats these variables as strings, meaning that it does not read the user's input.

 

Thanks in advance to you all.

 

Attached part of the code:

 

(setq i 0 CatLst '())
(repeat (atoi aeb16) (setq CatLst( append CatLst (list (strcat "CAT" (itoa (setq i (1+ i))))))))
(foreach item CatLst (action_tile item "(set (read $key) $value)"))
----------------------
(setq count 0 point '(45 248))
(while (< count (atof aeb16))
  (setq Mcat (nth count CatLst))
  (command "-insert" "autocad_new\\Libs\\VCB1" point "1" "1" "0" Mcat)
  (setq count (1+ count))
  (setq TheXValue (car point))
  (setq point (list (+ '35 TheXValue) (cadr point) ))
)

 

 

0 Likes
Accepted solutions (1)
1,713 Views
18 Replies
Replies (18)
Message 2 of 19

ВeekeeCZ
Consultant
Consultant

IMHO Mcat is an item of CatLst which is a list of strings. So it's a string. If the INSERT does not accept that, you have a problem somewhere else. Possibly ATTREQ sysvar.

 

BTW Why (while (< count (atof aeb16))

 

0 Likes
Message 3 of 19

john.uhden
Mentor
Mentor

@thabit79BL3 

If your block definition of VCB1 contains the same number of attributes as the length of CatLst, and CatLst is in the correct order then try...

(command "-insert" "autocad_new\\Libs\\VCB1" point "1" "1" "0")
(foreach Mcat CatLst (command Mcat)) ;; supply each string as an attribute value
(command "") ;; may or may not be needed

 

John F. Uhden

0 Likes
Message 4 of 19

paullimapa
Mentor
Mentor
post your block autocad_new\\Libs\\VCB1.dwg so we can take a look what it actually contains

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 19

thabit79BL3
Enthusiast
Enthusiast

Maybe I didn't explain it well, (sorry my english is bad😅).

 

For the sake of demonstration, I am attaching 2 pictures here, one describing my input and the other the output. From there you can see that my output is not exactly the same as the input, but all the attributes are strings of the sub-name that I defined to save the user's input.

(In other words, instead of the CAT1 in the output image, it should be replaced with S201)

0 Likes
Message 6 of 19

paullimapa
Mentor
Mentor
Accepted solution

I understand what you mean since you posted a question prior to this which I replied to.

Now you have a list like ("CAT1""CAT2""CAT3"...)

And you also have matching variables set like: (setq CAT1 "S209" CAT2 "S108" CAT3 "305"....)

And you want to get the item from the list which are strings and equate them to the matching symbol variable names.

 

Try swapping this line of code:

(setq Mcat (nth count CatLst))

with this line:

(setq Mcat (eval (read (nth count CatLst))))


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 19

thabit79BL3
Enthusiast
Enthusiast

@paullimapa 

Yeah it's worked perfect! (This time and before 😉)

There was nothing random about your acts of kindness, thhank you for all you have done ❤️

0 Likes
Message 8 of 19

paullimapa
Mentor
Mentor
glad that worked out for you....cheers!!!

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 19

john.uhden
Mentor
Mentor

@paullimapa & @thabit79BL3 

Better than that, make a list of dotted pairs...

(setq CatLst '(("CAT1" . "S209")("CAT2" . "S108")("CAT3" . "305")....))

Then you can retrieve the value you want by

(cdr (assoc Cat CatLst)) ;; where Cat would be any of the strings "CAT1" etc.

 

John F. Uhden

0 Likes
Message 10 of 19

thabit79BL3
Enthusiast
Enthusiast

Regards @john.uhden 

 

Can you please explain why this a better way to do this. 

 

0 Likes
Message 11 of 19

john.uhden
Mentor
Mentor

@thabit79BL3 

1.  It doesn't require a bundle of variables.

2.  You can create the list in any order because it derives the value by associativity.

3.  Actually the items in the list should probably be lists themselves rather than dotted pairs so that you can easily modify any item by subst without having to create a new list.

3.  Blah

4.  Blah

5.  Blah

John F. Uhden

0 Likes
Message 12 of 19

paullimapa
Mentor
Mentor

Now with this post and the previous post I would like to see your method of coding to answer both...would the action tile call back function be similar to @Sea-Haven in constructing an associated pair?

(action_tile "accept" "(mapcar '(lambda (x) (setq v_lst (cons (get_tile x) v_lst))) key_lst)(done_dialog)")

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 13 of 19

john.uhden
Mentor
Mentor

@paullimapa 

Hmm, let me think out loud...

;; First a function to add or modify items in the list of categories, eg.
(setq Cats '(("A" "123")("B" "456")("C" "789")))
(defun ModCats (Cat new / x)
  (if (setq x (assoc Cat Cats))
    (setq Cats (subst (list Cat new) x Cats))
    (setq Cats (cons (list Cat new) Cats))
  )
)
;; Examples:
Command: (setq Cats '(("A" "123")("B" "456")("C" "789")))
(("A" "123") ("B" "456") ("C" "789"))
Command: (modcats "A" "test")
(("A" "test") ("B" "456") ("C" "789"))
Command: (modcats "C" "SNERT")
(("A" "test") ("B" "456") ("C" "SNERT"))
Command: (modcats "D" "_____") ;; add a new Cat
(("D" "_____") ("A" "test") ("B" "456") ("C" "SNERT"))
;; Now to make it work for every action_tile
(foreach key (mapcar 'car Cats)(action_tile key "(modcats key $value)"))
;; Or maybe...
(action_tile "accept"
  "(foreach key (mapcar 'car Cats)(if (setq value (get_tile key))(modcats key value)))(done_dialog 1)"
)
;; Of course there may be a problem if there's no tile for a Cat.

John F. Uhden

Message 14 of 19

paullimapa
Mentor
Mentor

Since OPs original request from the previous thread is to avoid writing each line of code defining each of a total of say 15 variables/keys with exactly the same names with the # appended at the end as well as a simple action tile call back statement setting the value of each of the 15 entered values from the dialog into matching variable names, the simplest one line code I came up with is more than enough to satisify the requirements.  Of course if there was more of a need to manipulate or refer to individual items from the end result list, then an associated pair list as you have suggested would be preferred.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 15 of 19

john.uhden
Mentor
Mentor

Well then, Paulli, GOOD JOB!

John F. Uhden

Message 16 of 19

paullimapa
Mentor
Mentor
Thanks

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 17 of 19

ariannajono1
Community Visitor
Community Visitor

I have a "Contact Us" form that includes several input fields. I am interested in removing or blocking certain input fields from the form. How can I go about doing this?

0 Likes
Message 18 of 19

Sea-Haven
Mentor
Mentor

Do you mean get the attribute values ?

 

Yes various ways of getting certain attribute values like get the 2 4 & 6 attributes in creation order or get att2 att4 & att6 by tagname.

 

post a dwg showing what you want a before and after.

0 Likes
Message 19 of 19

john.uhden
Mentor
Mentor

@Sea-Haven ,

I like to organize them into a list, like...

(setq items (list '("att1" "1")'("att2" "2")'("att3" "") etc.))

That way your search is easy...

(setq item (assoc "att2" items))

(setq val (cadr item))

And they don't have to be in any order, but you could sort them if you wanted.

John F. Uhden

0 Likes