Jump to content

Standard scale of a viewport


dannywi77iams

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • dannywi77iams

    10

  • ReMark

    5

  • Lee Mac

    5

  • elfert

    2

Top Posters In This Topic

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Hippe013
Added (vl-load-com)
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by elfert
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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