mhy3sx Posted December 12 Posted December 12 Hi I am using a lisp code with DCL dialog incase to open some images with table data. The problem is that when i select the radio button and press Ok the dcl dialog close and open the image. I want to when I press ok open the image but not close the dialog because if I want to open two or tree images i have to load 2 or 3 times the lisp. Is any way to do this ? Here is a small sample of the code with only one image (defun C:test (/ shell dcl des dch filename) (defun *error* (msg) (if (and (= 'int (type dch)) (< 0 dch)) (unload_dialog dch) ) (if (= 'file (type des)) (close des) ) (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl) ) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) ) (princ (strcat "\nError: " msg)) ) (princ) ) ; end defun ;; Relocate this routine definition to before it is needed. (defun start_image-Renamed (filename /) ;; Renamed routine to not override built-in function (vl-load-com) (princ filename) (setq shell (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application" ) ) (vlax-invoke-method shell 'open filename) (vlax-release-object shell) ) ; end defun (cond ((not (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w") ) ; end setq ) ; end not (princ "\nUnable to open DCL for writing.") ) ((progn (foreach str '( "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}" "" "test : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"T E S T 1\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. ............................\";" " }" ; radio_button " }" ;end boxed_column " ok_only;" " }" ; end dialog ) ;end list (write-line str des) ) ; end foreach (setq des (close des) dch (load_dialog dcl) ) ; end setq (<= dch 0) ) (princ "\nUnable to load DCL file.") ) ((not (new_dialog "test" dch)) (princ "\nUnable to display 'test' dialog.") ) (t (set_tile "dcl" "test") ;; Add double backslashes for each backslash in the filepath (action_tile "radio_button01" "(setq filename \"C:\\\\file\\\\file2\\\\18.jpg\")") (action_tile "OK" (strcat ;; Added this function to allow commenting out the ;; start_image routine ;; call "(progn (done_dialog 1) " ;; (start_image filename) ;; Move this somewhere else ;; later in the ;; code " )" ) ) (setq dcl_Return (start_dialog)) ;; Save return code to a variable for later processing (if (= dcl_Return 1) ;; Check dcl return code (start_image-Renamed filename) ;; Run routine ) (unload_dialog dch) ;; Unload dialog from memory ) ) ; end cond ;; Relocated start_image routine definition to before it is needed. ;; Otherwise, it will be called but not ;; function. ); end defun Thanks Quote
rlx Posted December 12 Posted December 12 (edited) You're gona need to built a list with the filenames for all the images (with toggles / listbox) and the very last line in your code must be (foreach image image-list (attach / open / insert whatever ...)) some help here : https://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-10F5B2F6-5D84-4B60-8ED5-D0B3A2644275 (vl-load-com) (defun c:Example_ImageFile() ;; This example inserts a raster image and then finds the ;; ImageFile for the image. (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) ;; This example uses the "2d Projected Polylines.jpg" found in the Sample ;; directory. If you do not have the image, or if it is located ;; in a different directory, insert a valid path and name for the ;; imageName variable below. (setq insertionPoint (vlax-3d-point 5 5 0) imageName ".\\Sample\\VBA\\2d Projected Polylines.jpg" scalefactor 1 rotAngle (/ (* 0 3.141592) 180)) ;; Creates a raster image in model space (if (/= (findfile imageName) nil) (progn (setq modelSpace (vla-get-ModelSpace doc)) (setq raster (vla-AddRaster modelSpace (findfile imageName) insertionPoint scalefactor rotAngle)) (vla-ZoomExtents acadObj) ) (alert (strcat imageName " could not be found.")) ) ;; Find the current ImageFile (vla-Regen doc :vlax-true) (alert (strcat "The ImageFile is currently set to: " (vla-get-ImageFile raster))) ) Edited December 12 by rlx 1 Quote
mhy3sx Posted December 12 Author Posted December 12 Hi rlx. I dont want t o insert the images in autocad. I want to open in image viewer, but not close the dcl dialog. Thanks Quote
rlx Posted December 12 Posted December 12 (edited) that won't change my suggestion about building list and last line being (foreach image image-list (shellopen image)) , and maybe you even won't have to close dcl when using shellopen. Edited December 12 by rlx Quote
Steven P Posted December 12 Posted December 12 In your radio button action tile you should be able to put the open image function in there so when you change the radio button it will open, same as if it was in 'OK', or call a subroutine to do the processing you want. A lot of respect to the Dragon, and I think his plan might be better that you create a list of images to open, and on 'OK' close the dialogue and open the images at the end. If you open each on a radio button click the opened image will take the focus of your computer and you'll have to keep jumping back to CAD for the next image... it won't be as quick as you might think. Select them first and open them all at the end will be a quicker process. 1 Quote
rlx Posted December 12 Posted December 12 just a quicky , assuming you have or create C:\Temp\MyImages\ folder and dump a few jpg files there (or change folder in lisp file) ; returns T if no errors occurred during program execution (defun ShellOpen ( $f / it sh ) (if (and (not (void $f)) (setq $f (findfile $f)) (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))) (progn (setq it (vl-catch-all-apply 'vlax-invoke (list sh 'open $f)))(vlax-release-object sh)(not (vl-catch-all-error-p it))) (progn (prompt "\nShell application was unable to open file")(setq it nil)))) ;;; multiple from list (setq inp (mfl '("bak" "dwg" "pdf" "tif") '("dwg"))) ;;; added all / none buttons (defun mfl (%l %df / toggle set_all l f p d r) (setq l (mapcar '(lambda (x)(if (member x %df)(strcat "[X] " x)(strcat "[O] " x))) %l)) (defun toggle (v / s r)(if (eq (substr (setq r (nth (atoi v) l)) 2 1) "X")(setq s "[O] ")(setq s "[X] ")) (setq l (subst (strcat s (substr r 5)) r l))(start_list "lb")(mapcar 'add_list l)(end_list)) (defun set_all (i)(setq l (mapcar '(lambda (x)(if (eq i "1") (strcat "[X] " x) (strcat "[O] " x))) %l)) (start_list "lb")(mapcar 'add_list l)(end_list)) (and (setq p (open (setq f (vl-filename-mktemp ".dcl")) "w")) (princ (strcat "cfl:dialog{label=\"Choose\";:list_box {height=12;key=\"lb\";}" ":button{label=\"All\";key=\"bt_all\";}:button{label=\"None\";key=\"bt_none\";}ok_cancel;}") p) (not (setq p (close p)))(< 0 (setq d (load_dialog f)))(new_dialog "cfl" d) (progn (start_list "lb")(mapcar 'add_list l)(end_list) (action_tile "lb" "(toggle $value)") (action_tile "accept" "(setq r (get_tile \"lb\"))(done_dialog 1)") (action_tile "cancel" "(setq r nil)(done_dialog 0)") (action_tile "bt_all" "(set_all \"1\")")(action_tile "bt_none" "(set_all \"0\")") (start_dialog)(unload_dialog d)(vl-file-delete f))) (mapcar '(lambda (y)(substr y 5)) (vl-remove-if '(lambda (x)(eq (substr x 2 1) "O")) l)) ) (defun c:t1 ( / image-folder lst image-list) (setq image-folder "C:/Temp/MyImages/") (setq lst (vl-directory-files Image-folder "*.jpg")) (if (and (vl-consp lst) (setq image-list (mfl lst '()))) (foreach image image-list (ShellOpen (strcat image-folder image))) (alert (strcat "No images (jpg) in :\n " (vl-princ-to-string image-folder))) ) ) Quote
mhy3sx Posted December 12 Author Posted December 12 Hi rlx , I respect your help but the list of images is not what I am looking for. I hava allready set a dcl menu with a lot radio buttons with different leabel from the image names and is not possible to put all in one list, not help me and dont't work for me right now. The question is simple. Is any way to have DCL dialog and radio buttons and when I click OK open the image but not close the dcl dialog ? Thanks Quote
rlx Posted December 12 Posted December 12 sure , just like Steven P suggested , put action direct to radio_button (action_tile "radio-button01" "(shellopen filename)") but if you have multiple radio buttons you could maybe open the same file multiple times if button is activated multiple times. ShellOpen can run while dialog is active. Quote
BIGAL Posted December 12 Posted December 12 Have you thought about using a IMAGE dcl you should be able to click on the ones you want making a list behind the scenes, I have 2x2 3x3 4x4 images etc. 1 Quote
rlx Posted December 12 Posted December 12 you probably want something like this but without showing complete code or dialog we have to use our crystal ball (mine is broke so I used my wife's) (defun c:test (/ shell dcl des dch filename image-folder image-list) ; returns T if no errors occurred during program execution (defun ShellOpen ( $f / it sh ) (if (and (not (void $f)) (setq $f (findfile $f)) (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))) (progn (setq it (vl-catch-all-apply 'vlax-invoke (list sh 'open $f)))(vlax-release-object sh)(not (vl-catch-all-error-p it))) (progn (prompt "\nShell application was unable to open file")(setq it nil)))) (defun *error* (msg) (if (and (= 'int (type dch)) (< 0 dch)) (unload_dialog dch) ) (if (= 'file (type des)) (close des) ) (if (and (= 'str (type dcl)) (findfile dcl)) (vl-file-delete dcl) ) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")) image ) (princ (strcat "\nError: " msg)) ) (princ) ) ; end defun ;; Relocate this routine definition to before it is needed. (defun start_image-Renamed (filename /) ;; Renamed routine to not override built-in function (vl-load-com) (princ filename) (setq shell (vla-getinterfaceobject (vlax-get-acad-object) "Shell.Application" ) ) (vlax-invoke-method shell 'open filename) (vlax-release-object shell) ) ; end defun (cond ((not (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w") ) ; end setq ) ; end not (princ "\nUnable to open DCL for writing.") ) ((progn (foreach str '( "ed : edit_box { alignment = left; width = 20; edit_width = 10; fixed_width = true;}" "" "test : dialog { spacer; key = \"dcl\";" " : boxed_column { label = \"T E S T 1\"; height = 1.0;" " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button01\"; label = \"1. ............................\";" " }" ; radio_button " : radio_button { height = 1.0; width = 20; is_tab_stop = true;" " key = \"radio_button02\"; label = \"2. ............................\";" " }" ; radio_button " }" ;end boxed_column " ok_cancel;" " }" ; end dialog ) ;end list (write-line str des) ) ; end foreach (setq des (close des) dch (load_dialog dcl) ) ; end setq (<= dch 0) ) (princ "\nUnable to load DCL file.") ) ((not (new_dialog "test" dch)) (princ "\nUnable to display 'test' dialog.") ) (t (set_tile "dcl" "test") ;; Add double backslashes for each backslash in the filepath (action_tile "radio_button01" "(setq filename \"C:\\\\file\\\\file2\\\\18.jpg\")") (action_tile "radio_button02" "(setq filename \"C:\\\\file\\\\file2\\\\19.jpg\")") (action_tile "cancel" "(done_dialog)") ;;; (action_tile "accept" "(start_image-Renamed \"c:/temp/image1.jpg\")") (action_tile "accept" "(if (not (ShellOpen filename))(alert (strcat \"Unable to open \" (vl-princ-to-string filename))))") (setq dcl_Return (start_dialog)) ;; Save return code to a variable for later processing (if (= dcl_Return 1) ;; Check dcl return code (start_image-Renamed "c:/temp/image1.jpg") ;; Run routine ) (unload_dialog dch) ;; Unload dialog from memory ) ) ; end cond ;; Relocated start_image routine definition to before it is needed. ;; Otherwise, it will be called but not ;; function. ); end defun Quote
mhy3sx Posted December 12 Author Posted December 12 Hi rlx. Command: TEST Error: undefined function - VOID Perhaps ZWCAD not support VOID Thanks Quote
rlx Posted December 12 Posted December 12 darn , void again , didn't realize I used it here... just replace with null , should be good enough or else paste : (defun void (x) (or (eq x nil) (and (listp x)(not (vl-consp x))) (and (eq 'STR (type x)) (eq "" (vl-string-trim " \t\r\n" x))))) Quote
mhy3sx Posted December 13 Author Posted December 13 Hi rlx. I try the last changes and the code works. But the radio buttons I use stay selected. Is any whay wen I select ok to clear the selection (without close the DCL dialog) or add a reset button to clear the selections ? Thanks Quote
Steven P Posted December 13 Posted December 13 add a set_tile function to the action_tile for the radio button, setting the tile to 0 should clear it (think it is a number if below doesn't work try changing 0 to string \"0\" ) (action_tile "radio_button01" "(setq filename \"C:\\\\file\\\\file2\\\\18.jpg\")(set_tile \"radio_button01\" 0)") Quote
rlx Posted December 13 Posted December 13 Your dcl design is making less and less sense. Radio buttons are ment to be in a row or column and I get the feeling you are using them as buttons, You may look into combination of text_part for filename and button for shellopen and once button has fired use (mode_tile "MyButton" 1) to grey out / disable button. Also giving height and width to a radio button makes no sense at all. Quote
BIGAL Posted December 13 Posted December 13 Try this it uses toggle buttons so can be a on or off switch, the result is a list like this (1 1 0 0 1) the 1 means you picked it. You then match the list with your image name list, item number in list, if = 1 then item number in image list. Multi toggles.lsp 1 Quote
Recommended Posts
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.