+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19
  1. #1
    Junior Member
    Discipline
    Civil
    Using
    Civil 3D 2015
    Join Date
    Mar 2017
    Posts
    24

    Default Need some help with a dialog box

    Registered forum members do not see this ad.

    Hello, I nee some help with a dialog box. I just started learning how to add dialog boxes to my lisp recently. I am trying add a dialog box to a lisp that asks 3 yes or no questions at the start. I made the DCL file and it looks the way it should. I than tried to add to the lisp file to reference this new file. The dialog box shows up I answer the questions hit OK and it stops. What am I missing?
    Any help is very much appreciated.

    Code:
    (DEFUN C:MILROAD ( / OLDL NCNT WHICH CENTERL STRAIGHT )
      (setq dialog_name "CSDLB")
      (setq id (load_dialog "CSDLB.DCL"))
      (new_dialog dialog_name id "" )
      (setq dlcnt (get_tile "opt_cntyes"))
      (if (= dlcnt 1)
        (setq NCNT "Y"))
      (setq dlstr (get_tile "opt_stryes"))
      (if (= dlstr 1)
        (setq tm1 "Y"))
      (if (= dlstr 0)
        (setq tm1 "N"))
      (setq dlsym (get_tile "opt_symyes"))
      (if (= dlsym 1)
        (setq WHICH "Y"))
      (if (= dlsym 0)
        (setq WHICH "N"))
      (action_tile "cancle" "(done_dialog 0)")
      (action_tile "accept" "(done_dialog) (setq userclick T))")
      (start_dialog)
      (unload_dialog id)
      ;(SETQ NCNT (GETSTRING "\nDO YOU NEED A CENTERLINE: Y/N"))
      ;|(IF (= NCNT "Y")
        (SETQ STRAIGHT (GETSTRING "\nIS YOUR SRTEET STRAIGHT: Y/N")))|;
      (IF (and (= NCNT "Y") (= tm1 "Y"))
        (SETQ STRAIGHT "Y"))
      (IF (and (= NCNT "Y") (= tm1 "N"))
        (SETQ STRAIGHT "N"))
      ;(SETQ WHICH (GETSTRING "\nIS THE STREET SYMMETRICAL: Y/N"))
      (IF (= STRAIGHT "Y")
        (PROGN
          (SETQ OLDL (GETVAR "CLAYER"))
          (command "layer" "set" "MISC" "")
          (C:CPOLYSTRAIGHT)
          (setq CENTERL (ENTLAST))
          (command "layer" "set" OLDL "")
          ))
      (IF (= STRAIGHT "N")
        (PROGN
          (SETQ OLDL (GETVAR "CLAYER"))
          (command "layer" "set" "MISC" "")
          (C:CPOLYCURVE)
          (setq CENTERL (ENTLAST))
          (command "layer" "set" OLDL "")
          ))
      (IF (= WHICH "N")
        (C:MILROADONE))
      (IF (= WHICH "N")
        (C:MILROADONE))
      (IF (= WHICH "Y")
        (C:MILROADTWO))
      (IF (= NCNT "Y")
        (COMMAND "_.ERASE" CENTERL ""))
      (PRINC)
      )
    Attached Files

  2. #2
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    557

    Default

    Three remarks:
    1. Using toggles instead of Yes/No radio_buttons is more common.
    2. The get_tile function always returns a string.
    3. The get_tile function should be called within the context of an action_tile action.

    This tutorial may be of interest:
    http://web2.airmail.net/terrycad/Tut.../MyDialogs.htm
    BricsCAD 16

  3. #3
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2012
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    606

    Default

    Hi aawilds,

    did some cleaning to get your dialog working on my system without being to concerned about the routine itself
    Code:
    (defun c:milroad (/ dialog_name id drv oldl ncnt which centerl straight)
      (if (and (setq dialog_name (findfile "csdlb.dcl"))
           (setq id (load_dialog dialog_name))
           (new_dialog "CSDLB" id))
        (progn
          (setq dlcnt (get_tile "opt_cntyes"))
          (if (= dlcnt 1) (setq ncnt "y"))
          (setq dlstr (get_tile "opt_stryes"))
          (if (= dlstr 1) (setq tm1 "y"))
          (if (= dlstr 0) (setq tm1 "n"))
          (setq dlsym (get_tile "opt_symyes"))
          (if (= dlsym 1)(setq which "y"))
          (if (= dlsym 0)(setq which "n"))
          (action_tile "cancel" "(done_dialog 0)")
          (action_tile "accept" "(done_dialog 1) (setq userclick t))")
          (setq drv (start_dialog))(unload_dialog id)
          (if (and (= ncnt "y") (= tm1 "y")) (setq straight "y"))
          (if (and (= ncnt "y") (= tm1 "n")) (setq straight "n"))
          (if (= straight "y")
        (progn
          (setq oldl (getvar "clayer"))(command "layer" "set" "misc" "")(c:cpolystraight)
          (setq centerl (entlast))(command "layer" "set" oldl "")))
          (if (= straight "n")
        (progn (setq oldl (getvar "clayer"))(command "layer" "set" "misc" "")(c:cpolycurve)
               (setq centerl (entlast))(command "layer" "set" oldl "")))
          (if (= which "n") (c:milroadone))
          (if (= which "n") (c:milroadone))
          (if (= which "y") (c:milroadtwo))
          (if (= ncnt "y") (command "_.erase" centerl ""))
        )
      )
      (princ)
    )
    can't really check the rest of the program because functions like (C:CPOLYSTRAIGHT) or (C:CPOLYCURVE) or (C:MILROADTWO) are not included.
    What Roy says is valid and one of the first things that catches my attention if I look at this small piece of code :

    Code:
    (setq dlsym (get_tile "opt_symyes"))   (if (= dlsym 1)     (setq WHICH "Y"))   (if (= dlsym 0)     (setq WHICH "N"))   (action_tile "cancle" "(done_dialog 0)")
    get_tile returns a string , so not 1 but "1" (or in this case always "0" because you never use action_tile for this tile)
    I think action tile cancle should be cancel
    Think much of you code can be compacter and more elegant but for a first attempt not bad.

    gr.Rlx

  4. #4
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    557

    Default

    Correction:
    2. The get_tile function returns a string if the tile key is valid and the function is called in the context of an action_tile action. Else the function returns nil.
    BricsCAD 16

  5. #5
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2012
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    606

    Default

    Quote Originally Posted by Roy_043 View Post
    Correction:
    2. The get_tile function returns a string if the tile key is valid and the function is called in the context of an action_tile action. Else the function returns nil.

    could give the complete routine in one go but what would be the fun in that, this site is meant to learn , step by step ;-)


    well ok then...

    Code:
    (defun c:milroad2 (/ dcl_name dcl-id drv use-centerline straight-street symmetrical-street)
      (if (and (setq dcl-name (findfile "csdlb.dcl"))
                 (setq dcl-id (load_dialog dcl-name))
                 (new_dialog "Curbs_and_Sidewalks" dcl-id))
        (progn
          (action_tile "tg_use_centerline" "(setq use-centerline $value)")
          (action_tile "tg_straight_street" "(setq straight-street $value)")
          (action_tile "tg_symmetrical_street" "(setq symmetrical-street $value)")
          (action_tile "cancel" "(done_dialog 0)")
          (action_tile "accept" "(done_dialog 1)")
          (setq drv (start_dialog))(unload_dialog dcl-id)
          (if (= drv 1)
            (progn
              (if (= use-centerline "1")
                  (princ "\nUsing centerline") (princ "\nNot using centerline"))
              (if (= straight-street "1")
                  (princ "\nStreet is straight") (princ "\nStreet is not straight"))
              (if (= symmetrical-street "1")
                  (princ "\nStreet is symmetrical") (princ "\nStreet is not symmetrical"))
            )
          )
        )
       )
      (princ)
    )
    Code:
    Curbs_and_Sidewalks : dialog { label = "Create Curbs and Sidewalks";
      : boxed_column { label = "Street options :";
        : toggle { label = "Use centerline"; key = "tg_use_centerline";}
        : toggle { label = "Straight street"; key = "tg_straight_street";}
        : toggle { label = "Symmetrical street"; key = "tg_symmetrical_street";}
          spacer;
      }
      spacer;ok_cancel;
    }
    gr.Rlx
    Last edited by rlx; 15th Nov 2017 at 11:28 am.

  6. #6
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,124

    Default

    Rlx, you don't need these predefined actions:
    Code:
    (action_tile "cancel" "(done_dialog 0)")
    (action_tile "accept" "(done_dialog 1)")

    I'd wrap the whole thing within a single and function, and I'd use the dialog's keys as names for the localised variables in the lisp code:
    Code:
    (defun c:milroad2 (/ dcl_name dcl-id drv tg_use_centerline tg_straight_street tg_symmetrical_street)
      
      ; Toggle associator - connect toggle value (0 or 1) with symbol value (nil or T):
      (defun tgassoc ( keyorval ) (cadr (assoc keyorval '((nil "0")(T "1")("0" nil)("1" T)))) )
      
      (and 
        ; "can't really check the rest of the program because functions like (C:CPOLYSTRAIGHT) or (C:CPOLYCURVE) or (C:MILROADTWO) are not included."
        (or C:CPOLYSTRAIGHT (prompt "\nFunction C:CPOLYSTRAIGHT nod defined."))
        (or C:CPOLYCURVE (prompt "\nFunction C:CPOLYCURVE nod defined."))
        (or C:MILROADTWO (prompt "\nFunction C:MILROADTWO nod defined."))
        (setq dcl-name (findfile "csdlb.dcl"))
        (setq dcl-id (load_dialog dcl-name))
        (new_dialog "Curbs_and_Sidewalks" dcl-id)
        (progn
          (mapcar 
            '(lambda (x) (action_tile x (strcat "(setq $key (tgassoc $value))")))
            '("tg_use_centerline" "tg_straight_street" "tg_symmetrical_street")
          )
          (setq drv (start_dialog)) (unload_dialog dcl-id) (= drv 1)
        ); progn    
        (progn
          (if tg_use_centerline (princ "\nUsing centerline") (princ "\nNot using centerline"))
          (if tg_straight_street (princ "\nStreet is straight") (princ "\nStreet is not straight"))
          (if tg_symmetrical_street (princ "\nStreet is symmetrical") (princ "\nStreet is not symmetrical"))
        ); progn
      ); and 
      (princ)
    ); defun
    Just sharing my preferences - your example should be more understandable for the OP.

  7. #7
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2012
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    606

    Default

    @Grrr, indeed you don't really need them but for someone who's just starting, this code might be just a little bit too complex. I use a lot of mapcars and lambda's too but not everybody is comfortable with these command. Also , maybe one day a new person needs to edit the code. He might be Einstein , he might be Lee ... or not ;-)
    Have done very little coding lately, not enough hours in a day... but, always nice to hear from you!


    gr.Rlx

  8. #8
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,124

    Default

    Rlx,
    I definitely do not doubt about your skills - I think that the question here is 'what would be the most short and understandable example'.
    I tried avoid using mapcar'n'lambda for the simplier examples too, but its just too tempting to shorten the code.
    So just trying to provide example thats somewhere in the middle...

    Maybe I should use:
    Code:
    (foreach x '("tg_use_centerline" "tg_straight_street" "tg_symmetrical_street")
      (action_tile x (strcat "(setq $key (tgassoc $value))"))
    )
    Instead of:
    Code:
    (mapcar 
      '(lambda (x) (action_tile x (strcat "(setq $key (tgassoc $value))")))
      '("tg_use_centerline" "tg_straight_street" "tg_symmetrical_street")
    )
    Because I just now realised that foreach will be more suitable for simplicity, effectivness and shortness.

    Quote Originally Posted by rlx View Post
    Have done very little coding lately, not enough hours in a day... but, always nice to hear from you!
    Same here, I've got too much aside work to keep me off from my hobby... Still 5-10 minutes coding a day should keep anyone in shape.

  9. #9
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2012
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    606

    Default

    Quote Originally Posted by Grrr View Post
    Rlx, I definitely do not doubt about your skills

    thanx for the confidence but I really think my skills are a little exaggerated haha. I sometimes have original ideas but I lack speed, so experience is good , but IQ is better


    gr. Rlx

  10. #10
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    557

    Default

    Registered forum members do not see this ad.

    @Grrr:
    Are you sure this works as intended?:
    Code:
    (action_tile x (strcat "(setq $key (tgassoc $value))"))
    BricsCAD 16

Similar Threads

  1. DCL dialog box that modifies a nested dialog box...
    By sethtriad in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 28th Feb 2013, 01:30 pm
  2. Dialog box too big
    By assafius in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 10th Oct 2012, 12:59 pm
  3. Dialog box help
    By j_spawn_h in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 15th Nov 2011, 03:52 am
  4. Where is my dialog?
    By CAD Panacea in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 6th Mar 2009, 02:20 pm
  5. DWG in Dialog Box?
    By BLOACH85 in forum AutoLISP, Visual LISP & DCL
    Replies: 30
    Last Post: 25th Feb 2009, 09:02 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts