Author Topic: (DCL) How do you set a value in a popup_list?  (Read 7983 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28683
(DCL) How do you set a value in a popup_list?
« on: November 19, 2003, 12:22:28 PM »
I want to set the value of the popup_list to something other than "0" depending on the users last selection. I've tried the following but it locks up ACAD when I run it.
Code: [Select]

(start_list "selections")
(mapcar 'add_list lst)
(end_list)
 (if (setq pos (vl-position mst-last-sel lst))
   (set_tile "selections" (itoa pos))
   (set_tile "selections" "0"); default
   )

mst-last-sel = string
lst = list of strings
Code: [Select]

: popup_list {
label = "Select Override:";
allow_accept = true;
is_tab_stop = true;
key = "selections";
value = ""; // <-- here
edit_width = 30;
}
TheSwamp.org  (serving the CAD community since 2003)

Eloquintet

  • Gator
  • Posts: 3206
(DCL) How do you set a value in a popup_list?
« Reply #1 on: November 19, 2003, 12:39:37 PM »
hmmm that looks familiar  :wink:

dan
Dan

AutoCAD Architecture 2015

Columbia

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #2 on: November 19, 2003, 01:11:13 PM »
When you run your program code, does AutoCAD show the dialog and then refuse to let it go?  Or does it not get that far and break on trying to stuff the list?

Mark

  • Custom Title
  • Seagull
  • Posts: 28683
(DCL) How do you set a value in a popup_list?
« Reply #3 on: November 19, 2003, 01:15:41 PM »
>does AutoCAD show the dialog and then refuse to let it go?

Yep.
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #4 on: November 19, 2003, 01:56:28 PM »
Just made a short test of it. This works ok:

Code: [Select]
;...
(setq lst '("aaa" "bbb" "ccc" "ddd" "eee"))
(cond ((new_dialog "poptest" dcl_id)
       (start_list "selections")
       (mapcar 'add_list lst)
       (end_list)
       (if (setq pos (vl-position mst-last-sel lst))
         (set_tile "selections" (itoa pos))
         (set_tile "selections" "0")  ; default
       )
       (action_tile "selections"
           "(setq mst-last-sel (nth (atoi $value) lst))")
       (start_dialog)
      )
)
;...

Columbia

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #5 on: November 19, 2003, 02:11:12 PM »
Mark,

It would be a good bet that you forgot to use (start_dialog).  I do it all the time and it locks AutoCAD up tighter than drum.

Craig

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #6 on: November 19, 2003, 02:21:20 PM »
Thats what I was gonna say.

Mark

  • Custom Title
  • Seagull
  • Posts: 28683
(DCL) How do you set a value in a popup_list?
« Reply #7 on: November 19, 2003, 02:29:41 PM »
I don't know! This is what I'm using, am I missing something?
Code: [Select]
(defun DimTextOverRide (lst obj / *error* dcl_id str sel cur output)

  ;; error function
  (defun *error* (msg)
    (if (not
          (member
            msg
            '("console break" "Function cancelled" "quit / exit abort")
            )
          )
      (princ (strcat "\nError: " msg))
      ) ; if
    (princ)
    ) ; end error funtion


  ;load dialog
  (setq dcl_id (load_dialog "dcl_popup_list.dcl"))
 
  (if (not (new_dialog "dcl_popup_list" dcl_id))
    (exit)
    ) ;if
 
  (setq str (vlax-get-property obj 'TextOverride))
  (set_tile "curt" str)

  (start_list "selections")
  (mapcar 'add_list lst)
  (end_list)
;  (if (setq pos (vl-position mst-last-sel lst))
;    (set_tile "selections" (itoa pos))
;    (set_tile "selections" "0"))

  (action_tile
    "accept"
    (strcat
      "(progn
         (setq sel (atoi (get_tile \"selections\")))"
         "(setq cur (get_tile \"curt\"))"
         "(done_dialog)
         )"
      ) ;strcat
    ) ;action tile

    (action_tile "cancel" "(done_dialog)(exit)")
    ;action_tile
 
    (start_dialog)
    (unload_dialog dcl_id)

    (if (/= cur str); edit box changed, so ignore the list box
      (setq output cur)
      (setq output (nth sel lst))
      )
    output
    )
TheSwamp.org  (serving the CAD community since 2003)

Craig

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #8 on: November 19, 2003, 02:43:19 PM »
Is your dialog box coming up at all?
Code: [Select]
(setq dcl_id (load_dialog "dcl_popup_list.dcl"))
  (if (not (new_dialog "dcl_popup_list" dcl_id))

If not, is this the correct name for the .dcl file and is the dcl_id correct?

DParcon

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #9 on: November 19, 2003, 02:43:24 PM »
Try this:

 
 popup : dialog  {
   label  = "SAMPLE POP-UP LIST" ;
     : row {
         : column {
              : popup_list {
                  label       = "Flange Ratings" ;
                  key         = "rating" ;
                  edit_width  = 12 ;  
                  list        = "" ;
                  }
         }
     }
     ok_cancel ;
  }
         
  ;;;Save above dcl as popup.dcl

   (defun C:POPUP ()
    (setq rlist '("150" "300" "400" "600" "900" "1200")
          dcl_id (load_dialog "popup.dcl")
    )
    (if (not (new_dialog "popup" dcl_id))
      (exit)
    )
    (start_list "rating")
    (mapcar 'add_list rlist)
    (end_list)
    (if #val
      (set_tile "rating" (itoa (setq val #val)))
      (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)
    (princ)
  )

Craig

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #10 on: November 19, 2003, 02:49:11 PM »
Mark, post your DCL file

SMadsen

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #11 on: November 19, 2003, 03:10:41 PM »
Mark,
Do you normally put everything into the OK and Cancel buttons? Why force an error in the Cancel button with EXIT?

See if this runs (probably not the behavior you want - the popup sets the edit_box - but you can just change that):

Code: [Select]
(defun DimTextOverRide (lst obj / *error* dcl_id str sel cur output action)

  ;; error function
  (defun *error* (msg)
    (if (not
          (member
            msg
            '("console break" "Function cancelled" "quit / exit abort")
          )
        )
      (princ (strcat "\nError: " msg))
    ) ;_ if
    (princ)
  ) ;_ end error function

  (defun setValue (val alist / ret)
    (setq ret (nth (atoi val) alist))
    (set_tile "curt" (strcat "<> " ret))
    ret
  )

  ;; load dialog
  (setq dcl_id (load_dialog "dcl_popup_list.dcl"))
  (if (not (new_dialog "dcl_popup_list" dcl_id))
    (exit)
  ) ;_ if

  (setq str (vlax-get-property obj 'TextOverride))
  (set_tile "curt" str)

  (start_list "selections")
  (mapcar 'add_list lst)
  (end_list)
  (if (setq pos (vl-position mst-last-sel lst))
    (set_tile "selections" (itoa pos))
    (set_tile "selections" "0")
  )
  (action_tile "selections" "(setq mst-last-sel (setValue $value lst) cur (get_tile \"curt\"))")
  (action_tile "curt" "(setq cur $value)")
;;;    (strcat
;;;      "(progn
;;;         (setq sel (atoi (get_tile \"selections\")))"
;;;      "(setq cur (get_tile \"curt\"))"
;;;      "(done_dialog)
;;;         )"
;;;    )                                   ;strcat
;;;  )                                     ;action tile
;;;  (action_tile "cancel" "(done_dialog)(exit)") ;action_tile
  (setq action (start_dialog))
  (unload_dialog dcl_id)
  (cond ((= action 1)
         (if (/= cur str)               ; edit box changed, so ignore the list box
           (setq output cur)
           (setq output (nth sel lst))
         )
        )
  )
  output
)

SMadsen

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #12 on: November 19, 2003, 03:19:06 PM »
Action_tile for "selections" changed to this since last posting (makes a bit more sense):
(action_tile "selections" "(setq mst-last-sel (setValue $value lst) cur (get_tile \"curt\"))")

Columbia

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #13 on: November 19, 2003, 03:20:05 PM »
Mark,

here's a quick edit of your file...

Please notice a couple of quick things
1.) I pulled the strcat out of your action_tile call because you don't really need it.
2.) I'm also pulled the (exit) call out of your "cancel" action_tile call, because I'm using the optional integer call on done_dialog.  And that way I'm getting the same results without crashing out of the routine.

Code: [Select]

(defun DimTextOverRide (lst obj / *error* dcl_id str sel cur output start)

  ;; error function
  (defun *error* (msg)
    (if (not (member msg '("console break" "Function cancelled" "quit / exit abort")))
      (princ (strcat "\nError: " msg))
    ) ; if
    (princ)
  ) ; end error funtion


  ;load dialog
  (setq dcl_id (load_dialog "dcl_popup_list.dcl"))
 
  (if (not (new_dialog "dcl_popup_list" dcl_id)) (exit)) ;if
 
  (setq str (vlax-get-property obj 'TextOverride))
  (set_tile "curt" str)

  (start_list "selections")
  (mapcar 'add_list lst)
  (end_list)
  (if (setq pos (vl-position mst-last-sel lst))
    (set_tile "selections" (itoa pos))
    (set_tile "selections" "0")
  )

  (action_tile "selections" "(setq sel $value)")
  (action_tile "accept"
    "(setq sel (atoi (get_tile \"selections\")) cur (get_tile \"curt\")) (done_dialog 1)"
  )
  (action_tile "cancel" "(done_dialog 2)")
 
  (setq start (start_dialog))
  (unload_dialog dcl_id)
  (cond
    ( (= start 1)
      (if (/= cur str) ; edit box changed, so ignore the list box
        (setq output cur)
        (setq output (nth sel lst))
      )
    )
  )
  output
)


Darn it All!!!!!  I was beat again by too fast typing coders!!!! AGGHHHH!!!

However, as you can see from above I agree with SM whole heartedly. :D

Mark

  • Custom Title
  • Seagull
  • Posts: 28683
(DCL) How do you set a value in a popup_list?
« Reply #14 on: November 19, 2003, 03:22:58 PM »
>Do you normally put everything into the OK and Cancel buttons?

Well, that's how I've always done it. I've never taken the time to learn it properly.

Works very well Stig, thanks.

- DParcon
thanks for the insight.
TheSwamp.org  (serving the CAD community since 2003)