Author Topic: (DCL) How do you set a value in a popup_list?  (Read 8114 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)

Mark

  • Custom Title
  • Seagull
  • Posts: 28683
(DCL) How do you set a value in a popup_list?
« Reply #15 on: November 19, 2003, 03:35:00 PM »
Thank you gentlemen, it's starting to make sense now.
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
(DCL) How do you set a value in a popup_list?
« Reply #16 on: November 19, 2003, 03:42:42 PM »
You're welcome.

Wow, it may work for very small dialogs to put stuff into the OK button, but I think you'll get in trouble with more values.

For example, below is a loop of a quite large dialog. It doesn't matter what it does but outside this simple "engine" there is some 650 lines of utility functions that are called by the tiles (which keeps the ACTION_TILE calls very easy to write and maintain). The OK button does NOTHING except return a simple integer of 1.
If 1 then process the stuff, otherwise do nothing. If I had to construct an action_tile of all that I would go loco!

Code: [Select]
;...
(while (>= action 2)
  (if (not (new_dialog "layercomp" dcl_id))
    (exit)
  )
  (mapcar 'set_tile
          '("pos1" "pos2-4" "pos5" "pos6" "pos7")
          (list pos1 pos2-4 pos5 pos6 pos7)
  )
  (set_tile "special" "0")              ; get from registry
  (start_list "ansvar")
  (mapcar 'add_list (mapcar 'cadr ansvarList))
  (end_list)
  (set_tile "ansvar" currAnsvar)
  ;;change to registry
  (start_list "sfbmain")
  (mapcar 'add_list sfbmainOutput)
  (end_list)
  (start_list "info_6")
  (mapcar 'add_list info6Output)
  (end_list)
  (start_list "info_7")
  (mapcar 'add_list info7Output)
  (end_list)
  (start_list "ltypes")
  (mapcar 'add_list ltypeList)
  (end_list)
  (start_list "lweight")
  (mapcar 'add_list lwOutput)
  (end_list)
  (set_tile "plotoff" currPlot)
  (updateCode5 currAnsvar)
  (updLayer t)
  (action_tile "special" "(checkSfBGroup)")
  (action_tile "pos8" "(setPos8 $value)")
  (action_tile "ansvar" "(updateCode5 (setq currAnsvar $value))")
  (action_tile "sfbmain" "(updateSfBGroups (setq currSfBMain $value))")
  (action_tile "sfbgroup" "(updateSfBPos (setq currSfBGroup $value))")
  (action_tile "code_5" "(setCode5 (setq currCode5 $value))")
  (action_tile
    "info_6"
    "(setInfo (setq currInfo6 $value) infolist_6 \"info6txt\" $key)"
  )
  (action_tile
    "info_7"
    "(setInfo (setq currInfo7 $value) infolist_7 \"info7txt\" $key)"
  )
  (action_tile "lweight" "(setq currLweight (nth (atoi $value) lwList))")
  (action_tile "currlayer" "(setCurrentLayer $value)")
  (action_tile "ltload" "(progn (ddloadLtype dcl_id)(updateLtypes))")
  (action_tile "ltypes" "(setq currLtype $value)")
  (action_tile "plotoff" "(setq currPlot $value)")
                                        ;(action_tile "ltypes" "(setLtypes (setq currLtype $value))")
  (action_tile "lcolor" "(setq currColor (getAcadColor currColor))")
  (action_tile "l_make" "(addlayer)")

  (setq action (start_dialog))
  (cond ((= action 1)
         (foreach n '(currAnsvar)
           (if (not (eval n))
             (set n "0")))
         (setRegistryValues
           "HKEY_LOCAL_MACHINE\\SOFTWARE\\"
           "ddcompose"
           '(currAnsvar)
         )
         (updLayer nil)
         ;; TODO 240903: do loading of lagStradaMainDlg in the start of function
         ;; and alert if not found!!! Delete this test then
         (cond ((not (member (type (eval makeLayer)) '(SUBR USUBR)))
                (cond ((load "lagStradaMainDlg" nil)
                       (foreach n finalrecords
                         (makeLayer (mapcar 'cdr n))
                       ))))
               (t
                (foreach n finalrecords
                  (makeLayer (mapcar 'cdr n) nil)
                )))
         (princ "Lagnavn: ")
         (princ currLayer)
         (mapcar 'princ
                 (list "\nL: " currLayer "\nLt: " currLtype "\nCol: " currColor "\nLw: " currLweight
                       "\ncurrPlot: " currPlot
                      ))
         (terpri)
         (princ currLyrInfo)
        )
  )
;....
)