Jump to content

Creating a field that displays twice the scale of my viewport


jimwithaj

Recommended Posts

Hi,

I have created a field that displays the (custom) scale of my viewport and in paperspace the drawing is sized A3. So my field says for example 1:1000 @ A3. Now, our drawings are also printed at A1 and I would like to create a field that scales my viewport scale by 2 and displays the custom scale equivalent. I.e for 1:1000 it would display 1:500.

I am new to fields and any ideas/suggestions will be greatly appreciated.

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    11

  • alanjt

    8

  • jimwithaj

    5

  • woodman78

    1

Give this a shot:

 

(defun c:VPortField (/ *error* DOC ENT OBJ PT UFLAG)
 (vl-load-com)
 ;; Lee Mac  ~  25.02.10

 (defun *error* (msg)
   (and UFlag (vla-EndUndoMark doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))
 

 (while
   (progn
     (setq ent (car (entsel "\nSelect Viewport to Retrieve Scale: ")))

     (cond (  (eq 'ENAME (type ent))

              (if (eq "AcDbViewport"
                      (vla-get-Objectname
                        (setq Obj (vlax-ename->vla-object ent))))

                (if (setq pt (getpoint "\nSelect Point for Field: "))
                  (progn                     
                    (setq uFlag
                           (not (vla-StartUndomark
                                  (setq doc
                                         (vla-get-ActiveDocument
                                           (vlax-get-acad-object)))))

                          pt (trans pt 1 0))

                    (vla-AddMText

                      (if (zerop (vla-get-ActiveSpace doc))
                        
                        (if (eq :vlax-true
                                (vla-get-mspace doc))

                          (vla-get-ModelSpace doc)
                          (vla-get-PaperSpace doc))

                        (vla-get-ModelSpace doc))

                      (vlax-3D-point pt) 0.

                      (strcat "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId "
                              
                              (itoa (vla-get-ObjectId obj))

                              ">%).CustomScale >% * 2.0 \\f \"1:%lu2%ct1%qf2816\">%"))

                    (setq uFlag (vla-EndUndomark doc))))
                
                (princ "\n** Object Must be a Viewport **"))))))
 (princ))
                      

                    

                  

                  

                  
                  

                  
                               

Link to comment
Share on other sites

Now that's a mouthful.

 

Give this a shot:

 

(defun c:VPortField (/ *error* DOC ENT OBJ PT UFLAG)
 (vl-load-com)
 ;; Lee Mac  ~  25.02.10

 (defun *error* (msg)
   (and UFlag (vla-EndUndoMark doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))
 

 (while
   (progn
     (setq ent (car (entsel "\nSelect Viewport to Retrieve Scale: ")))

     (cond (  (eq 'ENAME (type ent))

              (if (eq "AcDbViewport"
                      (vla-get-Objectname
                        (setq Obj (vlax-ename->vla-object ent))))

                (if (setq pt (getpoint "\nSelect Point for Field: "))
                  (progn                     
                    (setq uFlag
                           (not (vla-StartUndomark
                                  (setq doc
                                         (vla-get-ActiveDocument
                                           (vlax-get-acad-object)))))

                          pt (trans pt 1 0))

                    (vla-AddMText

                      (if (zerop (vla-get-ActiveSpace doc))
                        
                        (if (eq :vlax-true
                                (vla-get-mspace doc))

                          (vla-get-ModelSpace doc)
                          (vla-get-PaperSpace doc))

                        (vla-get-ModelSpace doc))

                      (vlax-3D-point pt) 0.

                      (strcat "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId "
                              
                              (itoa (vla-get-ObjectId obj))

                              ">%).CustomScale >% * 2.0 \\f \"1:%lu2%ct1%qf2816\">%"))

                    (setq uFlag (vla-EndUndomark doc))))
                
                (princ "\n** Object Must be a Viewport **"))))))
 (princ))
                      

                    

                  

                  

                  
                  

                  
                               

Link to comment
Share on other sites

Wow, it is a mouthful and thanks for the quick response. I didn't expect a reply so soon.

Unfortunately I'm not sure how to activate this.

This is what I was worried about. While there is nothing wrong with Lee's code, you should really explore how the actual field is created, not coded. You said you knew very little about Fields. Take this opportunity and learn to fish.

Link to comment
Share on other sites

Yes, I did thanks. I made one small change to it, to get it to work exactly how I wanted it to, as originally the value displayed didn't correspond to the value of my 'scale name' as opposed to the 1:# setting.

I.e. If my viewport scale name is at 1:1000, and using Autocad's object 'scale name' field returns a value of 1:1000. Using your lisp returned a value of 1:0.5. Similarly a 1:200 scale name returned a value of 1:0.1.

So all i had to do was multiply that last value by 1000 and everything then was tickety boo, so I changed your lisp multiplication value of 2 to 0.002 and it worked a treat.:D

Thanks again Lee Mac, this is exactly what I was after. :thumbsup:

 

(defun c:VPortField (/ *error* DOC ENT OBJ PT UFLAG)
 (vl-load-com)
 ;; Lee Mac  ~  25.02.10

 (defun *error* (msg)
   (and UFlag (vla-EndUndoMark doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))
 

 (while
   (progn
     (setq ent (car (entsel "\nSelect Viewport to Retrieve Scale: ")))

     (cond (  (eq 'ENAME (type ent))

              (if (eq "AcDbViewport"
                      (vla-get-Objectname
                        (setq Obj (vlax-ename->vla-object ent))))

                (if (setq pt (getpoint "\nSelect Point for Field: "))
                  (progn                     
                    (setq uFlag
                           (not (vla-StartUndomark
                                  (setq doc
                                         (vla-get-ActiveDocument
                                           (vlax-get-acad-object)))))

                          pt (trans pt 1 0))

                    (vla-AddMText

                      (if (zerop (vla-get-ActiveSpace doc))
                        
                        (if (eq :vlax-true
                                (vla-get-mspace doc))

                          (vla-get-ModelSpace doc)
                          (vla-get-PaperSpace doc))

                        (vla-get-ModelSpace doc))

                      (vlax-3D-point pt) 0.

                      (strcat "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId "
                              
                              (itoa (vla-get-ObjectId obj))

                              ">%).CustomScale >% * 0.002 \\f \"1:%lu2%ct1%qf2816\">%"))

                    (setq uFlag (vla-EndUndomark doc))))
                
                (princ "\n** Object Must be a Viewport **"))))))
 (princ))

Link to comment
Share on other sites

  • 1 month later...

Hi Lee Mac,

 

I have been using your lisp with reckless abandon and was wondering if you could tweak it a little bit for me and have it allow me to choose an object as well as a viewport.

 

Thanks in advance

Link to comment
Share on other sites

I have a field setup that uses the viewport scale and the plot scale to display the scale on the drawing. I have lisps that apply settings for printing in either A3 or A1 and as part of these they regen all and so the scale on the drawing changes because the plot scale changes. I have done the same for pdf and dwf.

 

I have also setup a bar on the title scale which is a length of 100mm on A1 but the dimensions change to 50mm when at A3. I think it works quite well.

 

I had a lot of help with the lisps from the guys on this forum.

Link to comment
Share on other sites

I have been using your lisp with reckless abandon and was wondering if you could tweak it a little bit for me and have it allow me to choose an object as well as a viewport.

 

Hi Jim,

 

I'm not sure I fully understand your request, the current code retrieves the Viewport Scale and places it in a Field, what would you want to retrieve from an object?

Link to comment
Share on other sites

  • 1 month later...

Hi Lee Mac,

If i have a viewport that is irregular, ie it started off as an irregular object and I defined it as an object going mview->object and selecting the object. Now when i run vportfield and select this viewport I get an error saying ** Object Must be a Viewport **

Cheers for you help

Link to comment
Share on other sites

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...