robbt Posted March 25, 2012 Posted March 25, 2012 new to the dialog boxes. Been trying a routine and failing. Can't figure out why. The routine opens the dialog, which should allow me to pick 1 out of 3 blocks to instert and to define the scale of the block, text to be inputed, and the text style to be used. The idea was planed to first define defaults for the dialog. Once the dialog is opened I could change or except the defaults. It should then insert the selected block and print the text. If the lisp file is executed a second time it should use the last values used as the defaults. So far all I can do is call up the dialog box, change my inputs or leave them as default, but once I select OK autocad locks up. here are the files: tree.dcl tree.lsp as a note, tree.lsp file in in c:/program files/autocad.../lispfile folder, which is called to in autocad. it is where all my lisp files are stored and autoloaded from. and the tree.dcl file is in the Express folder. I originally saved it in the Lispfile folder, but for some reason it would not load from there, but did load once I saved it to the Express folder. But now it crashed all the time. I even tried putting tree.lsp file in the Express folder, but did not change the results. Still crashed. Quote
MSasu Posted March 25, 2012 Posted March 25, 2012 You should move the command calls outside dialog actions (setvals function) - those aren't allowed while dialog is opened: (action_tile "accept" "(setvals) (done_dialog [color=red]1[/color])") [color=red](action_tile "cancel" "(done_dialog 0)")[/color] (start_dialog) [color=red](if (= (getvar "DIASTAT") 1) (command "insert" tree "s" tscl pause "" "text" "s" tts pause "" ttxt) )[/color] Regarding the access to DCL file you should either hard-code his path (see example below) or use a custom folder for your routines and add this to AutoCAD search path. I strongly recommend the second solution since is much flexible. Try to avoid placing your routines in Express or other system folders, you may lost them if need to re-install. (setq dcl_id (load_dialog "[color=red]C:\\MyLispTools\\[/color]tree.dcl")) Regards, Mircea Quote
Lee Mac Posted March 25, 2012 Posted March 25, 2012 Mircea, The 'DIASTAT' is returned by the start_dialog function, and the action_tile expression for the cancel tile is already defined (action_tile "accept" "(setvals) (done_dialog [color=red]1[/color])") [color=red](if (= [/color](start_dialog) [color=red]1) (command "_.-insert" tree "_s" tscl pause "" "_.text" "_s" tts pause "" ttxt) )[/color] Quote
Lee Mac Posted March 25, 2012 Posted March 25, 2012 robbt, I've rewritten your code to demonstrate how I might approach the task, hopefully you can learn from my code. (defun c:tree ( / blk id scl ts ) (cond ( (or (<= (setq id (load_dialog "tree.dcl")) 0) (not (new_dialog "tree" id)) ) (princ "\nDialog could not be Loaded.") ) ( t (set_tile (cond (*tree*) ((setq *tree* "pine"))) "1") (set_tile "scl" (cond (*scale*) ((setq *scale* "12.0")))) (set_tile "txt" (cond (*text* ) ((setq *text* "12\"")))) (set_tile "ts" (cond (*style*) ((setq *style* "Standard")))) (foreach tile '("pine" "oak" "juniper") (action_tile tile "(setq *tree* $key)") ) (action_tile "scl" "(setq *scale* $value)") (action_tile "txt" "(setq *text* $value)") (action_tile "ts" "(setq *style* $value)") (action_tile "accept" (vl-prin1-to-string '(cond ( (null (setq scl (distof *scale*))) (alert "Scale must be numerical!") (mode_tile "scl" 2) ) ( (null (tblsearch "STYLE" *style*)) (alert "TextStyle not found!") (mode_tile "ts" 2) ) ( (done_dialog 1)) ) ) ) (if (= 1 (start_dialog)) (if (or (tblsearch "BLOCK" (setq blk *tree*)) (setq blk (findfile (strcat *tree* ".dwg"))) ) (command "_.-insert" blk "_S" scl "_R" 0.0 pause "_.text" "_S" ts pause "" *text* ) (princ (strcat "\n" *tree* ".dwg not found.")) ) ) ) ) (if (< 0 id) (unload_dialog id)) (princ) ) The code is a little more concise and offers more error trapping, however, I haven't modified the 'business end' of the code too much (i.e. the Insert / Text section), but would advise that you look to use entmake / vla-addtext to create your text (or check the TextStyle text height) since the prompts for the Text command will vary depending on whether the TextStyle has zero text height set. I would also recommend using an *error* handler to unload the dialog should the user hit Esc whilst the dialog has focus; more information on how to do this can be found here. Quote
robbt Posted March 25, 2012 Author Posted March 25, 2012 First, thanks for the quick replies. Been trying the help. Still has bugs. Lee, I will try your suggested modified file. Looks simpler then my mess. I will also look into the *error* handler once it actually works. Thanks for that. Just for more help, the current file is shown below. Cancel does not work, the (if (= (start_dialog) 1) ( command...) gives me an malformed list error. I obviously have something wrong there. Still working on it. Again thank for the input (defun c:tree (/ dcl_id) (setq dcl_id (load_dialog "tree.dcl")) (if (not (new_dialog "tree" dcl_id)) (exit) ) (if (= loop nil)(setdef)(setdef2)) (action_tile "accept" "(setvals) (done_dialog 1)") (start_dialog) (princ "\nInsert Tree Point") (command "_.-insert" tree "s" tscl pause "") (Princ "\nPlacement of Text") (command "_.text" "s" tts pause "" ttxt) (princ) ) ;;; Sets defaults ;;; (defun setdef () (setq tree "pine" tscl 12 ttxt (strcat "12" (chr 34)) tts "DIM") (set_tile "pine" "1") (set_tile "scl" (rtos 12 2 0)) (set_tile "txt" (strcat "12" (chr 34))) (set_tile "ts" "DIM") (princ) ) ;;; ReDefine Defaults ;;; (defun setdef2 () (setq ttxt (strcat "12" (chr 34))) (if (= tree "pine")(set_tile "pine" "1")) (if (= tree "oak")(set_tile "oak" "1")) (if (= tree "juniper")(set_tile "juniper" "1")) (set_tile "scl" (rtos tscl 2 0)) (set_tile "txt" ttxt) (set_tile "ts" tts) (princ) ) ;;; Sets values and inserts ;;; (defun setvals () (action_tile "pine" "(setq tree $key)") (action_tile "oak" "(setq tree $key)") (action_tile "juniper" "(setq tree $key)") (setq tscl (atof (get_tile "scl"))) (setq ttxt (get_tile "txt")) (setq tts (get_tile "ts")) (setq loop 1) (princ) ) Quote
robbt Posted March 25, 2012 Author Posted March 25, 2012 Lee Just to let you know, you idea gives me "malformed list" error when I try to execute the lisp command. Back to the test board Quote
Lee Mac Posted March 25, 2012 Posted March 25, 2012 Just to let you know, you idea gives me "malformed list" error when I try to execute the lisp command. Which post are you referring to? A 'malformed list' error means you have one or more missing closing parentheses ")", I see no problems with the code I have posted. Quote
robbt Posted March 25, 2012 Author Posted March 25, 2012 I found the problem. When I copies the file I miss picking the last ")". But it is still not working. No error, just does not do anything. Have to look at it closer. As for now, I have to be somewhere, so I will be back testing a checking this site in a couple hours. Quote
MSasu Posted March 26, 2012 Posted March 26, 2012 Mircea,The 'DIASTAT' is returned by the start_dialog function, and the action_tile expression for the cancel tile is already defined Good remarks Lee, thank you! But you know, old habits die very hard. Regards, Mircea Quote
Lee Mac Posted March 26, 2012 Posted March 26, 2012 Good remarks Lee, thank you! But you know, old habits die very hard. ........ Quote
robbt Posted March 26, 2012 Author Posted March 26, 2012 I see the mentioning of useing "vl" and "vla" call in the lisp routine. I am uning Acad2006, I do not know if this version even knows about vl callouts. And I do not know anything about them. My books were printed back in Acad14. Yes I am out of date. Can anyone help me with these callouts. Quote
MSasu Posted March 26, 2012 Posted March 26, 2012 Those functions are part of VisualLISP extension which is available in version 2006; the LV-* functions are well covered in help; for VLA-* should search on Forum. Just don't forget to load this extension prior to use his functions: (vl-load-com) Regards, Mircea Quote
Lee Mac Posted March 27, 2012 Posted March 27, 2012 Visual LISP was introduced in AutoCAD2000 and should be available in all versions thereafter. @msasu: The vl-* functions do not need to be loaded using vl-load-com, only vla-* vlax-* and vlr-*; here is a thread demonstrating this. 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.