Jump to content

Recommended Posts

Posted

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

Posted (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 by mhupp
  • Like 1
  • Thanks 1
Posted (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

 Multiradio18.png.9cd9acae68302cda3539bb0b2a4eb337.png

 

Multi radio buttons.lsp

 

Edited by BIGAL
  • Thanks 1
Posted
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
    )
  )
)

 

 

image.png.2cc69ac76f7bcd46372dbb6d80a492ec.png  :(

 

Posted

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.

 

 

 

  • Confused 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...