subfunction with popup not returning selected value to main function

subfunction with popup not returning selected value to main function

jsaayman
Advocate Advocate
854 Views
4 Replies
Message 1 of 5

subfunction with popup not returning selected value to main function

jsaayman
Advocate
Advocate

Hi

I'm having some issues with a popup function that I'm using. I have a main function TPop (the current main function is just a test main function) that calls popup2 and popup2 is suppose to return the selected ctb file and print it to the command line. But it seems that test is empty.

 

(defun C:TPop()
  	(setq test (popup2))
  	(princ test)

  )

(defun POPUP2 ()
    (setq rlist (vl-remove-if '(lambda (x)
(or (vl-string-search ".stb" x) (vl-string-search ".lnk" x))
)
(vl-directory-files (getenv "PrinterStyleSheetDir") nil 1))
          dcl_id (load_dialog "popup2.dcl") ; call the dcl file and asign to a var.
    )
    (if (not (new_dialog "popup" dcl_id)) ; if statement if dcl is not found. goodthing to have.
      (exit)
    )
    (start_list "rating")
    (mapcar 'add_list rlist)
    (end_list)
    (if #val
      (set_tile "rating" (itoa (setq val #val))) ; itoa convert int to string
      (set_tile "rating" (itoa (setq val 0)))
    );if
    (action_tile "rating" "(setq val (atoi $value))")
    (action_tile "accept" "(setq #val val)(done_dialog 1)")
    (action_tile "cancel" "(done_dialog 0)")
    (start_dialog)
    (unload_dialog dcl_id)
    (if userclick
      (progn
	(setq val (fix val))
	(setq val (nth val rlist))
	(princ val)
	)
      )
    (princ)
  )
0 Likes
Accepted solutions (1)
855 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

It has to be the last item evaluated of your sub...

 

(defun POPUP2 ()
.............
  val
  )

 

 

 

0 Likes
Message 3 of 5

jsaayman
Advocate
Advocate

@ВeekeeCZ wrote:

It has to be the last item evaluated of your sub...

 

(defun POPUP2 ()
.............
  val
  )

 

 

 


I've tested it by placing val at the bottom of the sub, but it makes no difference

0 Likes
Message 4 of 5

ВeekeeCZ
Consultant
Consultant

I have nothing to add. That's the way it works.

0 Likes
Message 5 of 5

dlanorh
Advisor
Advisor
Accepted solution

Try this:

 

(defun POPUP2 ()
    (setq rlist (vl-remove-if 
                  '(lambda (x) (or (vl-string-search ".stb" x) (vl-string-search ".lnk" x)))
                    (vl-directory-files (getenv "PrinterStyleSheetDir") nil 1)
                )
          dcl_id (load_dialog "popup2.dcl") ; call the dcl file and asign to a var.
    )
    (if (not (new_dialog "popup" dcl_id)) ; if statement if dcl is not found. goodthing to have.
      (exit)
    )
    (start_list "rating")
    (mapcar 'add_list rlist)
    (end_list)
    (if #val
      (set_tile "rating" (itoa (setq val #val))) ; itoa convert int to string
      (set_tile "rating" (itoa (setq val 0)))
    );if
    (action_tile "rating" "(setq val (atoi $value))")
    (action_tile "accept" "(setq #val val)(done_dialog 1)")
    (action_tile "cancel" "(done_dialog 0)")
    (setq x_val (start_dialog))
    (cond ( (= x_val 1)
            (setq val (nth (fix val) rlist))
            (princ val)
          )
    );end)cond
  (unload_dialog dcl_id)
  val
)

You were checking for a useclick after you had unloaded the dialog. If you want to use (done dialog) then you need to collect the exit value from (start_dialog)

If the value is 1 (OK Pressed) do...

If the value is 0 do nothing

don't put (princ) as the last line in a sub it is pointless and returns nil

localise your variables at present they are all global which could affect other routines that use the same variable names

I am not one of the robots you're looking for

0 Likes