leonucadomi Posted 19 hours ago Posted 19 hours ago hello: I'm trying to make a routine that adds new scale to my viewports I want the routine to only ask me a scale number. example . 20 and it generated the scale 1:20 and so on for others I started with this code but something happens and it doesn't work (defun c:EVP3 (/ ESC ESC2) (setq old_err *error*)(defun *error* ( a / )(princ "") (setq *error* old_err)(princ)) (setvar "cmdecho" 0) (setq ESC (getreal "\nIndica la escala: ")) (setq ESC2 (strcat "1" ":" ESC)) (command "_-SCALELISTEDIT" "A" ESC2 ESC2 "E") (princ) );fin defun enlighten me masters ... please thanks Quote
mhupp Posted 17 hours ago Posted 17 hours ago (edited) Shout out to @alanjt for doing the heavy lifting here. This will generate a temp DCL Menu with a list provided and whatever you pick will change the scale accordingly. could be cleaned up a bit with error handling of making sure you selected a viewport or if your in an active viewport pick that one by default. ;;----------------------------------------------------------------------------;; ;; Generates DCL Menu for user to select a veiwport Scale (defun C:VPS () (C:VPSCALE)) (defun C:VPSCALE (/ lst vp) (vl-load-com) (setq Doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark Doc) (setq lst '("1:1" "1:5" "1:10" "1:15" "1:20" "1:30" "1:40" "1:50" "1:60" "1:70" "1:80" "1:90" "1:100")) ;update list how you see fit (if (setq vp (car (entsel "\nSelect viewport: "))) (progn (setq vp (vlax-ename->vla-object vp)) (setq scl (AT:ListSelect "Set Viewport Scale" "Pick A Scale" 30 60 "False" lst)) (setq X (atoi (substr scl 3))) (vla-put-CustomScale vp (/ 1.0 X)) (vla-Regen Doc acAllViewports) ;might not be needed (princ (strcat "\nViewport scale set to " scl)) ) ) (vla-endundomark Doc) (princ) ) ;;----------------------------------------------------------------------------;; ;; Function to Pick form list ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite) ;; (AT:ListSelect "Title" "Lable" Height Width "true/false multi select" lst) ;; some coding borrowed from http://www.jefferypsanders.com (thanks for the DCL examples) (defun AT:ListSelect (title label height width multi lst / fn fo d f) (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w")) (write-line (strcat "list_select : dialog { label = \"" title "\"; spacer;") fo) (write-line (strcat ": list_box { label = \"" label "\";" "key = \"lst\";") fo) (write-line (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";") fo) (write-line (strcat "width = " (vl-princ-to-string width) ";") fo) (write-line (strcat "multiple_select = " multi "; } spacer; ok_cancel; }") fo) (close fo) (new_dialog "list_select" (setq d (load_dialog fn))) (start_list "lst") (mapcar (function add_list) lst) (end_list) (setq item (set_tile "lst" "0")) (action_tile "lst" "(setq item $value)") (setq f (start_dialog)) (unload_dialog d) (vl-file-delete fn) (if (= f 1) ((lambda (s / i s l) (while (setq i (vl-string-search " " s)) (setq l (cons (nth (atoi (substr s 1 i)) lst) l)) (setq s (substr s (+ 2 i))) ) (reverse (cons (nth (atoi s) lst) l)) ) item ) ) ) -edit Set x as integer with atoi Edited 1 hour ago by mhupp 1 1 Quote
BIGAL Posted 11 hours ago Posted 11 hours ago (edited) Another using radio buttons. (if (not AH:Butts)(load "Multi Radio buttons.lsp")) (if (= but nil)(setq but 1)) (setq ans (ah:butts but "V" '("Choose a Scale" "1:10" "1:20" "1:50" "1:100" "1:200" "1:250" "1:500" "1:1000"))) ; ans holds the button picked as an integer value or Multi radio buttons.lsp Edited 11 hours ago by BIGAL 1 Quote
leonucadomi Posted 4 hours ago Author Posted 4 hours ago 12 hours ago, mhupp said: Shout out to @alanjt for doing the heavy lifting here. This will generate a temp DCL Menu with a list provided and whatever you pick will change the scale accordingly. could be cleaned up a bit with error handling of making sure you selected a viewport or if your in an active viewport pick that one by default. ;;----------------------------------------------------------------------------;; ;; Generates DCL Menu for user to select a veiwport Scale (defun C:VPS () (C:VPSCALE)) (defun C:VPSCALE (/ lst vp) (vl-load-com) (setq Doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark Doc) (setq lst '("1:1" "1:5" "1:10" "1:15" "1:20" "1:30" "1:40" "1:50" "1:60" "1:70" "1:80" "1:90" "1:100")) ;update list how you see fit (if (setq vp (car (entsel "\nSelect viewport: "))) (progn (setq vp (vlax-ename->vla-object vp) scl (AT:ListSelect "Set Viewport Scale" "Pick A Scale" 30 60 "False" lst) X (substr scl 3) ) (vla-put-CustomScale vp (/ 1.0 X)) (vla-Regen Doc acAllViewports) ;might not be needed (princ (strcat "\nViewport scale set to " scl)) ) ) (vla-endundomark Doc) (princ) ) ;;----------------------------------------------------------------------------;; ;; Function to Pick form list ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite) ;; (AT:ListSelect "Title" "Lable" Height Width "true/false multi select" lst) ;; some coding borrowed from http://www.jefferypsanders.com (thanks for the DCL examples) (defun AT:ListSelect (title label height width multi lst / fn fo d f) (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w")) (write-line (strcat "list_select : dialog { label = \"" title "\"; spacer;") fo) (write-line (strcat ": list_box { label = \"" label "\";" "key = \"lst\";") fo) (write-line (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";") fo) (write-line (strcat "width = " (vl-princ-to-string width) ";") fo) (write-line (strcat "multiple_select = " multi "; } spacer; ok_cancel; }") fo) (close fo) (new_dialog "list_select" (setq d (load_dialog fn))) (start_list "lst") (mapcar (function add_list) lst) (end_list) (setq item (set_tile "lst" "0")) (action_tile "lst" "(setq item $value)") (setq f (start_dialog)) (unload_dialog d) (vl-file-delete fn) (if (= f 1) ((lambda (s / i s l) (while (setq i (vl-string-search " " s)) (setq l (cons (nth (atoi (substr s 1 i)) lst) l)) (setq s (substr s (+ 2 i))) ) (reverse (cons (nth (atoi s) lst) l)) ) item ) ) ) Quote
mhupp Posted 1 hour ago Posted 1 hour ago oops forgot atoi to set X as an integer. in VBA you can just do math with strings if they are numbers "80" * 5 works the same as 80 * 5. not so much in lisp. 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.