Jump to content

Recommended Posts

Posted

Dear all,

 

how to reset all variable e.g. aa44451 aa44452 44453, can I use the (setq 4445? 0 ) to reset all variable to 0 ?

 

Thanks !

Posted

This can be solved using the READ statement that allows to build run-time variables, see example below:

 

(foreach MyIndex '(1 2 3)
(set (read (strcat "aa4445" (itoa MyIndex))) 0)
)

 

Will need to adapt the cycling to your particular case.

 

Regards,

Posted
This can be solved using the READ statement that allows to build run-time variables, see example below:

 

(foreach MyIndex '(1 2 3)
(set (read (strcat "aa4445" (itoa MyIndex))) 0)
)

 

Will need to adapt the cycling to your particular case.

 

Regards,

 

 

thanks !

I want to use the following function to check any button selected by user and then pass the selected items to another lisp function to check, but I don't know how to make a lisp to check it.

 

I'm not sure I need to use array to store the selected items ? And use a loop to check all selected items ? Because after I selected 3 items, all items store in variable mystr "aa44451 aa44452 aa44453". I don't know how to wirte a loop to check all of them.

 

(defun chkToggle_dsc( / tog1 tog2 tog3)

(setq dsc_tog1(atoi(get_tile "dsc_tog1")))

(setq dsc_tog2(atoi(get_tile "dsc_tog2")))

(setq dsc_tog3(atoi(get_tile "dsc_tog3")))

 

(setq myStr "")

(if(= dsc_tog1 1)(setq myStr(strcat myStr " aa44451")))

(if(= dsc_tog2 1)(setq myStr(strcat myStr " aa44452")))

(if(= dsc_tog3 1)(setq myStr(strcat myStr " aa44453")))

 

(if(= myStr "")(setq myStr "Nothing Selected!"))

;;;--- Now set the text control to display the string

(set_tile "text3" myStr)

Posted

Perhaps:

 

(defun chkToggle_dsc  (/ lst2str lst)

 (defun lst2str (lst del)
   (if (cdr lst)
     (strcat (car lst) del (lst2str (cdr lst) del))
     (car lst)))

 (mapcar
   (function
     (lambda (tile string)
       (if (eq "1" (get_tile tile))
         (setq lst (cons string lst)))))

   '("dsc_tog1" "dsc_tog2" "dsc_tog3")
   '("aa44451"  "aa44452"  "aa44453"))

 (or lst (setq lst '("Nothing Selected!")))

 (set_tile "text3" (lst2str lst (chr 32)))

lst)

Posted
Perhaps:

 

(defun chkToggle_dsc  (/ lst2str lst)

 (defun lst2str (lst del)
   (if (cdr lst)
     (strcat (car lst) del (lst2str (cdr lst) del))
     (car lst)))

 (mapcar
   (function
     (lambda (tile string)
       (if (eq "1" (get_tile tile))
         (setq lst (cons string lst)))))

   '("dsc_tog1" "dsc_tog2" "dsc_tog3")
   '("aa44451"  "aa44452"  "aa44453"))

 (or lst (setq lst '("Nothing Selected!")))

 (set_tile "text3" (lst2str lst (chr 32)))

lst)

 

 

Thanks ! Lee Mac.

If I want to get each selected items and use the loop to check it, aims to use the function to check each item have this layer on the drawing or not, can help teach me how to do that. Because now all selected items stored in one variable "mystr" => " aa44451 aa44452 aa44453"

 

Thanks !

Posted
Thanks ! Lee Mac.

If I want to get each selected items and use the loop to check it, aims to use the function to check each item have this layer on the drawing or not, can help teach me how to do that. Because now all selected items stored in one variable "mystr" => " aa44451 aa44452 aa44453"

 

Thanks !

 

 

In my code, the selected items are stored in a list (lst variable), you could iterate through this list and check each item in turn, or do it in many other ways. :)

Posted
This can be solved using the READ statement that allows to build run-time variables, see example below:

 

(foreach MyIndex '(1 2 3)
(set (read (strcat "aa4445" (itoa MyIndex))) 0)
)

 

Will need to adapt the cycling to your particular case.

 

Regards,

 

Just a slighty different way of resetting the variables.

 

 

(vl-load-com)

(defun GetVariables (<StringFilter> / SearchFilter)

 (setq SearchFilter (strcase <StringFilter>))

 (vl-remove-if-not
 (function
   (lambda (<atom>)
    (wcmatch <atom>  SearchFilter)
    )
   )
 (atoms-family 1 )
 )
 )


(foreach n (GetVariables "AA444*" )
 (set (read n) 0)
 )


Posted
In my code, the selected items are stored in a list (lst variable), you could iterate through this list and check each item in turn, or do it in many other ways. :)

 

Thank you very much Lee Mac! Actually my program calling from dailog box, after running the function you teach me, it can't return the selected items.

 

 

(defun S3()

(setq myStr "")

 

;;;--- Load the dcl file

(setq dcl_id (load_dialog "dd.dcl"))

 

;;;--- Load the dialog definition if it is not already loaded

(if (not (new_dialog "dd" dcl_id) ) (exit))

 

;;;--- If an action event occurs, do this function

(action_tile "dsc_tog1" "(chkToggle_dsc)")

(action_tile "dsc_tog2" "(chkToggle_dsc)")

(action_tile "dsc_tog3" "(chkToggle_dsc)")

(action_tile "accept" "(setq ddiag 2)(done_dialog)")

(action_tile "cancel" "(setq ddiag 1)(done_dialog)")

;;;--- Display the dialog box

(start_dialog)

;;;--- Unload the dialog box

(unload_dialog dcl_id_dsc)

 

;;;--- If the user pressed the Cancel button

(if(= ddiag 1)

(princ "\n cancelled!")

)

;;;--- If the user pressed the Okay button, check selected layer

(if (= ddiag 2)

(progn

(if (= dsc_tog1 1)

(progn ...........

 

 

 

(defun chkToggle_dsc (/ lst2str lst)

 

(defun lst2str (lst del)

(if (cdr lst)

(strcat (car lst) del (lst2str (cdr lst) del))

(car lst)))

(mapcar

(function

(lambda (tile string)

(if (eq "1" (get_tile tile))

(setq lst (cons string lst))))) '("dsc_tog1" "dsc_tog2" "dsc_tog3") '("AA2221" "AA2222" "AA2223"))

 

(or lst (setq lst '("Nothing Selected!")))

 

(set_tile "text3" (lst2str lst (chr 32))) lst)

Posted
Use:

 

(setq lst (chkToggle_dsc))

 

 

Thanks for your help ! But I don't understand the above code, can you explain ? forgive me poor in the autolisp.

Posted
What do you think the function 'chktoggle_dsc' will return?

 

 

it will return selected items ?

Posted
it will return selected items ?

 

It will return the value bound to the variable "lst" which contains a list of strings.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...