Jump to content

Get coords of extents of viewport in Model Space


Recommended Posts

Posted

I have a layout that we use for land maps for our mapping authority. I need to indicate the coords of the extent of the viewport but the coords need to be from the model space.

I was thinking of writing a lisp that would draw a rectang over the viewport, create a selection set with the rectang, move it to the model tab and then query the coords of the corners and input them into the fields.

Then if the view is changed the routine would delete the layer with the rectang on it and start the process again.

 

Is this way over the top? Is there another way to do this?

 

Thanks.

Land.jpg

Posted

Try the following quick program:

 

([color=BLUE]defun[/color] c:vprec ( [color=BLUE]/[/color] _text l j k p )
   ([color=BLUE]defun[/color] _text ( s p r j )
       ([color=BLUE]entmake[/color]
           ([color=BLUE]list[/color]
              '(0 . [color=MAROON]"TEXT"[/color])
               ([color=BLUE]cons[/color] 410 ([color=BLUE]getvar[/color] 'ctab))
               ([color=BLUE]cons[/color] 040 ([color=BLUE]getvar[/color] 'textsize))
               ([color=BLUE]cons[/color] 007 ([color=BLUE]getvar[/color] 'textstyle))
               ([color=BLUE]cons[/color] 010 p)
               ([color=BLUE]cons[/color] 011 p)
               ([color=BLUE]cons[/color] 001 s)
               ([color=BLUE]cons[/color] 050 r)
               ([color=BLUE]cons[/color] 072 j)
              '(73 . 2)
           )
       )
   )
   ([color=BLUE]cond[/color]
       (   ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'tilemode))
           ([color=BLUE]princ[/color] [color=MAROON]"\nCommand only available in Paperspace."[/color])
       )
       (   ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport))
           ([color=BLUE]princ[/color] [color=MAROON]"\nPlease activate a viewport."[/color])
       )
       (   ([color=BLUE]setq[/color] l  ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] ([color=BLUE]getvar[/color] 'cvport) ([color=BLUE]vports[/color])))
                 j '(2 0 2 0)
                 k '(2 0 0 2)
           )
           ([color=BLUE]foreach[/color] x ([color=BLUE]list[/color] ([color=BLUE]car[/color] l) ([color=BLUE]cadr[/color] l) ([color=BLUE]list[/color] ([color=BLUE]caadr[/color] l) ([color=BLUE]cadar[/color] l)) ([color=BLUE]list[/color] ([color=BLUE]caar[/color] l) ([color=BLUE]cadadr[/color] l)))
               ([color=BLUE]setq[/color] p ([color=BLUE]mapcar[/color] '[color=BLUE]rtos[/color] ([color=BLUE]trans[/color] ([color=BLUE]trans[/color] x 3 2) 2 0)))
               (_text ([color=BLUE]strcat[/color] [color=MAROON]"E:"[/color] ([color=BLUE]car[/color]  p)) x ([color=BLUE]/[/color] [color=BLUE]pi[/color] 2.0) ([color=BLUE]car[/color] j))
               (_text ([color=BLUE]strcat[/color] [color=MAROON]"N:"[/color] ([color=BLUE]cadr[/color] p)) x    0.0     ([color=BLUE]car[/color] k))
               ([color=BLUE]setq[/color] j ([color=BLUE]cdr[/color] j)
                     k ([color=BLUE]cdr[/color] k)
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Posted

Thanks LeeMac. That is excellent. There are 2 issues though.

The first is that if I run it more than once it overwrites the first text.

The second is the text height. I have tried to create a text style for this and set the height in that to 5 but the text keeps coming in at 2.5 even though the new style is set to current. What am I missing with this?

 

Thanks again...

Posted

LeeMac,

Just found the solution to the text height issue.

Thanks.

Posted
The first is that if I run it more than once it overwrites the first text.

 

Of course, it just creates the text.

 

The second is the text height. I have tried to create a text style for this and set the height in that to 5 but the text keeps coming in at 2.5 even though the new style is set to current. What am I missing with this?

 

The text height is sourced from the TEXTSIZE System Variable.

Posted

Thanks LeeMac, I got sorted on the text height and on the issue of overwriting. One other thing I forgot to ask and that is how I can limit the numbers to whole numbers without and decimal places..

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Rounding-Text-to-Less-Decimal-Places/td-p/2510232

As per this link the setting in your program seems to be set to 0 but it still gives 4 places of decimals....Am I reading this wrong?

Posted
One other thing I forgot to ask and that is how I can limit the numbers to whole numbers without and decimal places..

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Rounding-Text-to-Less-Decimal-Places/td-p/2510232

As per this link the setting in your program seems to be set to 0 but it still gives 4 places of decimals....Am I reading this wrong?

 

The current program uses your settings for LUNITS & LUPREC since rtos is being called without the unit or precision parameters.

To include these parameters, change:

 

([color=BLUE]setq[/color] p ([color=BLUE]mapcar[/color] '[color=BLUE]rtos[/color] ([color=BLUE]trans[/color] ([color=BLUE]trans[/color] x 3 2) 2 0)))

to:

(setq p (mapcar '(lambda ( x ) (rtos x [highlight]2[/highlight] [highlight]0[/highlight])) (trans (trans x 3 2) 2 0)))

I have highlighted the units & precision parameters.

Posted

Thanks LeeMac,

This is what I finished up with..

 

;;Written by LeeMac: Modified by Woodman78
(defun c:vprec ( / _text l j k p ECL ECC ECE )
	(setq ECL (getvar "clayer"))
(setq ECC (getvar "cecolor"))
(setq ECE (getvar "cmdecho"))
(setq Layoutname (getvar "ctab"))
	(setq combinedlayer (strcat "CCC_SHEET_LAYOUT_ITM_Coordinates_"layoutname))
(setvar "cecolor" "Bylayer")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(command "_.-layer" "_U" combinedlayer "")
(command "laydel" "N" combinedlayer "" "YES")
(command "_.-layer" "_N" combinedlayer "_M" combinedlayer "")
(command "_.-layer" "_U" combinedlayer "")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   (defun _text ( s p r j )
       (entmake
           (list
              '(0 . "TEXT")
               (cons 410 (getvar 'ctab))
               (cons 040 5)
               (cons 007 (getvar 'textstyle))
               (cons 010 p)
               (cons 011 p)
               (cons 001 s)
               (cons 050 r)
               (cons 072 j)
              '(73 . 2)
           )
       )
   )
   (cond
       (   (= 1 (getvar 'tilemode))
           (princ "\nCommand only available in Paperspace.")
       )
       (   (= 1 (getvar 'cvport))
           (princ "\nPlease activate a viewport.")
       )
       (   (setq l  (cdr (assoc (getvar 'cvport) (vports)))
                 j '(2 0 2 0)
                 k '(2 0 0 2)
           )
           (foreach x (list (car l) (cadr l) (list (caadr l) (cadar l)) (list (caar l) (cadadr l)))
               (setq p (mapcar '(lambda ( x ) (rtos x 2 0)) (trans (trans x 3 2) 2 0)))
               (_text (strcat "  E: " (car  p) " ") x (/ pi 2.0) (car j))
               (_text (strcat "  N: " (cadr p) " ") x    0.0     (car k))
               (setq j (cdr j)
                     k (cdr k)
               )
           )
       )
   )
 
(setvar "cecolor" ECC)
(setvar "clayer" ECL)
(command "_.-layer" "LO" combinedlayer "")
 (princ)
)

 

My additions are crude I know....but they do seem to work.

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