jimwithaj Posted February 25, 2010 Share Posted February 25, 2010 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. Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 25, 2010 Share Posted February 25, 2010 You can create an object field within a formula field. Look at the posted example. new block.dwg Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 25, 2010 Share Posted February 25, 2010 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)) Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 25, 2010 Share Posted February 25, 2010 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)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 25, 2010 Share Posted February 25, 2010 Now that's a mouthful. Indeedy Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 25, 2010 Share Posted February 25, 2010 Indeedy Doesn't teach him anything about fields, though. Tsk Tsk. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 25, 2010 Share Posted February 25, 2010 Doesn't teach him anything about fields, though. Tsk Tsk. But then I wouldn't've had the enjoyment of writing it Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 25, 2010 Share Posted February 25, 2010 But then I wouldn't've had the enjoyment of writing it Just busting your chops. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 25, 2010 Share Posted February 25, 2010 Just busting your chops. Hehe, I know Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 25, 2010 Share Posted February 25, 2010 jimwithaj, did you get things sorted? Quote Link to comment Share on other sites More sharing options...
jimwithaj Posted February 26, 2010 Author Share Posted February 26, 2010 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 26, 2010 Share Posted February 26, 2010 Read this: http://www.cadtutor.net/forum/showthread.php?t=1390 Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 26, 2010 Share Posted February 26, 2010 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 26, 2010 Share Posted February 26, 2010 Did you get it working in the end JimwithAj? Quote Link to comment Share on other sites More sharing options...
jimwithaj Posted February 28, 2010 Author Share Posted February 28, 2010 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. Thanks again Lee Mac, this is exactly what I was after. (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)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 28, 2010 Share Posted February 28, 2010 Excellent - glad it helps PS> Read this Quote Link to comment Share on other sites More sharing options...
jimwithaj Posted April 8, 2010 Author Share Posted April 8, 2010 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 Quote Link to comment Share on other sites More sharing options...
woodman78 Posted April 8, 2010 Share Posted April 8, 2010 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 8, 2010 Share Posted April 8, 2010 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? Quote Link to comment Share on other sites More sharing options...
jimwithaj Posted June 2, 2010 Author Share Posted June 2, 2010 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 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.