Author Topic: How do I set a variable to "Nothing"  (Read 11146 times)

0 Members and 1 Guest are viewing this topic.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
How do I set a variable to "Nothing"
« on: April 15, 2006, 09:54:48 AM »
How do I set a variable to nothing?  Not nil, not zero, not false.

I am setting up condition statements for multiple DCL toggles.  If action toggle = 1 ~ then set the variable to a value; if = 0 then set variable to nothing.  Then I will strcat all the variables together and hopefully only have a string showing only the toggle(s) that were checked.

Or will I have to use “nil” or like something mention above?  And use the vl-string-subst function? 
This I am foreseeing as a problem because I want to substitute it with nothing.  I don’t want to replace it with a space or a character.  My goal is to keep the final string as short as possible.


Or am I total mad and going about this wrong way.  I tried to do search and was getting too many hits with all the /promt “nothing selected” code.

Thanks
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #1 on: April 15, 2006, 10:02:44 AM »
I am setting up condition statements for multiple DCL toggles.  If action toggle = 1 ~ then set the variable to a value; if = 0 then set variable to nothing.  Then I will strcat all the variables together and hopefully only have a string showing only the toggle(s) that were checked.

Sorry, should have clarified my intents one step further.

I have a condition statement for each toggle that evaluates that particular toggle.

Thanks again
Ted
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I set a variable to "Nothing"
« Reply #2 on: April 15, 2006, 10:35:14 AM »
I would need some code to figure out what you are trying to do.
But here is how I approach the dcl toggle.

I always set the lisp variable to some default.


Method one:
Use a string to hold the state of the lisp variable.
"0" = not checked
"1" = checked

Code: [Select]
;;  this is somewhere in the startup
(setq MyLispVar-ToggleOne "1") ; set default value

Code: [Select]
;;  This is in my DCL setup
(action_tile "MyToggleOne" "(setq MyLispVar-ToggleOne $value))")
(set_tile "MyToggleOne" MyLispVar-ToggleOne) ; set the default state

There is no need to get the DCL toggle state on exit from the Dialog because it is
set prior to entry & will update the Lisp variable if the user changed it.

Method two:
Use true nil to hold the state of the lisp variable.
nil = not checked
t   = checked

Code: [Select]
;;  this is somewher in the startup
(setq MyLispVar-ToggleOne t) ; set default value

Code: [Select]
;;  This is in my DCL setup
(action_tile "MyToggleOne" "(setq MyLispVar-ToggleOne (= $value \"1\"))")
(set_tile "MyToggleOne" (if MyLispVar-ToggleOne "1" "0")) ; set the default state

There is no need to get the DCL toggle state on exit from the Dialog because it is
set prior to entry & will update the Lisp variable if the user changed it.
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.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #3 on: April 15, 2006, 10:49:58 AM »
Here is the code that I have so far.  I believe that I am using Method 1 as you described. 
The portion that I need help in is at [;;Evaluating Toggles selected~~]

Code: [Select]
  ;; ;;PreSets Dialog Box Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(setq which_action 1)

(if (not toggle1) ;if no default
  (setq toggle1 "0") ;set default value
) ;if

(if (not toggle2) ;if no default
  (setq toggle2 "0") ;set default value
) ;if

 

  ;; ;;Starts Dialog Box Session~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(setq dcl_id (load_dialog "samp4.dcl")) ;load dialog

(if (not (new_dialog "samp4" dcl_id) ;test for dialog

    ) ;not

  (exit) ;exit if no dialog

) ;if

  ;;;Radio Button Row~~~~~~~~~~~~~~~~~~~~~~
(setq which_action 1)
  (action_tile "rb1" "(setq which_action 1)")
;New version 2004 file with date Prefix
  (action_tile "rb2" "(setq which_action 2)")
;New version 2000 file with date Prefix
  (action_tile
    "cancel" ;if cancel button pressed
    "(done_dialog) (setq userclick nil)" ;close dialog, set flag
  );action_tile

;;;Toggle Alley~~~~~~~~~~~~~~~~~~~~~~
    (set_tile "tog1" toggle1)
  ;set toggle

  (set_tile "tog2" toggle2)
  ;set toggle

   (action_tile "tog1"
   ;if toggle 1 selected

      "(setq toggle1 $value)"
       ;get the value

   );action_tile

   (action_tile "tog2"
   ;if toggle 2 selected

      "(setq toggle2 $value)"
       ;get the value

   );action_tile

  ;;;Evaluating Toggles selected~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  (setq name1 " ")
(cond ;start of Cond
  ((= toggle1 "1") (setq name1 "BSE"))

  ((= toggle1 "0") (setq name1 "")) ;;  this is where I am trying to get the "Nothing"

) ;End of Cond
  ;;Strings all the selected together ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(setq ConNames (strcat name1))


  (action_tile
    "accept" ;if O.K. pressed
    " (done_dialog)(setq userclick T))" ;close dialog, set flag
  ) ;action tile

  (start_dialog) ;start dialog

  (unload_dialog dcl_id) ;unload

  (princ)

I have to go and be the gracious host to my in-laws.  :-D
Looking forward to your response on Monday. 
Thanks,
Ted
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I set a variable to "Nothing"
« Reply #4 on: April 15, 2006, 11:52:36 AM »
This is how I would aproach the code.
Although I still don't have an understanding of what you want refering to "nothing"

Code: [Select]
;;PreSets Dialog Box Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; set default values
(setq which_action 1)
(or toggle1 (setq toggle1 "0"))
(or toggle2 (setq toggle2 "0"))

;; ;;Starts Dialog Box Session~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(setq dcl_id (load_dialog "samp4.dcl")) ;load dialog

;; test for dialog
(if (not (new_dialog "samp4" dcl_id))
  (exit)
)

;;;Radio Button Row~~~~~~~~~~~~~~~~~~~~~~
(setq which_action 1)
(action_tile "rb1" "(setq which_action 1)") ;New version 2004 file with date Prefix
(action_tile "rb2" "(setq which_action 2)") ;New version 2000 file with date Prefix

;;;Toggle Alley~~~~~~~~~~~~~~~~~~~~~~
(set_tile "tog1" toggle1)
(set_tile "tog2" toggle2)

(action_tile "tog1" "(setq toggle1 $value)")
(action_tile "tog2" "(setq toggle2 $value)")



(setq userclick (= (start_dialog) 1))
(unload_dialog dcl_id) ;unload

;;;Evaluating Toggles selected~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(if userclick
  (setq connames
         (list
           (if (= toggle1 "1") "BSE" "")
           (if (= toggle2 "1") "BSE" "")
         )
  )
)

;;  at this point connames is nil if the user canceled
;;  or it contains a list of BSE or "" as per the toggles

(princ)


If you are using ok_cancel; or similar for exit buttons the (done_dialog) passes a 0 or 1
to the (start_dialog) and that is returned. So you can test the exit condition.

From the help file:
Quote
The start_dialog function returns the optional status passed to done_dialog. The
default value is 1 if the user presses OK, 0 if the user presses Cancel, or -1
if all dialog boxes are terminated with term_dialog. If done_dialog is passed an
integer status greater than 1, start_dialog returns this value, whose meaning is
determined by the application.
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.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #5 on: April 15, 2006, 01:45:18 PM »
Okay I managed to get a few minutes while the wife and mother-in-law go shopping.  This problem is nagging at me in back of my head so I jump on the wife's computer and dial-up (It hurts us, it hurts us) :-).  So therefore I have No Acad and no lisp to try things.

Okay so here goes on further explaining "Nothing" 
Let say I have 5 toggles and they all stand for consultants names.  My condition statement assigns initials for the consultants names for each of the toggles.  Lets say the user checks 3 out of the 5.  For the 2 that were not selected i am getting nil or zero.  (the variable watch told me so)  right what is happening I strcat the all the "name1 thru name5 variables i getting the 0 and/or nil in the return of the variable ConNames

for example
(setq ConNames (strcat name1 name2 name3 name4 name5))

and if tog1, tog2 & tog4 was selected

I am getting a return for the variable conNames = name1nam200name40.
I don't want zeros.  I want to remove them and squeeze the string together so the desired return for ConName variable would be = name1name2name4

I hope this helps.  See you Monday.
Thanks for your help.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I set a variable to "Nothing"
« Reply #6 on: April 15, 2006, 06:07:49 PM »
OK, use this:
Code: [Select]
(if userclick
  (vl-remove nil
             (setq connames
                    (list
                      (if (= toggle1 "1") "name1")
                      (if (= toggle2 "1") "name2")
                      (if (= toggle3 "1") "name3")
                      (if (= toggle4 "1") "name4")
                    )
             )
  )
)

Gives you this:
Code: [Select]
("name1" "name2" "name4")
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.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #7 on: April 17, 2006, 06:46:22 AM »
Okay I see what you are doing and but I have questions on some parts of how you are doing it.  I spent this morning looking at Autodesk's help sectionwith very little success in explaining how you are doing it.  They always leave me hanging on some issues.

I arrived this morning to email from an industrious Sunday working architect giving me marching orders and to have those orders completed for a 10am meeting.  So I will be back questions.

Again thanks for you help.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: How do I set a variable to "Nothing"
« Reply #8 on: April 17, 2006, 09:27:39 AM »
nothing, just testing ..........
TheSwamp.org  (serving the CAD community since 2003)

whdjr

  • Guest
Re: How do I set a variable to "Nothing"
« Reply #9 on: April 17, 2006, 11:32:02 AM »
What about mode_tile?

You could use that to enable it or disable it.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How do I set a variable to "Nothing"
« Reply #10 on: April 17, 2006, 12:10:53 PM »
Okay I managed to get a few minutes while the wife and mother-in-law go shopping.  This problem is nagging at me in back of my head so I jump on the wife's computer and dial-up (It hurts us, it hurts us) :-).  So therefore I have No Acad and no lisp to try things.

Okay so here goes on further explaining "Nothing" 
Let say I have 5 toggles and they all stand for consultants names.  My condition statement assigns initials for the consultants names for each of the toggles.  Lets say the user checks 3 out of the 5.  For the 2 that were not selected i am getting nil or zero.  (the variable watch told me so)  right what is happening I strcat the all the "name1 thru name5 variables i getting the 0 and/or nil in the return of the variable ConNames

for example
(setq ConNames (strcat name1 name2 name3 name4 name5))

and if tog1, tog2 & tog4 was selected

I am getting a return for the variable conNames = name1nam200name40.
I don't want zeros.  I want to remove them and squeeze the string together so the desired return for ConName variable would be = name1name2name4

I hope this helps.  See you Monday.
Thanks for your help.

Not sure I understand, but for fun, and to think outside the box consider --

Replicate test environs --

Code: [Select]
(setq
    toggle1  t
    toggle2  t
    toggle3  nil
    toggle4  t
)

And then --

Code: [Select]
(apply 'strcat
    (mapcar
       '(lambda ( index / suffix )
            (if
                (vl-symbol-value
                    (read
                        (strcat "toggle"
                            (setq suffix (itoa index))
                        )
                    )
                )
                (strcat "Name" suffix)
                ""
            )   
        )
       '(1 2 3 4)
    )
)

Result --

Code: [Select]
"Name1Name2Name4"
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do I set a variable to "Nothing"
« Reply #11 on: April 17, 2006, 12:20:14 PM »
If i understand correctly, Krushert wants to gather up the results of the user picked toggles
and combine them into a string created based on the states of the toggles. He was having a problem
ignoring the unchecked toggles.
My example returned a list of strings for the checked toggles only and if he wants to combine them
he could use this.

(setq str (apply 'strcat connames))

but I think the list may serve him better.


MP beat me to the enter key again. :-)
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How do I set a variable to "Nothing"
« Reply #12 on: April 17, 2006, 12:26:39 PM »
Perhaps this will illuminate better --

Code: [Select]
(setq
    toggle1  t
    toggle2  nil
    toggle3  t
)

Code: [Select]
(setq
    toggles '(toggle1 toggle2 toggle3)
    names   '("Fred" "Barney" "Wilma")
)

Code: [Select]
(apply 'strcat
    (mapcar
       '(lambda (toggle name) (if (vl-symbol-value toggle) name ""))
        toggles
        names
    )
)

Code: [Select]
"FredWilma"
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #13 on: April 17, 2006, 12:47:59 PM »
Yes Cab you understood me correctly.  Of course my day is screwed up so can not list all my questions at once.  Sorry about that.  Below is my first question.  I only have a few.  :-)  Please keep in mind that I question to learn the "hows & whys" not imply "Why aren't you doing this way?"  I almost had a shovel on the head because I made that implication a long time ago.   :-D


How does the your "or" replace my " if (not " and why?  I think you are streamling it but not sure.  For that matter I really don't understand how my " if (not " works.
Yours:

Code: [Select]
;;PreSets Dialog Box Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;; set default values
(setq which_action 1)
(or toggle1 (setq toggle1 "0"))
(or toggle2 (setq toggle2 "0"))

Mine:
Code: [Select]
  ;; ;;PreSets Dialog Box Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(setq which_action 1)
(if (not toggle1) ;if no default
  (setq toggle1 "0") ;set default value
) ;if
(if (not toggle2) ;if no default
  (setq toggle2 "0") ;set default value
) ;if
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: How do I set a variable to "Nothing"
« Reply #14 on: April 17, 2006, 01:15:25 PM »
Second how & why question.

You replace my
Code: [Select]
  (action_tile "cancel" "(done_dialog) (setq userclick nil)" )
         ;;if cancel button pressed close dialog, set flag
 
  (action_tile "accept" " (done_dialog)(setq userclick T))")
         ;;if O.K. pressed close dialog, set flag

  (start_dialog) ;start dialog
  (unload_dialog dcl_id) ;unload



with yours
Code: [Select]
(setq userclick (= (start_dialog) 1))
(unload_dialog dcl_id) ;unload

Again I believe that your streamlining the code but not sure exactly how.  I do see the userclick variable being set to 1 instead of T so it can be used later on in "list".  Not sure how the Start Dialog activate it though. 
Where did the "cancel" go??
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans