Author Topic: Assistance with code  (Read 1646 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Assistance with code
« on: August 24, 2014, 07:30:22 PM »
Hey guys,

I posted this a while back but I got no response.  I have come up with this bit of code that I need a little help with. I originally started this code from a sample from Afralisp to generate what I currently have. The problem I am experiencing is when the user selects the "Accept" button I need it to run a sub-function, the (InsDoor) which inserts doors based on the dialog selection and if the "Cancel" is pressed then exit the dialog and do nothing. Any help would be great.

Code: [Select]
(defun C:InsertDoor () ;define function
(setq DoorType "LH")
(setq DoorSize "3-0")
  (setq dcl_id (load_dialog "samp.dcl")) ;load dialog
  (if (not (new_dialog "samp" dcl_id) ;test for dialog
      );not
    (exit) ;exit if no dialog
  );if
  (setq w (dimx_tile "im") ;get image tile width
        h (dimy_tile "im") ;get image tile height
);setq
  (start_image "im") ;start the image
  (fill_image 0 0 w h 5) ;fill it with blue
  (end_image) ;end image
 ;added
    (mode_tile "rb1" 0)
    (mode_tile "rb2" 0)
    (mode_tile "rb3" 0)
    (mode_tile "rb4" 1)
    (mode_tile "rb5" 1)
    (mode_tile "rb6" 1)
    (mode_tile "selections" 0)
(drsizes)
 ;added 
(action_tile "rb1" "(setq DoorType \"LH\")(drsizes)")
(action_tile "rb2" "(setq DoorType \"RH\")(drsizes)")
(action_tile "rb3" "(setq DoorType \"DB\")(ddrsizes)")
(action_tile "rb4" "(setq DoorType \"BFD\")(drsizes)")
(action_tile "rb5" "(setq DoorType \"PD\")(drsizes)")
;(action_tile "rb6" "(setq DoorType \"VD\")(Vdrsizes)")
(action_tile "selections" "(setq Doorsize (nth (atoi $value) sizes))")
  (action_tile
    "accept" ;if O.K. pressed
    " (done_dialog)(setq userclick T)" ;close dialog
  );action tile
      (action_tile
      "cancel" ;if cancel button pressed
      "(done_dialog)(setq userclick nil)" ;close dialog
    );action_tile
  (start_dialog) ;start dialog
  (unload_dialog dcl_id) ;unload
(if (= userclick T)
         (InsDoor)
         (command)
)
(princ)
);defun C:InsertDoor


(defun InsDoor ()
(if (= T (wcmatch doorsize "V*"))
       (progn
       (setq drft (substr doorsize 2 1)
               drin (substr doorsize 4 2))
(setq cnt (strlen doorsize))
(setq zmath1 (* (atoi drft) 12))
(setq zmath2 (+ (atoi drin) zmath1))
(setq drsz (rtos zmath2 2 0))
(setq doorsize (strcat "08" (strcase DoorType) drsz "VD"))
(setvar "orthomode" 1)
(command ".-Insert" doorsize pause "" "")
       )
(progn
(setq drft (substr doorsize 1 1)
        drin (substr doorsize 3 2))
(setq cnt (strlen doorsize))
(setq zmath1 (* (atoi drft) 12))
(setq zmath2 (+ (atoi drin) zmath1))
(setq drsz (rtos zmath2 2 0))
(setq doorsize (strcat "08" (strcase DoorType) drsz "EX"))
(setvar "orthomode" 1)
(command ".-Insert" doorsize pause "" "")
)
)
(princ)
)

(defun drsizes ()
       (setq sizes '("1-6" "2-0" "2-2" "2-4" "2-6" "2-8" "2-10" "3-0" "3-2" "3-4" "3-6" "3-8" "3-10" "4-0" "V3-0" "V4-0")
                dcl:option "1")
      (start_list "selections")
      (mapcar 'add_list sizes)
      (end_list)
)
(defun ddrsizes ()
      (setq sizes '("4-0" "5-0" "5-4" "6-0" "7-0" "8-0")
               dcl:option "2")
      (start_list "selections")
      (mapcar 'add_list sizes)
      (end_list)
)

Code: [Select]
samp : dialog { //dialog name
      label = "Insert Door, version 1.0" ; //give it a label
 
       : row { //define row
 
  :boxed_radio_column{
        label = "Door Type" ;
         : radio_button {
        key = "rb1" ;
        label = "Left Hand Door" ;
        is_enabled = false;
        value = "1" ;
         }
      : radio_button {
        key = "rb2" ;
        label = "Right Hand Door" ;
        is_enabled = false;
      }
      : radio_button {
        key = "rb3" ;
        label = "Double Door" ;
        is_enabled = false;
        }
      : radio_button {
        key = "rb4" ;
        label = "Bifold" ;
        is_enabled = false;
        }
      : radio_button {
        key = "rb5" ;
        label = "Pocket" ;
        is_enabled = false;
        }
 }
         : boxed_column {
         label = "&Size";
      : popup_list {
         key = "selections";
         is_enabled = false;
        // value = "1" ;
         }
        }
 
 
       } //end row
 
 :spacer{
 width=4;
}
 
     ok_cancel ; //predifined OK/Cancel
 
     : row { //define row
 
     : image { //define image tile
     key = "im" ; //give it a name
     height = 1.0 ; //and a height
     width = 1.0 ; //and now a width
     } //end image
 
     : paragraph { //define paragraph
 
     : text_part { //define text
     label = "Designed and Created"; //give it some text
     } //end text
 
     : text_part { //define more text
     label = "by DV"; //some more text
     } //end text
     } //end paragraph
     } //end row
     } //end dialog

Any suggestions would be great.

Thanks,
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Assistance with code
« Reply #1 on: August 24, 2014, 07:35:32 PM »
Put the done_dialog last
Code: [Select]
      (action_tile
      "cancel" ;if cancel button pressed
      "(setq userclick nil)(done_dialog)" ;close dialog
    );action_tile
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Assistance with code
« Reply #2 on: August 24, 2014, 08:10:15 PM »
After a close look there were several problems.
Try this: (did not test insert)
Code: [Select]
(defun c:insertdoor () ;define function   
  (setq doortype "LH")
  (setq doorsize "3-0")
  (setq dcl_id (load_dialog "samp.dcl")) ;load dialog
  (if (not (new_dialog "samp" dcl_id) ;test for dialog
      ) ;not
    (exit) ;exit if no dialog
  ) ;if
  (setq w (dimx_tile "im") ;get image tile width
        h (dimy_tile "im") ;get image tile height
  ) ;setq
  (start_image "im") ;start the image
  (fill_image 0 0 w h 5) ;fill it with blue
  (end_image) ;end image
  (setq DoorType "LH")
  (set_tile "rb1" "1")
  (set_tile "rb2" "0")
  (set_tile "rb3" "0")
  (set_tile "rb4" "0")
  (set_tile "rb5" "0")
  (set_tile "rb6" "0")
  (set_tile "selections" "0")
  (drsizes)
  ;added 
  (action_tile "rb1" "(setq DoorType \"LH\")(drsizes)")
  (action_tile "rb2" "(setq DoorType \"RH\")(drsizes)")
  (action_tile "rb3" "(setq DoorType \"DB\")(ddrsizes)")
  (action_tile "rb4" "(setq DoorType \"BFD\")(drsizes)")
  (action_tile "rb5" "(setq DoorType \"PD\")(drsizes)")
  ;(action_tile "rb6" "(setq DoorType \"VD\")(Vdrsizes)")
  (action_tile "selections" "(setq Doorsize (nth (atoi $value) sizes))")
  (action_tile "accept" "(setq userclick T) (done_dialog)")
  (action_tile "cancel" "(setq userclick nil)(done_dialog)")
  (start_dialog) ;start dialog
  (unload_dialog dcl_id) ;unload
  (if userclick
    (insdoor)
  )
  (princ)
) ;defun C:InsertDoor


(defun insdoor ()
  (if (wcmatch doorsize "V*")
    (progn
      (setq drft (substr doorsize 2 1)
            drin (substr doorsize 4 2)
      )
      (setq cnt (strlen doorsize))
      (setq zmath1 (* (atoi drft) 12))
      (setq zmath2 (+ (atoi drin) zmath1))
      (setq drsz (rtos zmath2 2 0))
      (setq doorsize (strcat "08" (strcase doortype) drsz "VD"))
      (setvar "orthomode" 1)
      (command ".-Insert" doorsize pause "" "")
    )
    (progn
      (setq drft (substr doorsize 1 1)
            drin (substr doorsize 3 2)
      )
      (setq cnt (strlen doorsize))
      (setq zmath1 (* (atoi drft) 12))
      (setq zmath2 (+ (atoi drin) zmath1))
      (setq drsz (rtos zmath2 2 0))
      (setq doorsize (strcat "08" (strcase doortype) drsz "EX"))
      (setvar "orthomode" 1)
      (command ".-Insert" doorsize pause "" "")
    )
  )
  (princ)
)


(defun drsizes ()
       (setq sizes '("1-6" "2-0" "2-2" "2-4" "2-6" "2-8" "2-10" "3-0" "3-2" "3-4" "3-6" "3-8" "3-10" "4-0" "V3-0" "V4-0")
                dcl:option "1")
      (start_list "selections")
      (mapcar 'add_list sizes)
      (end_list)
  (set_tile "selections" "0")
)
(defun ddrsizes ()
      (setq sizes '("4-0" "5-0" "5-4" "6-0" "7-0" "8-0")
               dcl:option "2")
      (start_list "selections")
      (mapcar 'add_list sizes)
      (end_list)
  (set_tile "selections" "0")
)

Code: [Select]
samp : dialog {     label = "Insert Door, version 1.0" ;        //give it a label
 
  : row {                    //define row
 
    :boxed_radio_column{ label = "Door Type" ;
        : radio_button { key = "rb1" ; label = "Left Hand Door" ;}
          : radio_button { key = "rb2" ; label = "Right Hand Door" ;}
          : radio_button { key = "rb3" ; label = "Double Door" ; }
          : radio_button { key = "rb4" ; label = "Bifold" ; }
          : radio_button { key = "rb5" ; label = "Pocket" ; }
    }
    : boxed_column {  label = "&Size";
          : popup_list { key = "selections"; }
    }
 
 
  }                    //end row
 
  :spacer{ width=4;}
 
  ok_cancel ;                //predifined OK/Cancel
 
  : row {                    //define row
 
     : image {                    //define image tile
       key = "im" ;                //give it a name
       height = 1.0 ;                //and a height
       width = 1.0 ;                //and now a width
     }                        //end image
 
     : paragraph {                //define paragraph
 
     : text_part {                //define text
       label = "Designed and Created";        //give it some text
     }                        //end text
 
     : text_part {                //define more text
       label = "by DV";        //some more text
     }                        //end text
     }                        //end paragraph
   }                        //end row
}                        //end dialog
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Assistance with code
« Reply #3 on: August 24, 2014, 08:31:14 PM »
Quote
After a close look there were several problems.

I tested the revised code and you are a genius!. Many thanks Cab. I see the changes you made and have learned from it. I really appreciate it.

Thanks,
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Assistance with code
« Reply #4 on: August 24, 2014, 09:49:04 PM »
Glad to help.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.