dannywi77iams Posted February 10, 2012 Share Posted February 10, 2012 Hi all Can you help I what to be able to extract the scale from a viewport. When you look at the properties of a selected viewport there is a section called "standard scale" (1:50 or 1:100) is there a way of extracting this from a table. I know you can do a table search for blocks and anything else you wish but I'm having trouble with "standard scale". What I want to do is check for a viewport (the largest in the paper space) extract the "standard scale" (1:50) put this in to a string then use it for my title block. Can somebody point me on the right direction. My knowledge of lisp is basic and I do not know any of the "vl" code, any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
ReMark Posted February 10, 2012 Share Posted February 10, 2012 Maybe you could start with this viewport scale lisp routine by Jimmy Bergmark of JTB World fame. http://www.jtbworld.com/lisp/getvpscale.htm Quote Link to comment Share on other sites More sharing options...
dannywi77iams Posted February 10, 2012 Author Share Posted February 10, 2012 Thanks for the reply ReMark, But has I'm still learning lisp I don't know we're to start when it comes to the Code the starts with "vl". This just seem to confuses me. If you could point me to any basic lisp code that would help. Thanks again. Quote Link to comment Share on other sites More sharing options...
dannywi77iams Posted February 10, 2012 Author Share Posted February 10, 2012 If I can't find this though a table search is it possible to find this out though an assoc list??? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 10, 2012 Share Posted February 10, 2012 If you have the entity name of a Viewport, you can ascertain the scale by dividing the View Height in ModelSpace units (DXF Group Code 45) by the Height in PaperSpace Units (DXF Group Code 41), (reference here): (defun c:test ( / e ) (if (and (setq e (car (entsel))) (eq "VIEWPORT" (cdr (assoc 0 (setq e (entget e))))) ) (/ (cdr (assoc 45 e)) (cdr (assoc 41 e))) ) ) If you instead have a Viewport VLA-Object, retrieve the CustomScale property: (/ 1.0 (vla-get-customscale <VLA Viewport Object>)) However, for your task, I would instead insert a Field into your titleblock attribute, linked to the Custom Scale property of the Viewport. Quote Link to comment Share on other sites More sharing options...
Hippe013 Posted February 10, 2012 Share Posted February 10, 2012 (edited) Arggg!!!! Lee Mac beat me to it!!! Oh well... here is my version. (defun c:getviewportscale () ;vl-load-com allows you to use vl stuff (vl-load-com) ;Get the viewport object (setq obj (vlax-ename->vla-object (car (entsel)))) ;Get the viewport scale (setq vps (vlax-get-property obj 'CustomScale)) ;Get the inverse of the custom scale (setq inv-vps (/ 1 vps)) ;Then just put it into a string form (setq str (strcat "1\" = " (rtos inv-vps 2 0) "'")) ;Then do with str what ever you wish to do with it! (princ) ;Exit clean ) Edited February 10, 2012 by Hippe013 Added (vl-load-com) Quote Link to comment Share on other sites More sharing options...
elfert Posted February 10, 2012 Share Posted February 10, 2012 Hello Lee! I can't find the variable that you stores the scale is it e? I am asking because i want to make a routine that puts a detail view in model space from paper! thx. lee in advance. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 10, 2012 Share Posted February 10, 2012 I can't find the variable that you stores the scale is it e? There is no variable to store the scale value, the scale value is returned by the function (notice there is no 'princ' at the end of the code). The variable 'e' is the entity name, then the entity data. The function is merely an example however, demonstrating the method. Quote Link to comment Share on other sites More sharing options...
elfert Posted February 11, 2012 Share Posted February 11, 2012 (edited) There is no variable to store the scale value, the scale value is returned by the function (notice there is no 'princ' at the end of the code). The variable 'e' is the entity name, then the entity data. The function is merely an example however, demonstrating the method. Year could it be done ? The reason why i am asking is that i want to feed that scale to a text command and put it in model space while still standing i paper space. So i think about a routine that let the user choose the viewport, the viewport locks, the scale is storede for later use in a text command, the routine jumps in to the view port from paperspace, let the user choose where the text should be, the routine should put in a text with detail number or name + plus the scale, and jump out of the viewport again. The detail number could be automatically be counting every time its put into the views. In AutoCAD mec. The detailviews isn't good enough. And then why not put the text in ps Because we always put all the dimensions, text, leader ect. in ms. The only think we have in ps is the frame and drawing head. Edited February 11, 2012 by elfert Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 11, 2012 Share Posted February 11, 2012 Year could it be done? It has been done - the function shows how to ascertain the scale from the DXF Group codes. Quote Link to comment Share on other sites More sharing options...
dannywi77iams Posted February 11, 2012 Author Share Posted February 11, 2012 Mr Mac, I like the code you have supplied but is there away to check for the largest viewport in paperspace and set that as my value without selecting any viewports. I appreciate your time and effort and this will help me out a lot to understand what needs to be done in order to achieve this. Thanks Mac Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 11, 2012 Share Posted February 11, 2012 I like the code you have supplied but is there away to check for the largest viewport in paperspace and set that as my value without selecting any viewports. Yes, collect a selection set of all Viewports in Paperspace using the ssget function with the "_X" mode string with a filter list filtering for entity type (DXF Group 0) equal to VIEWPORT. Then, iterate through this selection set (there are many examples on the forum demonstrating how to do this, see here for some recently posted examples), then, for each Viewport entity you can determine the dimensions using the Viewport DXF Reference I linked you to in my earlier post. When you have the largest Viewport, use the method shown in the function I posted to determine the scale. Quote Link to comment Share on other sites More sharing options...
dannywi77iams Posted February 11, 2012 Author Share Posted February 11, 2012 What is a filter ans how do I go about writing a filter. That is something I'm not sure how to do. I really do have a small amount of LISP Programming. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 11, 2012 Share Posted February 11, 2012 What is a filter ans how do I go about writing a filter. That is something I'm not sure how to do. I really do have a small amount of LISP Programming. Read the following sections of the VLIDE Help Documentation: +-- AutoLISP Developer's Guide | +--+-- Using the AutoLISP Language | +--+-- Using AutoLISP to Manipulate AutoCAD Objects | +--+-- [b][color=red]Selection Set Handling[/color][/b] | +--+-- [b][color=red]Selection Set Filter Lists[/color][/b] | +-- [b][color=red]Wild-Card Patterns in Filter Lists[/color][/b] | +-- [b][color=red]Filtering for Extended Data[/color][/b] | +--[b][color=red] Relational Tests[/color][/b] | +--[b][color=red] Logical Grouping of Filter Tests[/color][/b] | +-- [b][color=red]Selection Set Manipulation[/color][/b] Quote Link to comment Share on other sites More sharing options...
dannywi77iams Posted February 16, 2012 Author Share Posted February 16, 2012 back again, I'm struggling with the "ssget" comand. I have searched everywhere, to find out how to grab everything associated with the viewport. Then when I have the selection set to find out what layer the viewports is on. I've read that you can use wild cards to find out. but i'm unsure if i'm placing them in the right part of the code. (setq vptest (ssget "x" (list (cons 0 "VIEWPORT"); my selection set for viewport entities (cons 8 "*") ;my wild card to find out what layer );list ) ) (setq vply (cdr(assoc 8 vptest))); my varible to find out which layer the viewport is on I'm not sure if this is the correct way to do this. The reason I want to find out which layer my viewport is on, is to switch this back on if it is frozen. What I'm also having trouble with is, how do I get to see whats is in your selection set. ie (0 = type of entity) (8 = Layer) and so on. all that comes up is "aa5f" when I do a "!vptest" Quote Link to comment Share on other sites More sharing options...
dober Posted February 16, 2012 Share Posted February 16, 2012 Expresstools VPSCALE Quote Link to comment Share on other sites More sharing options...
dannywi77iams Posted February 16, 2012 Author Share Posted February 16, 2012 That doesn't help dober Thanks anyway Quote Link to comment Share on other sites More sharing options...
ReMark Posted February 16, 2012 Share Posted February 16, 2012 VPSCALE A command that can only be used in paper space to ascertain the scale of a viewport. Type the command, hit Enter, pick the viewport then look at the command line. Example: Command: vpscale Select edge of viewport.1 found Command: PS:MS == 1:1.441 Quote Link to comment Share on other sites More sharing options...
dannywi77iams Posted February 16, 2012 Author Share Posted February 16, 2012 Never mind. It seems that what I want is not making any sence. I want to use lisp to find out what layer my viewports are on so that if there switched off or frozen the lisp will switch them on or un freeze the layer so that it can be selected. Quote Link to comment Share on other sites More sharing options...
ReMark Posted February 16, 2012 Share Posted February 16, 2012 Your viewports should go on their own unique layer and that layer, for obvious reasons, should be named either VPorts or Viewports. How easy is that to remember? BTW...the viewports layer should also be set to "no print" in the Layer Properties Manager so even if visible onscreen they do not plot. 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.