Jump to content

Drop Down Help


rcb007

Recommended Posts

I am messing around with Afralisp Dialog Boxes and AutoLisp.

 

https://www.afralisp.net/dialog-control-language/tutorials/dialog-boxes-and-autolisp-part-2.php

 

With the following I am trying to figure where to add the Function or routine piece to the code. So when i select a Line from the drop down it will execute the command.

(For example, if I select "M16" and then ok. An Alert Box will show saying what it is M16 is selected.)

 

Thanks for any pointers.

 

Quote

(defun C:samp5 ()					;define function	
 
  (setq siz "M20")					;preset hole size
 
  (setq NAMES '("M6" "M8" "M10" "M12"
                "M16" "M20" "M24" "M30")		;define list
  );setq
 
  (setq dcl_id (load_dialog "samp5.dcl"))		;load dialog
 
  (if (not (new_dialog "samp5" 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
 
  (start_list "selections")				;start the list box
  (mapcar 'add_list NAMES)				;fill the list box
  (end_list)						;end list
 
  (action_tile "rb1" "(setq hole \"site\")")		;store hole type
  (action_tile "rb2" "(setq hole \"shop\")")		;store hole type
  (action_tile "rb3" "(setq hole \"hid\")")		;store hole type
  (action_tile "rb4" "(setq hole \"ctsk\")")		;store hole type
  (action_tile "rb5" "(setq hole \"elev\")")		;store hole type
  (action_tile "rb6" "(setq hole \"slot\")")		;store hole type
 
 
    (action_tile
    "cancel"						;if cancel button pressed
    "(done_dialog) (setq userclick nil)"		;close dialog, set flag
    );action_tile
 
  (action_tile
    "accept"						;if O.K. pressed
    (strcat						;string 'em together
      "(progn 
       (setq SIZ (atof (get_tile \"selections\")))"	;get list selection
      " (done_dialog)(setq userclick T))"		;close dialog, set flag
    );strcat
  );action tile
 
  (start_dialog)					;start dialog
 
  (unload_dialog dcl_id)				;unload
 
   (if userclick					;check O.K. was selected
    (progn
 
      (setq SIZ (fix SIZ))				;convert to integer
      (setq SIZ (nth SIZ NAMES))			;get the size
 
    );progn
 
  );if userclick
 
(princ)
 
);defun C:samp
 
(princ)

 

Link to comment
Share on other sites

This may be useful its a Library routine can use in any code will make a dcl on the fly for you. You would just run it twice the second time would be for hole type. I dont have it yet but an image version is possible. Same as 2 columns are on the wish list. Would just need 2 lists.

(if (not AH:Butts)(load "Multi radio buttons.lsp")) 		; loads the program if not loaded already
(if (not but)(setq but 1)) 				; this is needed to set default button
(setq siz  (ah:butts but "V"   '("Choose size " "  M8" "  M10" "  M12" "  M16" "  M20" "  M24")) )

(setq hole  (ah:butts but "V"   '("Choose size " "  SITE" "  SHOP" "  HID" "  CTSK" " ELEV" "  SLOT")) )

image.png.1d17266ae30f08c449901ba82b76db5f.png

 

Multi radio buttons.lsp

screenshot267.png

 

What you can do is loop through your keys RbX and check if clicked so return the item number of a list rather than checking each button individually, look at "BUT" so no need to hard code the do what as it will match a list that is passed to the routine. (nth but butlst) then use a cond.  Remove the (setq siz and last ) and look at (nth but  butlst)

Edited by BIGAL
Link to comment
Share on other sites

Interesting. Thank you for sharing that idea.

 

I was modifying the DCL to a shape that i think would work. I am hopeful that i would not need to modify the DCL anymore.

Within the Lisp, I am hoping that I could just modify the List Contents. That way, the List in the DCL will automatically read it from the lisp.

 

I am still trying to figure out how to activate a command when the user selects an option, then hits the OK button to execute it.

 

(defun C:samp5 ()					;define function	
 
  (setq siz "Site Plan")					;preset hole size
 
  (setq NAMES '("M6" "M8" "M10" "M12"
                "M16" "Site Plan" "M24" "M30")		;define list
  );setq
 
  (setq dcl_id (load_dialog "samp5.dcl"))		;load dialog
 
  (if (not (new_dialog "samp5" 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_list "selections")				;start the list box
  (mapcar 'add_list NAMES)				;fill the list box
  (end_list)						;end list
 
  (action_tile "list1" "(setq hole \"M6\")")		;store list type
  (action_tile "list2" "(setq hole \"M8\")")		;store list type
  (action_tile "list3" "(setq hole \"M10\")")		;store list type
  (action_tile "list4" "(setq hole \"M12\")")		;store list type
  (action_tile "list5" "(setq hole \"M16\")")		;store list type
  (action_tile "list6" "(setq hole \"Site Plan\")")	;store list type
  (action_tile "list6" "(setq hole \"M24\")")		;store list type 
  (action_tile "list6" "(setq hole \"M30\")")		;store list type

 
    (action_tile
    "cancel"						;if cancel button pressed
    "(done_dialog) (setq userclick nil)"		;close dialog, set flag
    );action_tile
 
  (action_tile
    "accept"						;if O.K. pressed
    (strcat						;string 'em together
      "(progn 
       (setq SIZ (atof (get_tile \"selections\")))"	;get list selection
      " (done_dialog)(setq userclick T))"		;close dialog, set flag
    );strcat
  );action tile
 
  (start_dialog)					;start dialog
 
  (unload_dialog dcl_id)				;unload
 
   (if userclick					;check O.K. was selected
    (progn
 
      											;;(setq SIZ (fix SIZ))				;convert to integer
      											;;(setq SIZ (nth SIZ NAMES))			;get the size
	(setq M6)
		(defun C:M6 ()
		(Alert "This is M6.")
		(princ))

	(setq M8)
		(defun C:M8 ()
		(Alert "This is M8.")
		(princ))

	(setq M10)
		(defun C:M10 ()
		(Alert "This is M10.")
		(princ))
	(setq M12)
		(defun C:M12 ()
		(Alert "This is M12.")
		(princ))
	(setq M16)
		(defun C:M16 ()
		(Alert "This is M16.")
		(princ))
	(setq Site Plan)
		(defun C:Site-Plan ()
		(Alert "This is Site Plan.")
		(princ))
	(setq M24)
		(defun C:M24 ()
		(Alert "This is M24.")
		(princ))
	(setq M30)
		(defun C:M30 ()
		(Alert "This is M30.")
		(princ))

 
    );progn
 
  );if userclick
 
(princ)
 
);defun C:samp
 
(princ)

 

Capture.JPG

Link to comment
Share on other sites


(defun C:samp5  ( / siz names dcl_id userclick drv hole )
  (setq siz "Site Plan") ;preset hole size
  (setq NAMES '("M6" "M8" "M10" "M12" "M16" "Site Plan" "M24" "M30")) ;define list
  (setq dcl_id (load_dialog "samp5.dcl")) ;load dialog
  (if (not (new_dialog "samp5" dcl_id))(exit)) ;test for dialog
  (setq w (dimx_tile "im") h (dimy_tile "im")) ;get image tile width / height
  (start_list "selections") ;start the list box
  (mapcar 'add_list NAMES) ;fill the list box
  (end_list) ;end list

  (action_tile "list1" "(setq hole \"M6\")") ;store list type
  (action_tile "list2" "(setq hole \"M8\")") ;store list type
  (action_tile "list3" "(setq hole \"M10\")") ;store list type
  (action_tile "list4" "(setq hole \"M12\")") ;store list type
  (action_tile "list5" "(setq hole \"M16\")") ;store list type
  (action_tile "list6" "(setq hole \"Site Plan\")") ;store list type
  (action_tile "list6" "(setq hole \"M24\")") ;store list type
  (action_tile "list6" "(setq hole \"M30\")") ;store list type

 

  (action_tile "selections" "(setq userclick $value)") ;<------ catch action from popup_list
 
  (action_tile "cancel" "(setq userclick nil)(done_dialog 0) ")
  (action_tile "accept" "(done_dialog 1)")
  (setq drv (start_dialog))
  (unload_dialog dcl_id) ;unload
  (if (and userclick (= drv 1)) (alert (nth (atoi userclick) names))) ;<---- if there was a userclick and user clicked ok use return value from popup_list as index
)

Link to comment
Share on other sites

Thank you, thank you. I placed the other routines within it and it works just like I was envisioning it too.

(defun C:samp5  ( / siz names dcl_id userclick drv hole )
  (setq siz "Site Plan") ;preset hole size
  (setq NAMES '("M6" "M8" "M10" "M12" "M16" "Site Plan" "M24" "M30")) ;define list
  (setq dcl_id (load_dialog "samp5.dcl")) ;load dialog
  (if (not (new_dialog "samp5" dcl_id))(exit)) ;test for dialog
  (setq w (dimx_tile "im") h (dimy_tile "im")) ;get image tile width / height
  (start_list "selections") ;start the list box
  (mapcar 'add_list NAMES) ;fill the list box
  (end_list) ;end list

  (action_tile "list1" "(setq hole \"M6\")") ;store list type
  (action_tile "list2" "(setq hole \"M8\")") ;store list type
  (action_tile "list3" "(setq hole \"M10\")") ;store list type
  (action_tile "list4" "(setq hole \"M12\")") ;store list type
  (action_tile "list5" "(setq hole \"M16\")") ;store list type
  (action_tile "list6" "(setq hole \"Site-Plan\")") ;store list type
  (action_tile "list6" "(setq hole \"M24\")") ;store list type
  (action_tile "list6" "(setq hole \"M30\")") ;store list type

  (action_tile "selections" "(setq userclick $value)") ;<------ catch action from popup_list
 
  (action_tile "cancel" "(setq userclick nil)(done_dialog 0) ")
  (action_tile "accept" "(done_dialog 1)")
  (setq drv (start_dialog))
  (unload_dialog dcl_id) ;unload
  (if (and userclick (= drv 1)) (alert (nth (atoi userclick) names))) ;<---- if there was a userclick and user clicked ok use return value from popup_list as index
)
(defun C:M6 ()
	(Alert "This is M6.")
(princ))

(defun C:M8 ()
	(Alert "This is M8.")
(princ))

(defun C:M10 ()
	(Alert "This is M10.")
(princ))

(defun C:M12 ()
	(Alert "This is M12.")
(princ))

(defun C:M16 ()
	(Alert "This is M16.")
(princ))

(defun C:Site-Plan ()
	(Alert "This is Site Plan.")
(princ))

(defun C:M24 ()
	(Alert "This is M24.")
(princ))

(defun C:M30 ()
	(Alert "This is M30.")
(princ))

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...