Author Topic: Prompt for justification  (Read 287 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Bull Frog
  • Posts: 306
Prompt for justification
« on: February 25, 2017, 12:48:17 pm »
Hi guys,



I was about to ask if this is doable with using radio_buttons (3x3 matrix button display) but I've managed to figure it out bymyself.  :yay!:



So I'm leaving this here, as a solution to help anyone:

Code - Auto/Visual Lisp: [Select]
  1. ; Use DCL to prompt for justification
  2. ; (GetJustificationDCL nil nil)
  3. ; (GetJustificationDCL nil T)
  4. ; (GetJustificationDCL "Move Option" nil)
  5. ; (GetJustificationDCL "Move Option" T)
  6. (defun GetJustificationDCL ( dlbl UseRadios / *error* b dcl des dch dcf rtn )
  7.  
  8.  (defun *error* ( msg )
  9.    (and (< 0 dch) (unload_dialog dch))
  10.    (and (eq 'FILE (type des)) (close des))
  11.    (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl))
  12.    (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\nError: " msg)) ))
  13.    (princ)
  14.  ); defun *error*
  15.  
  16.  (setq b (if UseRadios ": radio_button" ": button"))
  17.  
  18.  (cond
  19.    (
  20.      (not
  21.        (and (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w"))
  22.          (vl-every (function (lambda (x) (princ x des))); write-line / princ
  23.            (list
  24.              "Justification : dialog"
  25.              (strcat "{ label = \"" (if (eq 'STR (type dlbl)) dlbl "Choose Justification") "\";")
  26.              (if UseRadios " : radio_column " " : column ")
  27.              "  { : row { " b " { label = \"TL\"; key = \"TL\"; } " b " { label = \"TC\"; key = \"TC\"; } " b " { label = \"TR\"; key = \"TR\"; } } "
  28.              "    : row { " b " { label = \"ML\"; key = \"ML\"; } " b " { label = \"MC\"; key = \"MC\"; } " b " { label = \"MR\"; key = \"MR\"; } } "
  29.              "    : row { " b " { label = \"BL\"; key = \"BL\"; } " b " { label = \"BC\"; key = \"BC\"; } " b " { label = \"BR\"; key = \"BR\"; } } "
  30.              "  } "
  31.              "  spacer;"
  32.              "  ok_cancel; "
  33.              "  : text { label = \"\"; key = \"info\"; } "
  34.              "}"
  35.            ); list
  36.          ); mapcar
  37.          (not (setq des (close des))) (< 0 (setq dch (load_dialog dcl)))
  38.        ); and
  39.      ); not
  40.      (princ "\nUnable to write or load the DCL file.")
  41.    )
  42.    ( (not (new_dialog "Justification" dch)) (princ "\nUnable to display the dialog.") )
  43.    (
  44.      (not
  45.        (and
  46.          (vl-every
  47.            (function
  48.              (lambda (x)
  49.                (action_tile x
  50.                  (vl-prin1-to-string
  51.                    '(progn (if UseRadios (mapcar '(lambda (k) (set_tile k "0")) '("TL" "TC" "TR" "ML" "MC" "MR" "BL" "BC" "BR")))
  52.                      (set_tile $key "1") (setq rtn $key) (set_tile "info" (strcat "Chosen justification: " $key))
  53.                    )
  54.                  )
  55.                )
  56.              )
  57.            )
  58.            '("TL" "TC" "TR" "ML" "MC" "MR" "BL" "BC" "BR")
  59.          ); vl-every
  60.          (action_tile "accept" (vl-prin1-to-string '(cond ( (not rtn) (set_tile "info" "Choose justification, please!") ) ( (done_dialog 1) ))))
  61.          (setq dcf (start_dialog))
  62.        ); and
  63.      ); not
  64.      (princ "\nUnable to start the dialog.")
  65.    )
  66.    ( (/= 1 dcf) (princ "\nUser cancelled the dialog.") (setq rtn nil) )
  67.  ); cond
  68.  (*error* nil) (princ) rtn
  69. ); defun GetJustificationDCL

Cheers!
« Last Edit: February 25, 2017, 12:58:25 pm by Grrr1337 »

Lee Mac

  • Seagull
  • Posts: 11661
  • AutoCAD 2015 Windows 7 London, England
Re: Prompt for justification
« Reply #1 on: February 25, 2017, 01:11:42 pm »
Nice one Grrr1337 - I see that your DCL skills are improving with every post  :-)

To offer another option in addition to buttons & radio_buttons, you could also use image_buttons - here are a couple of examples:

Justify Base Point
DCL Bitmaps (See Text Wrapping example)

Grrr1337

  • Bull Frog
  • Posts: 306
Re: Prompt for justification
« Reply #2 on: February 25, 2017, 01:39:02 pm »
Thanks Lee!  :-)
The main reason for my improvement is that I'm learning most of the stuff from you, since you perfected everything in lisp. Thank god that you exist!
I don't think I'll ever become insane programmer like you - but I'm doing my best (slowly and surely) (my intention is to become insane CAD drafter).

hint about my intention with this: It will be used to justify SelectionSets (using move).

roy_043

  • Swamp Rat
  • Posts: 1428
  • BricsCAD 16
Re: Prompt for justification
« Reply #3 on: February 25, 2017, 04:05:39 pm »
@Grrr1337: Try using the radio_cluster tile.

Grrr1337

  • Bull Frog
  • Posts: 306
Re: Prompt for justification
« Reply #4 on: February 25, 2017, 06:21:15 pm »
Thanks Roy, I feel that I'm missing something.
However I just tried this and got this messy result :



Heres the test code - using Keith's suggestion (and without manually resetting all the tile's values to 0 - for every action) :

Code - Auto/Visual Lisp: [Select]
  1. ; Radio_cluster test:
  2. (defun C:test ( / *error* dcl des dch rtn dcf )
  3.  
  4.  (defun *error* ( msg )
  5.    (and (< 0 dch) (unload_dialog dch))
  6.    (and (eq 'FILE (type des)) (close des))
  7.    (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl))
  8.    (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\nError: " msg)) ))
  9.    (princ)
  10.  ); defun *error*
  11.  
  12.  (cond
  13.    (
  14.      (not
  15.        (and (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w"))
  16.          (princ
  17.            (strcat
  18.              "Justification : dialog"
  19.              "{ label = \"test\";"
  20.              "  : radio_cluster"
  21.              "  { :row "
  22.              "    { : column "
  23.              "      { : radio_button { label = \"TL\"; key = \"TL\"; }"
  24.              "        : radio_button { label = \"TC\"; key = \"TC\"; }"
  25.              "        : radio_button { label = \"TR\"; key = \"TR\"; }"
  26.              "      }"
  27.              "      : column "
  28.              "      { : radio_button { label = \"ML\"; key = \"ML\"; }"
  29.              "        : radio_button { label = \"MC\"; key = \"MC\"; }"
  30.              "        : radio_button { label = \"MR\"; key = \"MR\"; }"
  31.              "      }"
  32.              "      : column "
  33.              "      { : radio_button { label = \"BL\"; key = \"BL\"; }"
  34.              "        : radio_button { label = \"BC\"; key = \"BC\"; }"
  35.              "        : radio_button { label = \"BR\"; key = \"BR\"; }"
  36.              "      }"
  37.              "    }"
  38.              "  }"
  39.              "  spacer;"
  40.              "  ok_cancel;"
  41.              "  : text { label = \"\"; key = \"info\"; } "
  42.              "}"
  43.            ); strcat
  44.            des
  45.          ); princ
  46.          (not (setq des (close des))) (< 0 (setq dch (load_dialog dcl)))
  47.        ); and
  48.      ); not
  49.      (princ "\nUnable to write or load the DCL file.")
  50.    )
  51.    ( (not (new_dialog "Justification" dch)) (princ "\nUnable to display the dialog.") )
  52.    (
  53.      (not
  54.        (and
  55.          (vl-every
  56.            (function
  57.              (lambda (x)
  58.                (action_tile x (vl-prin1-to-string '(progn (setq rtn $key) (set_tile "info" (strcat "Chosen justification: " $key)))))
  59.              )
  60.            )
  61.            '("TL" "TC" "TR" "ML" "MC" "MR" "BL" "BC" "BR")
  62.          ); vl-every
  63.          (action_tile "accept" (vl-prin1-to-string '(cond ( (not rtn) (set_tile "info" "Choose justification, please!") ) ( (done_dialog 1) ))))
  64.          (setq dcf (start_dialog))
  65.        ); and
  66.      ); not
  67.      (princ "\nUnable to start the dialog.")
  68.    )
  69.    ( (/= 1 dcf) (princ "\nUser cancelled the dialog.") (setq rtn nil) )
  70.    (rtn (alert rtn) )
  71.  ); cond
  72.  (*error* nil) (princ)
  73. ); defun C:test
  74.  

BTW Thats a nice thread, thanks!  :-)

roy_043

  • Swamp Rat
  • Posts: 1428
  • BricsCAD 16
Re: Prompt for justification
« Reply #5 on: February 27, 2017, 08:14:33 am »
I do not know why the radio_cluster does not work in this case. BricsCAD does not support this tile. Maybe somebody with an AutoCAD license can shed some light.

Lee Mac

  • Seagull
  • Posts: 11661
  • AutoCAD 2015 Windows 7 London, England
Re: Prompt for justification
« Reply #6 on: February 27, 2017, 08:24:13 am »
I do not know why the radio_cluster does not work in this case. BricsCAD does not support this tile. Maybe somebody with an AutoCAD license can shed some light.

IIRC, I could never get it to work as expected.

MP

  • Seagull
  • Posts: 16907
  • brevity != aggression
Re: Prompt for justification
« Reply #7 on: February 27, 2017, 09:12:25 am »
The ambitious might fake it with image tiles.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

snownut2

  • Swamp Rat
  • Posts: 919
  • ADT 2004 - AutoCad 2011 Bricscad 15
Re: Prompt for justification
« Reply #8 on: March 10, 2017, 11:15:44 am »
I've not been successful in getting multiple rows or columns of radio buttons to work in Bcad or ACAD.
God helps those who helps themselves.
A little searching goes a long ways.