Lee Mac Posted March 14, 2012 Share Posted March 14, 2012 Is there somewhere on your site that gives an example of what that would look like? Not on my site, though in fact, the program that I linked you to uses this method - I construct the action_tile statements within a foreach loop. Lee Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 15, 2012 Author Share Posted March 15, 2012 okay...so i went in and tried to figure out the foreach with the action_tiles placed within it, but now when i run the routine it comes up with an *error: too many arguments* (defun doButton ( / ) (cond ((= 1) (command "Insert" "GATEV" pause "1" "1" "0")) ((= 2) (command "Insert" "GLOBE" pause "1" "1" "0")) ((= 3) (command "Insert" "BALL" pause "1" "1" "0")) ((= 4) (command "Insert" "BUTTERFLY" pause "1" "1" "0")) ((= 5) (command "Insert" "CHECK" pause "1" "1" "0")) ((= 6) (command "Insert" "PLUG" pause "1" "1" "0")) ((= 7) (command "Insert" "WAFER" pause "1" "1" "0")) ((= (command "Insert" "NEEDLE" pause "1" "1" "0")) ((= 9) (command "Insert" "GLOBE-CV" pause "1" "1" "0")) ) ) (defun c:blk ( / dcl_id) (setq dcl_id (load_dialog "valveblk.dcl")) (if (not (new_dialog "valveblk" dcl_id)) (progn (alert "the valveblk.dcl file could not be loaded!") (exit) ) ) (foreach "valveblk" (set_tile "valveblk") (get_tile "valveblk") (action_tile "GATE" "(done_dialog) (doButton 1)") (action_tile "GLOBE" "(done_dialog) (doButton 2)") (action_tile "BALL" "(done_dialog) (doButton 3)") (action_tile "BUTTERFLY" "(done_dialog) (doButton 4)") (action_tile "CHECK" "(done_dialog) (doButton 5)") (action_tile "PLUG" "(done_dialog) (doButton 6)") (action_tile "WAFER" "(done_dialog) (doButton 7)") (action_tile "NEEDLE" "(done_dialog) (doButton 8)") (action_tile "GLOBECV" "(done_dialog) (doButton 9)") ) (action_tile "cancel" "(done_dialog)") (action_tile "accept" "(done_dialog)") (start_dialog) (unload_dialog dcl_id) (princ) ) can you tell me if i am on the right track? Thanks! Matt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 15, 2012 Share Posted March 15, 2012 For the way that you have it, you don't need the foreach, since you have constructed each action_tile statement individually. You are receiving the error because you are passing the 'doButton' function an argument, when the function isn't defined to accept any arguments. Also, all of your COND statment test expressions will always return T, since there is only one argument in the '=' expression, so no comparision. You will need to have the 'doButton' function accept a single integer argument and test this argument in each of the test expressions. However, instead of using COND, you could just pass the doButton a string containing the name of the block to be inserted. Also, there is no need for: (set_tile "valveblk") (get_tile "valveblk") Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 15, 2012 Author Share Posted March 15, 2012 should done_dialog be after the function call? for example: (action_tile "GATE" "(done_dialog) (inga)") or (action_tile "GATE" "(inga) (done_dialog)") Thanks, Matt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 15, 2012 Share Posted March 15, 2012 No, you need to close the dialog before the user attempts to insert the block, so done_dialog needs to be called first. Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 15, 2012 Author Share Posted March 15, 2012 well, i got the error for the arguments fixed, but now when i run the routine and pick one of the buttons it locks up autocad... what would cause that to happen? sorry about all the questions... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 15, 2012 Share Posted March 15, 2012 well, i got the error for the arguments fixed, but now when i run the routine and pick one of the buttons it locks up autocad...what would cause that to happen? sorry about all the questions... Could you post your code as it stands? Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 15, 2012 Author Share Posted March 15, 2012 i changed it from the 'doButton' function to creating individual functions for each one. (defun inga() (command "Insert" "GATEV" "1" "1" "0") (princ) ) (defun ingl() (command "Insert" "GLOBE" "1" "1" "0") (princ) ) (defun inbl() (command "Insert" "BALL" "1" "1" "0") (princ) ) (defun inbf() (command "Insert" "BUTTERFLY" "1" "1" "0") (princ) ) (defun inck() (command "Insert" "CHECK" "1" "1" "0") (princ) ) (defun inpg() (command "Insert" "GATEV" "1" "1" "0") (princ) ) (defun inwr() (command "Insert" "GATEV" "1" "1" "0") (princ) ) (defun innd() (command "Insert" "GATEV" "1" "1" "0") (princ) ) (defun ingcv() (command "Insert" "GLOBE-CV" "1" "1" "0") (princ) ) (defun c:blk ( / dcl_id) (setq dcl_id (load_dialog "valveblk.dcl")) (if (not (new_dialog "valveblk" dcl_id)) (progn (alert "the valveblk.dcl file could not be loaded!") (exit) ) ) (action_tile "GATE" "(done_dialog) (inga)") (action_tile "GLOBE" "(done_dialog) (ingl)") (action_tile "BALL" "(done_dialog) (inbl)") (action_tile "BUTTERFLY" "(done_dialog) (inbf)") (action_tile "CHECK" "(done_dialog) (inck)") (action_tile "PLUG" "(done_dialog) (inpg)") (action_tile "WAFER" "(done_dialog) (inwr)") (action_tile "NEEDLE" "(done_dialog) (innd)") (action_tile "GLOBECV" "(done_dialog) (ingcv)") (action_tile "cancel" "(done_dialog)") (action_tile "accept" "(done_dialog)") (start_dialog) (unload_dialog dcl_id) (princ) ) Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 15, 2012 Author Share Posted March 15, 2012 here is the dcl as well... valveblk : dialog { label = "select block to insert"; key = "valves"; : column { : row { label = "valves"; : button { key = "GATE"; width = 5; height = 2; allow_accept = true; label ="GATE"; } : button { key = "GLOBE"; width = 5; height = 2; allow_accept = true; label ="GLOBE"; } : button { key = "Ball"; width = 5; height = 2; allow_accept = true; label ="BALL"; } : button { key = "BUTTERFLY"; width = 5; height = 2; allow_accept = true; label ="BUTTERFLY"; } : button { key = "CHECK"; width = 5; height = 2; allow_accept = true; label ="CHECK"; } : button { key = "PLUG"; width = 5; height = 2; allow_accept = true; label ="PLUG"; } : button { key = "WAFER"; width = 5; height = 2; allow_accept = true; label ="WAFER"; } : button { key = "NEEDLE"; width = 5; height = 2; allow_accept = true; label ="NEEDLE"; } } : row { label = "control valves"; key = "cv"; : button { key = "GLOBE CV"; width = 5; height = 2; allow_accept = true; label ="GLOBE CV"; } } } ok_cancel; } Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 15, 2012 Share Posted March 15, 2012 Sorry, I realise that you can't use a command call before the start_dialog is evaluated. Anyway, I've quickly rewritten your code, please study it carefully so that my time hasn't been wasted on this. DCL code (save this as "valveblk.dcl"): bt : button { width = 15; height = 2; fixed_width = true; fixed_height = true; } valveblk : dialog { label = "Select block to insert"; spacer; : boxed_column { label = "Valves"; : row { : column { : bt { key = "GATEV"; label ="GATE" ; } : bt { key = "GLOBE"; label ="GLOBE"; } : bt { key = "BALL" ; label = "BALL" ; } : bt { key = "BUTTERFLY" ; label = "B/FLY"; } } : column { : bt { key = "CHECK"; label = "CHECK"; } : bt { key = "PLUG" ; label = "PLUG" ; } : bt { key = "WAFER"; label = "WAFER"; } : bt { key = "NEEDLE"; label = "NEEDLE"; } } } spacer; } : boxed_column { label = "Control Valves"; : bt { key = "GLOBE-CV"; label = "GLOBE CV"; } spacer; } : bt { key = "accept"; label = "Cancel"; is_default = true; is_cancel = true; alignment = centered; } } LISP code: (defun c:blk ( / block id name ) (cond ( (<= (setq id (load_dialog "valveblk.dcl")) 0) (princ "\nDCL File not found.") ) ( (not (new_dialog "valveblk" id)) (princ "\nDialog could not be loaded.") ) ( t (foreach tile '("GATEV" "GLOBE" "BALL" "BUTTERFLY" "CHECK" "PLUG" "WAFER" "NEEDLE" "GLOBE-CV") (action_tile tile "(setq name $key) (done_dialog)") ) (start_dialog) (if name (if (or (tblsearch "BLOCK" (setq block name)) (setq block (findfile (strcat name ".dwg"))) ) (command "_.-insert" block "_S" 1.0 "_R" 0.0 pause) (princ (strcat "\nBlock: " name ".dwg could not be found.")) ) (princ "\n*Cancel*") ) ) ) (if (< 0 id) (unload_dialog id)) (princ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 16, 2012 Share Posted March 16, 2012 Great as usual Lee just a suggestion for matsui21 if you make the keys say P1 P2 P3 etc then you can quickly use the code again and again without having to change the lisp only the lable description which I am pretty sure can be variables and hence can match different block names. AlanJT has a real nice lisp method that writes the dcl code and hence you add a start part to what Lee has done but the lables are passed to the dcl from a list so could be anything valves bends taps depending on the first choice You just write a temporary dcl and then call it. ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite) calling lsp (AT:ListSelect "Set new surface style" "Select style" 10 10 "false" dcl generator ;; title - list box title ;; label - label for list box ;; height - height of box ;; width - width of box ;; multi - selection method ["true": multiple, "false": single] ;; lst - list of strings to place in list box ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite) (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w")) (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;") (strcat ": list_box { label = \"" label "\";" "key = \"lst\";") (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";") (strcat "width = " (vl-princ-to-string width) ";") (strcat "multiple_select = " multi "; } spacer; ok_cancel; }") ) (write-line x fo) ) (close fo) (new_dialog "list_select" (setq d (load_dialog fn))) (start_list "lst") Quote Link to comment Share on other sites More sharing options...
sachindkini Posted March 16, 2012 Share Posted March 16, 2012 Sorry, I realise that you can't use a command call before the start_dialog is evaluated. Anyway, I've quickly rewritten your code, please study it carefully so that my time hasn't been wasted on this. DCL code (save this as "valveblk.dcl"): bt : button { width = 15; height = 2; fixed_width = true; fixed_height = true; } valveblk : dialog { label = "Select block to insert"; spacer; : boxed_column { label = "Valves"; : row { : column { : bt { key = "GATEV"; label ="GATE" ; } : bt { key = "GLOBE"; label ="GLOBE"; } : bt { key = "BALL" ; label = "BALL" ; } : bt { key = "BUTTERFLY" ; label = "B/FLY"; } } : column { : bt { key = "CHECK"; label = "CHECK"; } : bt { key = "PLUG" ; label = "PLUG" ; } : bt { key = "WAFER"; label = "WAFER"; } : bt { key = "NEEDLE"; label = "NEEDLE"; } } } spacer; } : boxed_column { label = "Control Valves"; : bt { key = "GLOBE-CV"; label = "GLOBE CV"; } spacer; } : bt { key = "accept"; label = "Cancel"; is_default = true; is_cancel = true; alignment = centered; } } LISP code: (defun c:blk ( / block id name ) (cond ( (<= (setq id (load_dialog "valveblk.dcl")) 0) (princ "\nDCL File not found.") ) ( (not (new_dialog "valveblk" id)) (princ "\nDialog could not be loaded.") ) ( t (foreach tile '("GATEV" "GLOBE" "BALL" "BUTTERFLY" "CHECK" "PLUG" "WAFER" "NEEDLE" "GLOBE-CV") (action_tile tile "(setq name $key) (done_dialog)") ) (start_dialog) (if name (if (or (tblsearch "BLOCK" (setq block name)) (setq block (findfile (strcat name ".dwg"))) ) (command "_.-insert" block "_S" 1.0 "_R" 0.0 pause) (princ (strcat "\nBlock: " name ".dwg could not be found.")) ) (princ "\n*Cancel*") ) ) ) (if (< 0 id) (unload_dialog id)) (princ) ) Dear sir, Nice code can add sld file for preview Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 16, 2012 Share Posted March 16, 2012 Great as usual Lee just a suggestion for matsui21 if you make the keys say P1 P2 P3 etc then you can quickly use the code again and again without having to change the lisp only the lable description which I am pretty sure can be variables and hence can match different block names. AlanJT has a real nice lisp method that writes the dcl code and hence you add a start part to what Lee has done but the lables are passed to the dcl from a list so could be anything valves bends taps depending on the first choice You just write a temporary dcl and then call it. Thanks BIGAL To add to the mix, here is my version of a 'ListBox' function: http://lee-mac.com/listbox.html Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 16, 2012 Share Posted March 16, 2012 Dear sir, Nice code can add sld file for preview No, this was purely an example for 'Matsui21' to learn from. Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 16, 2012 Author Share Posted March 16, 2012 I definitely did learn from your example...so, believe me your time was not wasted at all! Thank you so much for your help as well! I realized that i was way off on what i had before hand... Thank you! Matt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 16, 2012 Share Posted March 16, 2012 You're welcome Matt, I'm glad you could benefit from my code. You weren't 'way off', since there are many ways that this could have been accomplished, I just coded it in a more concise manner. Quote Link to comment Share on other sites More sharing options...
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.