Matsui21 Posted March 9, 2012 Share Posted March 9, 2012 (edited) I am new to writing visual lisp routines, and i am trying to develop a routine that shows a dialog box for valves and then you can select one and hit ok and then it inserts the block that you selected. Below is what i have so far... Dcl file: BlockSelect : dialog { label = "Select block to insert"; : list_box { key = "list"; height = 10; width = 40; } ok_cancel; } lsp file: (Defun c:valve (/) (defun ChooseBlk (lst / dcl result blkname) (defun OKClicked (/ ) (setq result (get_tile "list")) (if (or (not result) (= result "")) (done_dialog 0) (progn (setq result (nth (atoi result) lst)) (done_dialog 1) ) ) ) (setq dcl (load_dialog "blksel.dcl")) (new_dialog "BlockSelect" dcl) (start_list "list" 3) (mapcar 'add_list lst) (end_list) (setq list (list "BALL" "BUTTERFLY" "CHECK")) (if blkname (progn ) (princ "Canceled by user") ) (action_tile "accept" "(OKClicked)") (action_tile "cancel" "(done_dialog 0)") (if (= 1 (start_dialog)) result nil ) ) any advise would be much appreciated! Thank you Edited March 9, 2012 by Matsui21 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 9, 2012 Share Posted March 9, 2012 Hi Matsui21, Welcome to CADTutor! Firstly, I would suggest that you read the Code Posting Guidlines and edit your post to format your code correctly. Concerning the program: are you writing the program specifically to learn LISP/DCL, because if not, I would recommend you use Tool Palettes for this task - they are very powerful and easy to use. Lee Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 9, 2012 Author Share Posted March 9, 2012 tool palettes would be fine...the only question i would have with using them is how do i make it to where other users can pull up the Palettes that i create? And then when a new version of AutoCAD is installed with those Palettes transfer? Thanks, Matt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 9, 2012 Share Posted March 9, 2012 how do i make it to where other users can pull up the Palettes that i create? And then when a new version of AutoCAD is installed with those Palettes transfer? You have the option to Import / Export the Tool Palettes that you create, although others may have a more streamlined solution. Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 9, 2012 Share Posted March 9, 2012 1. Create a toolpalettes directory on the server. 2. Change the toolpalettepath (in options or do it by code) on everyone's computer to one on server 3. Either make the folder "read only" or have IT remove write access to that folder from everyone except you (keep people from accidentally altering something or you losing work - last out gets priority). 4. Every time you make an update to the tool palettes, everyone else will see the additions. 5. ??? 6. Profit! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 9, 2012 Share Posted March 9, 2012 Nice one Alan Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 9, 2012 Share Posted March 9, 2012 Nice one Alan b/w ToolPalletes, the enterprise CUIx and a custom menu pulldown, I can easily streamline everything I need for every user in the office. Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 9, 2012 Author Share Posted March 9, 2012 Thanks Alan for the help on that! Here is my next question for you and Lee; not all users are on the same version of AutoCAD...are the palettes that i create going to be able to function on different versions? Thanks, Matt Quote Link to comment Share on other sites More sharing options...
alanjt Posted March 9, 2012 Share Posted March 9, 2012 Thanks Alan for the help on that!Here is my next question for you and Lee; not all users are on the same version of AutoCAD...are the palettes that i create going to be able to function on different versions? Thanks, Matt AFAIK, it shouldn't matter - very little has changed with Tool Palettes over the years. What version differences are we talking? Your biggest limitation with version differences will lie in lower versions not being able to utilize objects/procedures created in a newer version of CAD. Rule of thumb: if you have multiple versions of CAD to deal with and have to streamline blocks, etc., always make sure to create everything with the lowest used version of CAD. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 10, 2012 Share Posted March 10, 2012 A bit extra if you have your partial menu's on the server only and make a change to the mnu then next time others start Autocad they will automatically see the new menu, you do not have to go to their box and load. Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 13, 2012 Author Share Posted March 13, 2012 Good Morning All, i found out that the oldest version that is in use in our office is 2008 lt. I have made the tool palettes, but am still working on writing the lisp routines because more than half our office won't be able to use the tool palettes. I have gotten it to where the i can select a valve type and hit OK, and it will insert the block, but it will only insert the first one in the list. LSP code: (defun c:valve () (setq lst1 (list "GATE" "GLOBE" "BALL" "BUTTERFLY" "CHECK" "PLUG" "WAFER")) (setq dcl_id (load_dialog "blksel.dcl")) (if (not (new_dialog "blksel" dcl_id)) (progn (alert "the blksel.dcl file could not be loaded!") (exit) ) ) (start_list "lst1" 3) (mapcar 'add_list lst1) (end_list) (action_tile "accept" "(setq ddiag 2) (done_dialog)") (action_tile "cancel" "(setq ddiag 1) (done_dialog)") (start_dialog) (unload_dialog dcl_id) (setq sStr1(get_tile "lst1")) (if(= ddiag 1) (princ "\n block select cancelled!") ) (if(= ddiag 2) (if(= sStr1 "GATE")> (while (setq pt (getpoint "\nPick Insertion point.")) (command "-Insert" "GATEV" "_non" pt "" pause) )) (if(= sStr1 "GLOBE")> (while (setq pt (getpoint "\nPick Insertion point.")) (command "_Insert" "GLOBE" "_non" pt "" pause) )) ) (princ) ) any help would be awesome! Thanks, Matt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 13, 2012 Share Posted March 13, 2012 When used with a list_box / popup_list tile, get_tile will return a string containing a zero-based integer index indicating the item selected. Also I believe you will need to use get_tile before the dialog exits, i.e. in the "accept" action_tile statement. And remember to localise your variables! Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 13, 2012 Author Share Posted March 13, 2012 Hey Lee... so, i went away from the listbox and went to radio buttons instead but now i am getting *error: bad argument type: stringp nil* (defun saveVars( / choices choice1 choice2 choice3 choice4 choice5 choice6 choice7 choice8 choice9) (setq choices(get_tile "mylist")) (setq choice1(atoi(get_tile "gate"))) (setq choice2(atoi(get_tile "globe"))) (setq choice3(atoi(get_tile "ball"))) (setq choice4(atoi(get_tile "butterfly"))) (setq choice5(atoi(get_tile "check"))) (setq choice6(atoi(get_tile "plug"))) (setq choice7(atoi(get_tile "wafer"))) (setq choice8(atoi(get_tile "needle"))) (setq choice9(atoi(get_tile "angle relief"))) ) (defun ingate( / ) (command "-Insert" "GATEV" pause "" "0" pause) ) (defun inglobe( / ) (command "-Insert" "GLOBE" pause "" "0" pause) ) (defun c:valve ( / dcl_id ddiag) ;;(setq lst1 (list "GATE" "GLOBE" "BALL" "BUTTERFLY" "CHECK" "PLUG" "WAFER")) (setq dcl_id (load_dialog "blockSelect.dcl")) (if (not (new_dialog "blockSelect" dcl_id)) (progn (alert "the blockSelect.dcl file could not be loaded!") (exit) )) ;; (start_list "lst1" 3) ;; (mapcar 'add_list lst1) ;; (end_list) (action_tile "accept" "(setq ddiag 2) (saveVars) (done_dialog)") (action_tile "cancel" "(setq ddiag 1) (done_dialog)") (start_dialog) (unload_dialog dcl_id) (if(= ddiag 1) (princ "\n block select cancelled!") ) (if(= ddiag 2) (progn (cond ((= choice1 1)(ingate)) ((= choice2 1)(inglobe)) ) ) ) ) i have been looking all over to try and find some kind of solution, but i have no idea where the error is coming from. sorry for all the code posts...i am just trying to figure this out pretty quick. Thanks, Matt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 13, 2012 Share Posted March 13, 2012 (edited) so, i went away from the listbox and went to radio buttons instead but now i am getting *error: bad argument type: stringp nil* Personally, I would find list_box / popup_list tiles easier to manipulate for this task, though radio_button tiles could also be used. If you want to proceed with radio_button tiles, I would suggest setting a variable within the action_tile expression for each radio_button, then checking this single variable after the user has exited the dialog. Hence the action_tile statement might be something like: (action_tile "gate_radio_button_key" "(setq choice \"gate\")") This is the very reason that I state that list_box / popup_list tiles would be easier, since with radio_button tiles, you would require an action_tile statement for each tile; however, with either of the list style tiles, only a single action_tile statement is required to achieve the same result. Concerning your error, use the debugging utilities offered by the Visual LISP IDE to ascertain the source and cause of the error. I have written a short tutorial on this here. Edited March 13, 2012 by Lee Mac Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 14, 2012 Share Posted March 14, 2012 Did you know that you can have a Dialouge with images ? so you could have a 3x3 4x4 etc panel and pick an image rather than a name. Obviously the coding becomes a bit more complex. Its at home not here so can not post right now. Found a copy // DD4x3 dialogue. Used by // Called from the AutoCAD Release 12 Standard Menu. dd4x3: dialog { label = "Please choose item"; : column { : row { : image_button { key = "43sq1"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } : image_button { key = "43sq2"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } : image_button { key = "43sq3"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } : image_button { key = "43sq4"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } } : row { : image_button { key = "43sq5"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } : image_button { key = "43sq6"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } : image_button { key = "43sq7"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } : image_button { key = "43sq8"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } } :row { : image_button { key = "43sq9"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } : image_button { key = "43sq10"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } : image_button { key = "43sq11"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } : image_button { key = "43sq12"; width = 15; aspect_ratio = 1.0; color = graphics_background; allow_accept = true; } } } ok_cancel; } Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 14, 2012 Author Share Posted March 14, 2012 This may be a dumb question, but if you were to use buttons in the dialog box would it make it easier to code them to insert blocks? Thanks! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 14, 2012 Share Posted March 14, 2012 6 of one, half a dozen of the other Maybe you can get some inspiration from this program in which I created the Dialog interface for CAB's excellent program [ May require membership ] Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 14, 2012 Author Share Posted March 14, 2012 That is an incredible looking program...I still have a lot of learning to do before i can understand what is going on there completely. Can I ask a couple more questions... With using buttons on my dcl; would i need an action_tile for each button? and then how would i callup that buttons key to tell the routine to insert a certain block? Thanks! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 14, 2012 Share Posted March 14, 2012 That is an incredible looking program...I still have a lot of learning to do before i can understand what is going on there completely. Thanks! All credit to CAB, I just created/programmed the interface Can I ask a couple more questions...With using buttons on my dcl; would i need an action_tile for each button? and then how would i callup that buttons key to tell the routine to insert a certain block? Yes, since each button is an independent tile, without an action_tile statement for the tile there would be no way to evaluate a response when the user clicks the button. I would suggest using a done_dialog call in the action_tile statement of each button, using a different 'status' argument for each. Then read back the status value from the start_dialog call to determine which block to insert. Quote Link to comment Share on other sites More sharing options...
Matsui21 Posted March 14, 2012 Author Share Posted March 14, 2012 Is there somewhere on your site that gives an example of what that would look like? 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.