Exchange Forum > Dcl Dialogs
I can't get it
I can't get it

#1

Seventhram
Join Date:
05-27-2008
I must be the biggest retard in the world…..I have been programming AutoLISP what seems like forever…..never really messed with dialog boxes in my programs….so I get the wild hair to rewrite a few of my programs with dialog boxes and talk about making my feel like a idiot……something as simple as getting a radio_button to tell me which one is selected and do a "setq" seems to be too much for me…I cant get it, I've tried everything I have read or can find. Please, someone tell me what I'm doing wrong.
 
-----------------------------------------------------------------------------------------------
border : dialog {
label = "My Border Program";
: text {
label = "Select the Scale of your Drawing";
}
: row {
: boxed_column {
// key = "ascale"{
label = "Architectural Scale";
: radio_button {
key = "as1";
label = "1=1";
}
: radio_button {
key = "as2";
label = "3/4=1";
}
: radio_button {
key = "as3";
label = "1/2=1";
}
}
}
ok_cancel;
}
----------------------------------------------------------------
;
; BORDER command - custom setup routine
;
(setq dcl_id (load_dialog "border.dcl"))
(if (not (new_dialog "border" dcl_id))
(exit)
)
(start_dialog)
; (if (= "1" action_tile "as1")
; (setq scale "111")
; )
; (if (= "1" action_tile "as2")
; (setq scale "222")
; )
; (if (= "1" action_tile "as3")
; (setq scale "4444")
; )
; (if (= "1" get_tile "as1")
; (setq scale "111")
; )
; (if (= "1" get_tile "as2")
; (setq scale "222")
; )
; (if (= "1" get_tile "as3")
; (setq scale "4444")
; )
; (action_tile "as1" (setq scale "111"))
; (action_tile "as2" (setq scale "222"))
; (action_tile "as3" (setq scale "4444"))
; (action_tile "scale" "(setq scale $value)")
; (done_dialog)
(unload_dialog dcl_id)
-------------------------------------------------------------------------------------------
 
As you can see, I've tried every IF statement I can think of……………all I want it to do is when I pick "one" of the radio_buttons (I used radio_buttons so the user could only pick one), return to me which one they picked and (setq scale) to a value I have in my lisp routine.
Why is that so hard??? Something so simple is eating my lunch.
Thank you,
Seventhram
I can't get it

#2

Bennett
Join Date:
07-26-2007
Seventhram,
Sometimes it's confusing at first. In the lisp part I moved the (start_dialog) after the action_tile calls.
In the dialog part it needed a the main boxed_radio_column that the radio_buttons are part of.
Welcome,
Bennett
 
Code:
;Border.lsp
(defun c:Border (/ dcl_id return)
  (setq dcl_id (load_dialog "Border.dcl"))
  (new_dialog "border" dcl_id);Remember that dcl is case sensitive, so use the same case as is in the dcl file.
  (action_tile "ascale" "(setq Scale $value)")
  (setq return (start_dialog));This line needs to be after action_tile calls.
  (unload_dialog dcl_id)
  (if (= return 0) (exit));Exit if Cancel selected.
  (cond
    ((= Scale "as1")(setq Scale "111"));Don't you want these to be numbers?
    ((= Scale "as2")(setq Scale "222"))
    ((= Scale "as3")(setq Scale "4444"))
  )
  (princ "\nScale = ")(princ Scale)
  (princ)
)
 
Code:
//Border.dcl
border : dialog {
  label = "My Border Program";
  : text {
    label = "Select the Scale of your Drawing";
  }
  : boxed_radio_column {
    key = "ascale";
    label = "Architectural Scale";
    : radio_button {
      key = "as1";
      label = "1=1";
    }
    : radio_button {
      key = "as2";
      label = "3/4=1";
    }
    : radio_button {
      key = "as3";
      label = "1/2=1";
    }
    spacer;
  }
  ok_cancel;
}
I can't get it

#3

Adesu
Join Date:
10-03-2007
Or like this:
LSP File
Code:
(defun c:test (/ data_as1 data_as2 data_as3 data_box scale)
  (setq dcl_id (load_dialog "border.dcl"))
  (if
    (not (new_dialog "border" dcl_id))
    (exit)
  ) ; if
  (setq scale '("1=1" "3/4=1" "1/2=1"))
  (set_tile "as1" "111")
  (mode_tile "as1" 2)
  (mode_tile "as2" 2)
  (mode_tile "as3" 2)
  (action_tile
    "as1"
    "(progn
    (setq data_as1 (get_tile \"as1\"))
    (setq data_box (nth (- (atoi data_as1) 1) scale)))")
  (action_tile
    "as2"
    "(progn
    (setq data_as2 (get_tile \"as2\"))
    (setq data_box (nth (atoi data_as2) scale)))")
  (action_tile
    "as3"
    "(progn
    (setq data_as3 (get_tile \"as3\"))
    (setq data_box (nth (+ (atoi data_as3) 1) scale)))")
  (action_tile "accept" "(done_dialog 1)")
  (setq ans (start_dialog))  
  (if
    (= ans 1)
    (progn
      (alert  (strcat "\nYou just click " "\"" data_box "\""))
    ) ; progn
  ) ; if
  (princ)
) ; defun  
 
DCL File
Code:
border : dialog {label = "My Border Program"; 
       : text {label = "Select the Scale of your Drawing";} 
       : row { 
       : boxed_column {label = "Architectural Scale"; 
       // key = "ascale"{ 
       : radio_button {label = "1=1";  
                       key = "as1";} 
       : radio_button {label = "3/4=1";  
                       key = "as2";} 
       : radio_button {label = "1/2=1";  
                       key = "as3";}}} 
       ok_cancel;} 
I can't get it

#4

Seventhram
Join Date:
05-27-2008
Thank you Bennett,
Thank you Adesu,
 
I used your suggestions Bennett, it worked perfectly. I'm still a little confused, but it works. Yes, I needed those to be real #'s, I just did a "atof" to convert it to a real #. Now that I have it working, I can re-write it again for engineering scales and architectural scales. I'm trying to totally eliminate the user from using a non-standard scale....then set the border, set-up all the text, dim's.....actually try to standardize things....imagine that, a company actually using standards....lol
 
Thanks again,
Seventhram
I can't get it

#5

Bennett
Join Date:
07-26-2007
Seventhram,
You're too kind! Thanks. I noticed that I forgot to declare Scale and setq it's default in my version. If the user was to pick the OK button before selecting a scale the return would be nil. I've included the revised version. Have you given any thought to using a popup list version of your dialog. It takes up much less space than rows of radio buttons. Just let me know.
Bennett
Code:
(defun c:Border (/ dcl_id return Scale)
  (setq dcl_id (load_dialog "Border.dcl"))
  (new_dialog "border" dcl_id)
  (setq Scale "as1");Default
  (set_tile "ascale" "as1");Set default
  (action_tile "ascale" "(setq Scale $value)")
  (setq return (start_dialog))
  (unload_dialog dcl_id)
  (if (= return 0) (exit))
  (cond
    ((= Scale "as1")(setq Scale "111"))
    ((= Scale "as2")(setq Scale "222"))
    ((= Scale "as3")(setq Scale "4444"))
  )
  (princ "\nScale = ")(princ Scale)
  (princ)
)
I can't get it

#6

Seventhram
Join Date:
05-27-2008
Bennett, thanks again, I totally over looked setting a default scale, thats a good idea, thank you. My original design for this dialog box was to use a pop-up list, but I had even more trouble getting that to work. The way I wanted to design it was to have two different popup list, one architectural scale and one engineering scale with a radio buttom above each one and you could only toggle back and forth between arch and eng scales, when you selected one, the other popup list could not be selected. In the one below, I have them stacked, and every time I tried to get them side by side I couldnt get it to work....actually two side by side groups where if you select one, the other can not be selected.
 
Below is what I started:
 
border : dialog {
label = "Border Program";
: boxed_radio_column {
label = "Select the Scale of your Drawing";
:radio_button {
label = "Architectural Scale";
key = "ascale";
value = "1";
}
:radio_button {
label = "Engineering Scale";
key = "escale";
}
:popup_list {
label = "";
list = "1=1 (1)\n3/4=1 (1.3333)\n1/2=1 (2)\n3/8=1 (2.6667)\n1/4=1 or 3=12 (4)\n3/16=1 (5.3333)\n1/8=1 or 1 1/2=12 (8)\n3/32=1 (10.6667)\n1=12 (12)\n3/4=12 (16)\n1/2=12 (24)\n3/8=12 (32)\n1/4=12 (48)\n3/16=12 (64)\n1/8=12 (96)\n3/32=12 (128)";
key = "scalea";
}
:popup_list {
label = "";
list = "1=10Ft (120)\n1=20Ft (240)\n1=30Ft (360)\n1=40Ft (480)\n1=50Ft (600)\n1=60Ft (720)\n1=70Ft (840)\n1=80Ft (960)\n1=90Ft (1080)\n1=100Ft (1200)";
key = "scalee";
}
}
ok_cancel ;
}
 
As you can imagine using radio buttoms it gets to be a pretty long dialog box, where using a popup list would make it a lot smaller.....but as before, how do you get the value of the popup to be returned in my lisp program??
 
Thanks again,
Seventhram
I can't get it

#7

Bennett
Join Date:
07-26-2007
Yea, that looks better! You mentioned graying out one of the lists depending if they chose Architectural or Engineering. How about just changing the values in one list. Here's what I put together. I added a variable named RealScale that you might be able to use in the rest of your program.
Bennett
Code:
Border : dialog {
  label = "Border Program";
  : boxed_radio_column {
    label = "Select the Scale of your Drawing";
    key = "ScaleType";
    : radio_button {
      label = "Architectural Scale";
      key = "1";
    }
    : radio_button {
      label = "Engineering Scale";
      key = "2";
    }
    : popup_list {
      key = "ScaleList";
    }
    spacer;
  }
  ok_cancel;
}
Code:
(defun c:Border (/ ArchScales Dcl_Id EngScales RealScale Return Scale ScaleList
  ScaleType SetScale SetScaleType)
  (defun SetScaleType ()
    (setq ScaleType $value)
    (if (= ScaleType "1")
      (setq ScaleList ArchScales)
      (setq ScaleList EngScales)
    )
    (setq Scale (nth 0 ScaleList))
    (start_list "ScaleList" 3)(mapcar 'add_list ScaleList)(end_list)
    (set_tile "ScaleList" (itoa (- (length ScaleList) (length (member Scale ScaleList)))))
  )
  (defun SetScale ()
    (setq Scale (nth (atoi $value) ScaleList))
  )
  (setq ArchScales (list "1=1 (1)" "3/4=1 (1.3333)" "1/2=1 (2)"
    "3/8=1 (2.6667)" "1/4=1 or 3=12 (4)" "3/16=1 (5.3333)"
    "1/8=1 or 1 1/2=12 (8)" "3/32=1 (10.6667)" "1=12 (12)"
    "3/4=12 (16)" "1/2=12 (24)" "3/8=12 (32)" "1/4=12 (48)"
    "3/16=12 (64)" "1/8=12 (96)" "3/32=12 (128)"))
  (setq EngScales (list "1=10Ft (120)" "1=20Ft (240)" "1=30Ft (360)"
    "1=40Ft (480)" "1=50Ft (600)" "1=60Ft (720)" "1=70Ft (840)"
    "1=80Ft (960)" "1=90Ft (1080)" "1=100Ft (1200)"))
  (setq ScaleType "1");Default to Architectural Type
  (setq ScaleList ArchScales);Default to Architectural Scales
  (setq Scale (nth 0 ScaleList));Default to 1st scale in list
  (setq Dcl_Id (load_dialog "Border.dcl"))
  (new_dialog "Border" Dcl_Id)
  (set_tile "ScaleType" ScaleType)
  (start_list "ScaleList" 3)(mapcar 'add_list ScaleList)(end_list)
  (set_tile "ScaleList" (itoa (- (length ScaleList) (length (member Scale ScaleList)))))
  (action_tile "ScaleType" "(SetScaleType)");Have a subfunction do all the work
  (action_tile "ScaleList" "(SetScale)");Have a subfunction do all the work
  (setq Return (start_dialog))
  (unload_dialog Dcl_Id)
  (if (= Return 0) (exit))
  (setq RealScale (atof (substr Scale (+ 2 (vl-string-position (ascii "(") Scale)))))
  (princ "\nScale = ")(princ Scale)(princ ", RealScale = ")(princ RealScale)
  (princ)
)



Attachments  BorderProgram.gif  
I can't get it

#8

Seventhram
Join Date:
05-27-2008
OMG Bennett, you wouldnt believe how well that works, that is perfect, I merged that with the rest of my border program and its perfect.
 
What is very frustrating to me, the book I bought on Amazon talks nothing about doing these things. What book would you suggest that shows things like this.......pulling a list from a LISP program and using it in a DCL, then returning info from DCL back to the LISP.....got any suggestions on a good book??
 
Thank you very much for your help with this,
Seventhram
I can't get it

#9

Bennett
Join Date:
07-26-2007
Shouldn't you have named this thread "Yes, I can get it."?
 
A friend that I used to work with was fairly advance in AutoLISP. When he left the company we kept in contact via email. I asked him to help me with a similar border drawing setup routine with a dialog. I sent him what I had started and he emailed me back with the finished program. He mentioned in his email to never ever hard code your lists in your dialog code. I couldn't even find an example of what he was talking about, but it was in his program. You'll do someone else a favor someday too.
Bennett