TheSwamp

CAD Forums => CAD General => Topic started by: ML on October 01, 2004, 06:07:01 PM

Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on October 01, 2004, 06:07:01 PM
OK,

This is a weird request but I do hope it is possible.

I created a macro that will copyclip a viewport out of paper and pasteclip it into Model scaled up at the respective scale in the macro. This is a cool way for me to define my limits to which I can draw in Model. For example, if I am going to plot at 1/4"=1' then I will have the viewport scale to a factor of 48 and so on.

Anyhow, this concept works great except one thing. In order to copy the viewport, you need to use copy and pasteclip.

My question is, is there a way to either explode that VP, copy it using AutoCAD's standard copy command or possibly convert it into some other geometry like a rectangle?

Hope there is an answer?

Thanks

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: danny on October 01, 2004, 06:44:10 PM
I use this
Code: [Select]
;draws Pspace / viewport Limits in Mspace on defpoints layer
               ;VPLIM.lsp draws the limits of a Paperspace Viewport Boundary in MODELSPACE
               ;VP - Get ViewPort object
               ;HT - Get Outside HeighT of Viewport
               ;WD - Get Oustide WiDth of Viewport
               ;VN - Get Viewport Number
               ;CTR - Get CenTeR of Viewport
               ;CTRX - Caluculate X of Viewport CenTeR
               ;CTRY - Caluculate Y of Viewport CenTeR
               ;VS - Get View Size of viewport
               ;XP - Calculate XP factor of viewport
               ;IW - Calculate Width of viewport
               ;BL - Calculate Bottom Left corner of viewport
               ;BR - Calculate Bottom Right corner of viewport
               ;TR - Calculate Top Right corner of viewport
               ;TL - Calculate Top Left corner of viewport
               ;PW - Save PlineWid
               ;OS - Save OSmode



               ;start function and define variables
(defun
     C:VPL
          (/ VP HT   WD VN CTR CTRX CTRY VS XP IW BL   BR TR TL PW OS)

               ;turn off command echoing
  (setvar "cmdecho" 0)

               ;save current layer as "clay"
  (setq clay (getvar 'clayer))

               ;make current layer defpoints
  (command "_.layer" "m" "Defpoints" "")

               ;enter pspace
  (command ".pspace")

               ;select viewport boundary
  (setq   VP
    (entget
      (car
        (entsel
          "\nSelect Viewport to Draw Boundary
             in "
        ) ;_ end of entsel
      ) ;_ end of car
    ) ;_ end of entget
  ) ;_ end of setq

               ;Get Viewport height with
  (setq HT (cdr (assoc 41 VP)))

               ;Get Viewport width with
  (setq WD (cdr (assoc 40 VP)))

               ;Get Viewport Number
  (setq VN (cdr (assoc 69 VP)))

               ;enter mspace
  (command ".mspace")

               ;set correct viewport
  (setvar "cvport" VN)

               ;set UCS to View
  (command ".ucs" "v")

               ;Get VIEWCTR store as CTR
  (setq CTR (getvar "viewctr"))

               ;Get X of CTR
  (setq CTRX (car CTR))

               ;Get Y of CTR
  (setq CTRY (cadr CTR))

               ;Get inside Viewport height
  (setq VS (getvar "viewsize"))

               ;Get XP Factor with HeighT / View Size
  (setq XP (/ HT VS))

               ;Get inside width of Viewport by
  (setq IW (* (/ VS HT) WD))

               ;Find four corners of Viewport
  (setq BL (list (- CTRX (/ IW 2)) (- CTRY (/ VS 2))))

  (setq BR (list (+ CTRX (/ IW 2)) (- CTRY (/ VS 2))))

  (setq TR (list (+ CTRX (/ IW 2)) (+ CTRY (/ VS 2))))

  (setq TL (list (- CTRX (/ IW 2)) (+ CTRY (/ VS 2))))

               ;Save current pline width
  (setq PW (getvar "plinewid"))

               ;Set Pline width to zero
  (setvar "plinewid" 0)

               ;Save current osmode
  (setq OS (getvar "osmode"))

               ;Draw pline inside border
  (command ".pline" BL BR TR TL "c")

               ;Restore pline width back
  (setvar "plinewid" PW)

               ;Restore UCS back
  (command ".ucs" "p")

               ;Restore osmode
  (setvar "osmode" OS)

               ;Restore curernt layer
  (setvar "clayer" clay)

               ;Clean up command prompt
  (princ)

               ;Go Back To Papserspace
  (command ".pspace")

)
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on October 01, 2004, 06:54:53 PM
LOL

Hey Danny,

I really do appreciate it but Iwas looking for something real simple.
I know some VBA and a very little Lisp but the people I work with want it nice and easy. I guess I am looking ffor a way without going to code


Thanks

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 15, 2004, 10:22:24 PM
Maybe I don't understand the problem, but I just activate the viewport and draw a rectangle
in model space the size of the viewport.  :?:
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: Serge J. Gianolla on November 15, 2004, 11:04:29 PM
Ciao CAB, how's things? If I understand his issue [that remains to be seen!!  :D ], the problem with copy'nPasting a viewport in MS means that this is still a viewport - though it looks like a rectangle. Incidentally, for users who want a rectangle acting like a rectangle as opposed to a de facto polyline, this is the way to go around AutoCAD's limitation: Make a viewport in PS, cut'nPaste in MS, then have fun with changeProperties to edit width and height!
Sorry for digressing Mark, I remember seeing in dim past, a lisp routine for rel14 that was "imprinting the viewport in MS [in other word creating the exact rectangle in MS] but was limited to rectangular viewports - obviously because polygonal viewports came with 2000. Do some google search, I'll try to find it in my ever increasing bricabrac!
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CADaver on November 16, 2004, 07:54:18 AM
Draw a rectangle in PS on top of the viewport then use CHSPACE out of Express Tools.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 16, 2004, 09:04:24 AM
Quote from: CADaver
Draw a rectangle in PS on top of the viewport then use CHSPACE out of Express Tools.

Could it be that easy?
Wow, Thanks CADaver. :shock:

Hay Serge, good to see you...
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 16, 2004, 09:06:52 AM
I am curently working my way through VBA
Eventually I will just be able to write whatever comes to mind.

For now, I still cling to plain old menu macros to a large degree and I don't know much about LISP, otherwise I would just tweak a few routines I have seen

Serge, you did nail the problem of the head. I don't mind the block reference in Model (as long as no one explodes it) but inevitably someone will explode it. Also, note that you can not copy viewports in Model. My Viewport is on Defpoints and color blue, I wanted it to be green after pasted to Modelspace

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CADaver on November 16, 2004, 10:51:01 AM
Quote from: CAB
Quote from: CADaver
Draw a rectangle in PS on top of the viewport then use CHSPACE out of Express Tools.

Could it be that easy?
Wow, Thanks CADaver. :shock:



Button macro:
Code: [Select]
^C^Cpspace;-layer;m;defpoints;;rectang;end;\end;\chspace;l;;
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 16, 2004, 11:53:39 AM
LOL, I didn't try it yet!  :)
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 16, 2004, 12:01:57 PM
Ok, that is a real cool macro BUT
I would still prefer to click on the viewport and have it make a polyline in MSPACE for me.

Or if I can pick the viewport and it then creates the PL in Model for me scaled up.

I don't want to get into picking points for this one. I think it will discourage people from using it.

I amy be able to follow that same macro principal and acheive it

Anymore suggestions?

Thank you

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CADaver on November 16, 2004, 12:42:47 PM
Lesee...

Group codes
10 is the PS viewport center
40 is the PS viewport width
41 is the PS viewport height
45 is the MS viewport width

The viewport scale would be group_41 / group_45

Looks do-able in lisp. What am I missing?
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: daron on November 16, 2004, 02:27:14 PM
The fact that he only desires to know vba. I think you still need those group code for vba too. I could be wrong, though.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CADaver on November 16, 2004, 03:12:12 PM
Quote from: Daron
The fact that he only desires to know vba. I think you still need those group code for vba too. I could be wrong, though.


ah, missed that.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: Serge J. Gianolla on November 16, 2004, 06:20:29 PM
Quote

 Also, note that you can not copy viewports in Model.

Correct Mark, but if you cut'nPaste as a block then it can be copied, mirrored, arrayed... and then they can be exploded to viewports. The viewport itself cannot be exploded to its primitives.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 16, 2004, 06:21:20 PM
My reply to that would be no and no.
I don't only desire to know VBA, the fact is that it is enough to be learning VBA, not only as it relates to AutoCAD but as it relates to Excel also.

My work wants me to possibly take a VB course which would be cool and I need to learn how to desire security systems that span across the entire country.

So, in short, I would love to learn LISP as well, I just don't know when and how. Also, I am not sure of the approach for this in VBA as I am still only 6 months into my learning and if I did know, I am not sure that I would spend the time to figure it out. Too many fish to fry :)

I was merely hoping that someone would have a simple answer to my original question

Thank you again

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 16, 2004, 06:25:49 PM
Quote

Correct Mark, but if you cut'nPaste as a block then it can be copied, mirrored, arrayed... and then they can be exploded to viewports. The viewport itself cannot be exploded to its primitives.



That's correct Serge

This is why I used Paste Block "BUT" I still have the original problem.
I want the pasted block (which is on defpoints) to be green while the layer defpoints is blue.

Thank you

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CADaver on November 17, 2004, 09:13:04 AM
Quote from: ML
I was merely hoping that someone would have a simple answer to my


The simple answer is the button macro posted previously.  You also wish to make it complicated by adding sevaeral other parameters to the original question.  The more complicated the problem, the more complicated the solution.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 17, 2004, 11:20:56 AM
Yes, this is true but I have to say to myself, my existing macro that I created does X,Y + Z but these macros that people are offering are real nice but they only do X+Y of what I need. So, it isn't really a solution, it is a solution that keeps me saying, well, where is the rest of the answer.

That is the funny things in here, Sometimes you can be as specific as possible, I need it to do "this" but you get a whole bunch of answers that don't address just that.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ELOQUINTET on November 17, 2004, 12:09:30 PM
check this out ml

http://www.cadnovation.com/en/Prod/mvport/mvport.asp
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CADaver on November 17, 2004, 12:48:47 PM
Quote from: ML
Yes, this is true but I have to say to myself, my existing macro that I created does X,Y + Z but these macros that people are offering are real nice but they only do X+Y of what I need. So, it isn't really a solution, it is a solution that keeps me saying, well, where is the rest of the answer.

That is the funny things in here, Sometimes you can be as specific as possible, I need it to do "this" but you get a whole bunch of answers that don't address just that.


Well now I'm insulted.  Specific my keester, go back and read your bloody posts, every one added a new feature or a new desire to the question, and each time you wanted it simple.  What you're really asking is for someone to read your mind and then provide you with the program desired. You've been given enough information to bang out exactly what you need, but you haven't the time for that, then you have the gonads to throw out a comment like that.

BTW, DW, this is the first post you said anything about "Z", if you'd have checked the button macro previously posted, you'd have noticed it matched the viewport's orientation, including "Z".
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ELOQUINTET on November 17, 2004, 01:01:10 PM
i'm not sure he was talking axis cadaver. take it easy cadaver don't take everything so personal it's just autocad  :roll:
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CADaver on November 17, 2004, 01:22:53 PM
Quote from: eloquintet
i'm not sure he was talking axis cadaver. take it easy cadaver don't take everything so personal it's just autocad  :roll:
This isn't his first time to post thinly-veiled insults when his un-posted needs weren't specifically met.  And when I need someone to tell me to "take it easy" I'll be sure to ask.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ELOQUINTET on November 17, 2004, 01:35:28 PM
i know we have personality conflicts. i don't see anyone else feeling insulted maybe it's time to look within at why this offends you rather than lashin out at others. i think we're all friends here and i wouldn't intentionally try to hurt anybody let's keep this fun is all i'm saying smile :lol:
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 17, 2004, 02:07:56 PM
Mark
Why don't you post your macro?
All you are looking for is to change the copied object to a pline, right?
Perhaps someone cod add that to YOUR macro?
Let's see it.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 17, 2004, 02:19:15 PM
Just a little research and I found this:
Code: [Select]
;;; vp-outline.lsp
;;;
;;; Creates a polyline in modelspace that
;;; has the outline of the selected viewport.
;;; Supports clipped viewports.
;;; If vp-outline is called when in mspace it detects
;;; the active viewport.
;;;
;;; c:vp-outline
;;;
;;; By Jimmy Bergmark
;;; Copyright (C) 1997-2003 JTB World, All Rights Reserved
;;; Website: www.jtbworld.com / http://jtbworld.vze.com
;;; E-mail: info@jtbworld.com / jtbworld@hotmail.com
;;;
;;; 2000-04-10
;;;
;;; Tested on AutoCAD 2000
;;; To do: support for drawing the outline in other ucs/view than world/current

(defun dxf (n ed) (cdr (assoc n ed)))

(defun ax:List->VariantArray (lst)
  (vlax-Make-Variant
    (vlax-SafeArray-Fill
      (vlax-Make-SafeArray
        vlax-vbDouble
        (cons 0 (- (length lst) 1))
      )
      lst
    )
  )
)

(defun c:vp-outline (/ ad ss ent pl plist xy n vpbl vpur msbl msur ven vpno ok)
  (setq ad (vla-get-activedocument (vlax-get-acad-object)))
  (if (= (getvar "tilemode") 0)
    (progn
      (if (= (getvar "cvport") 1)
        (progn
          (if (setq ss (ssget ":E:S" '((0 . "VIEWPORT"))))
            (progn
              (setq ent (ssname ss 0))
              (setq vpno (dxf 69 (entget ent)))
              (vla-Display (vlax-ename->vla-object ent) :vlax-true)
              (vla-put-mspace ad :vlax-true) ; equal (command "._mspace")
              ; this to ensure trans later is working on correct viewport
              (setvar "cvport" vpno)
              (vla-put-mspace ad :vlax-false) ; equal (command "._pspace")
              (setq ok T)
            )
          )
        )
        (setq ent (vlax-vla-object->ename (vla-get-activepviewport ad))
              ok T
        )
      )
      (if ok
        (progn
          (setq ven (vlax-ename->vla-object ent))
          (if (/= 1 (logand 1 (dxf 90 (entget ent)))) ; detect perspective
            (if (= (vla-get-clipped ven) :vlax-false)
               (progn ; not clipped
                 (vla-getboundingbox ven 'vpbl 'vpur)
                 (setq msbl (trans (vlax-safearray->list vpbl) 3 2)
                       msur (trans (vlax-safearray->list vpur) 3 2)
                       plist (list (car msbl) (cadr msbl)
                                   (car msur) (cadr msbl)
                                   (car msur) (cadr msur)
                                   (car msbl) (cadr msur)
                             )
                 )
               )
               (progn ; clipped
                 (setq pl (entget (dxf 340 (entget ent)))
                       plist (vla-get-coordinates
                               (vlax-ename->vla-object (dxf -1 pl))
                             )
                       plist (vlax-safearray->list (vlax-variant-value plist))
                       n 0
                       pl nil
                 )
                 (repeat (/ (length plist) 2)
                   (setq xy (trans (list (nth n plist) (nth (1+ n) plist)) 3 2)
                         pl (cons (car xy) pl)
                         pl (cons (cadr xy) pl)
                         n (+ n 2)
                   )
                 )
                 (setq plist (reverse pl))
               )
            )
          )
          (setq plist (ax:List->VariantArray plist))
          (vla-Put-Closed
            (vla-AddLightWeightPolyline
              (vla-get-ModelSpace ad)
              plist
            )
            :vlax-True
          )
        )
      )
    )
  )
  (princ)
)
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ELOQUINTET on November 17, 2004, 04:16:27 PM
is that similar to the vplim routine posted already or no cab?
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ronjonp on November 17, 2004, 04:44:43 PM
Quote
is that similar to the vplim routine posted already or no cab?


It is better  :D  It will work with polygon viewports as well. Great find CAB...I was just going to ask if anyone had a program like this.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 17, 2004, 06:16:03 PM
OK CAB,

Here it is:

I did try the lisp routine above, it is real nice but this very simple macro will prompt you to pick your object, you pick your viewport, it copies it, it then tiles to model space and asks you for an insertion point, you can then pick a point, it scales the viewport up (in this case by 96 because our plot scale will be 1/8"=1') it makes, the current layer defpoints, it then pastes the viewport as a block, then layer 0 is made current. From there you can copy it around in model space. So, by putting the scale portion into the macro, we now have an overall limits that we can draw within in Model space for our viewport that we will plot from.

Now, if there was a way to make the viewport a polyline instead of a block in Model Space, I would be real happy.

Thanks

Mark

Code: [Select]

^C^Ccopyclip;\;(setvar "tilemode" 1);-layer;s;defpoints;;pasteblock;s;96;\(setvar 'clayer "0");
 
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: MikePerry on November 17, 2004, 06:53:40 PM
Quote from: ML
Now, if there was a way to make the viewport a polyline instead of a block in Model Space, I would be real happy.

Hi Mark

Did the following not work for you -

Change object layer color in Macro (http://theswamp.org/phpBB2/viewtopic.php?p=39318#39318)

Have a good one, Mike
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 17, 2004, 07:11:12 PM
Hey Mike

It is very nice and I held onto to it but if you read the above, I told CAB what my macro does and what I need the routine to do.

Man! I just finally figured out a VBA problem I was working on :)

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: MikePerry on November 18, 2004, 02:52:38 AM
Hi Mark

I probably missing something here.... it does everything you require apart from the Scale 96 part (I honestly can't see / understand why that's required but obviously it's important to the way you work). I'm sure you can easily amend the necessary part to take into account the Scale 96 part.

CAB's find from JTB World is much better, simply due to the fact it will also handle Polygonal Floating Viewports.... therefore which ever way you decide to go I believe you've all the information needed to piece together a routine that meets your exact requirements.

Have a good one, Mike
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 18, 2004, 10:45:05 AM
Mike

Take the macro I posted above

Copy it into a button, run it in paper space, it will prompt you to pick your view port.

Then it will ask you for an insertion point in Model

I believe the one I posted i a scale factor of 96, so set your VP in Paper for 1/8"=1'

Inside the rectangle it creates in Model, draw a line from one side of the recangle to the other.

Go back to paper, you should then understand why I use the scale part.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 18, 2004, 11:16:33 AM
MIKE,
can you live with a lisp?
Code: [Select]
;;;  cvp.lsp by Charles Alan Butler
;;;         Copyright 2004
;;;  by Precision Drafting & Design All Rights Reserved.
;;;  Contact at ab2draft@TampaBay.rr.com
;;;
;;;   Version 1.0 Beta  Nov 18,2004
;;;
;;; DESCRIPTION
;;;  Copy a selected viewport to model space , converting it
;;;  to a pline on layer defpoints with color green
;;;  The copy is scales up 96 times
;;;  NOTE very limited testing
;;;
(defun c:cvp ()
  ;;  function to select a viewport & activate it
  ;;  returns the vp entlist
  (defun vp_sel (/ vpflag sel-vport vptest entvport)
    (setvar "TileMode" 0) ;  Force PaperSpace
    (if (/= (getvar "cvport") 1)
      (command "._pspace") ; close the view port
    )
    (setq vpflag (getvar "cvport")) ; get viewport #
    (while (= vpflag 1) ; No active viewport, Loop until one is picked
      (setq sel-vport (car (entsel "\nSelect view port: ")))
      (if (= sel-vport nil)
        (alert
          "You must select a viewport\n    --=<  Try again!  >=--"
        )
        (progn
          (setq entvport (entget sel-vport))
          (if (and ;; not all vp objects are LWPolylines
                   ;;(= (cdr (assoc 0 entvport)) "LWPOLYLINE")
                   (setq vptest (member '(102 . "{ACAD_REACTORS") entvport))
                   (setq vptest (member '(102 . "}") (reverse vptest)))
                   (assoc 330 vptest)
              )
            (setq entvport (entget (cdr (assoc 330 vptest))))
          )


          (if (= (cdr (assoc 0 entvport)) "VIEWPORT")
            (progn
              (setq vpflag (cdr (assoc 69 entvport))
              )
              (command "._mspace")
              (setvar "cvport" vpflag)
            ) ;  endif  viewport
          )
        )
      ) ;  endif cond  sel-vport
    ) ;endwhile (= vpFlag 1)
    entvport
  )

  ;;=============================================
  (if (setq vp (cdr (assoc -1 (vp_sel))))
    (progn
      (setq cm-pt (getvar "viewctr"))
      (command "._pspace")
      ;;  zoom view port
      (vl-load-com)
      (setq obj (vlax-ename->vla-object vp))
      (vla-getboundingbox obj 'lowerc 'upcor)
      (vla-zoomwindow (vlax-get-acad-object) lowerc upcor)
      ;; get center of vp
      (setq cp-pt (getvar "viewctr"))
      (command "._copybase" cp-pt vp "") ;copy vp
      (command "._zoom" "P")
      (setvar "tilemode" 1) ;
      (command "._pasteblock" "S" 96 cm-pt)
      (command "._explode" (entlast))
      (command "._change" (entlast) "" "_P" "_LA" "DefPoints" "_C" "Green" "")
    )
  )
  (princ)
)

(prompt "\nViewport Copy to Model space loaded.... Enter cvp to run.")
(princ)


edited 1:30pm EST
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: MikePerry on November 18, 2004, 01:40:16 PM
Quote from: ML
Take the macro I posted above

Hi Mark

I totally understand what your macro does, but as far as I can tell it's only good for Floating Viewports set at 1/8"=1' is that correct? (Sorry Imperial Units mean very little to me, afraid your dealing with a Metric user here) .

If yes, that explains my "don't understand...." comment, as the routine I modified to your requirements would serve yourself much better (I believe), as it works with any Regular Floating Viewport regardless of their Zoom XP Scale Factor.

Have you actually tried the routine?

If yes, then what exactly doesn't it do to meet your requirements?

If no, please try it.

Have a good one, Mike
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 18, 2004, 06:22:35 PM
Hi Mike,

I didn't realize that you updated it, I'm sorry.
Feel free to e-mail me at home if you like, I don't always get to the forum.

As far as my macro, that is only 1 out of like 8 or so.
I have 1:1,1/16, 1/8,1/4,1"=10',1"=20',1"=30',1"=40,1"=50' and 1"=60'

So, once again, If you have a viewport scaled to 1/8"=1', then 8X12 = 96

96 is the scale factor. So, if you multiply the width of your viewport in the X direction and the height in the Y direction by 96, you will have your outer most limits that you can draw in Model Space and still be any to plot in scale

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: MikePerry on November 18, 2004, 06:35:59 PM
Hi Mark

There's no need for the sorry....

I honestly understand the Zoom XP Factor you are talking about, but if you tried the routine I modified for you, you should see why it's not important (hence my "don't understand...." comment), the routine takes care of the Zoom XP Factor ensuring the PolyLine Rectangle is the correct size in Modelspace -

Please try the routine, if it doesn't do exactly what you want then please say where it's falling short of your requirements -

Change object layer color in Macro (http://theswamp.org/phpBB2/viewtopic.php?p=39318#39318)

Have a good one, Mike
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 18, 2004, 07:16:01 PM
This version asks the user to select a viewport, when selected
copies the vp to model space at the scale of the vp and centered on the same
center as the viewport. Then converts the vp to a pline and changes it to
defpoints layer with color green.

Code: [Select]
;;;  cvp.lsp by Charles Alan Butler
;;;         Copyright 2004
;;;  by Precision Drafting & Design All Rights Reserved.
;;;  Contact at ab2draft@TampaBay.rr.com
;;;
;;;   Version 1.1 Beta  Nov 18,2004
;;;
;;; DESCRIPTION
;;;  Copy a selected viewport to model space , converting it
;;;  to a pline on layer defpoints with color green
;;;  The copy is scaled to match vp scale
;;;  NOTE very limited testing
;;;
(defun c:cvp ()
  ;;  function to select a viewport & activate it
  ;;  returns the vp entlist
  (defun vp_sel (/ vpflag sel-vport vptest entvport)
    (setvar "TileMode" 0) ;  Force PaperSpace
    (if (/= (getvar "cvport") 1)
      (command "._pspace") ; close the view port
    )
    (setq vpflag (getvar "cvport")) ; get viewport #
    (while (= vpflag 1) ; No active viewport, Loop until one is picked
      (setq sel-vport (entsel "\nSelect view port: "))
      (if (= sel-vport nil)
        (alert "You must select a viewport\n    --=<  Try again!  >=--")
        (progn
          (setq entvport (entget (car sel-vport)))
          (if (and ;; not all vp objects are LWPolylines
                   ;;(= (cdr (assoc 0 entvport)) "LWPOLYLINE")
                   (setq vptest (member '(102 . "{ACAD_REACTORS") entvport))
                   (setq vptest (member '(102 . "}") (reverse vptest)))
                   (assoc 330 vptest)
              )
            (setq entvport (entget (cdr (assoc 330 vptest))))
          )

          (if (= (cdr (assoc 0 entvport)) "VIEWPORT")
            (progn
              (setq vps (/ (cdr (assoc 45 entvport))
                           (cdr (assoc 41 entvport))
                        )
              ) ;---returns absolute viewport scale as integer
              (if (< vps 1)
                (setq vps (/ 1 vps))
              ) ;---sets viewport scale to real
              (setq vpflag (cdr (assoc 69 entvport)))
              (command "._mspace")
              (setvar "cvport" vpflag)
            ) ;  endif  viewport
          )
        )
      ) ;  endif cond  sel-vport
    ) ;endwhile (= vpFlag 1)
    (cons (car sel-vport) vps)
  )

  ;;=============================================
  (if (setq vp (vp_sel))
    (progn
      (setq cm-pt (getvar "viewctr"))
      (command "._pspace")
      ;;  zoom view port
      (vl-load-com)
      (setq obj (vlax-ename->vla-object (car vp)))
      (vla-getboundingbox obj 'lowerc 'upcor)
      (vla-zoomwindow (vlax-get-acad-object) lowerc upcor)
      ;; get center of vp
      (setq cp-pt (getvar "viewctr"))
      (command "._copybase" cp-pt (car vp) "") ;copy vp
      (command "._zoom" "P")
      (setvar "tilemode" 1) ;
      (command "._pasteblock" "S" (cdr vp) cm-pt)
      (command "._explode" (entlast))
      (command "._change" (entlast) "" "_P" "_LA" "DefPoints" "_C" "Green" "")
    )
  )
  (princ)
)

(prompt "\nViewport Copy to Model space loaded.... Enter cvp to run.")
(princ)
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 18, 2004, 07:28:10 PM
Sure Mike

I will try it right now
I will let you know what I think

Thank you

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 18, 2004, 07:45:56 PM
Hey Mike

That is great!

That is almost exactly what I was looking for. I like the way it gets the scale factor and creates the polyline scaled up perfectly.

You see, the way my pulldown is structured is so the user can choose the scale factor, they click on the scale factor then my macro does its thing.

I there a way that I could tweak it so that I have several smaller ones (one for each scale) as opposed to 1 large one?

Then be prompted for an insertion point in Model space?

Thanks again

Keep up the good work

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 18, 2004, 08:35:28 PM
Mike,

I really like it a lot
It creates a perfectly scaled closed rectangular polyline in Model,
It puts it on defpoints, makes it green while leaving the layer blue. That is excellent

Like I said, instead of it needing to have a scaled VP, I rather click the scale, then have it take the 1:1 vp and ask me for an insertion point in Model.

If that can be done, then we are on. I just have to see where in the code that I need to tweak for it to realize each scale

I have some nice routines I would be glad to share with you also if you are interested

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: MikePerry on November 19, 2004, 03:22:47 AM
Quote from: ML
You see, the way my pulldown is structured is so the user can choose the scale factor, they click on the scale factor then my macro does its thing.

I there a way that I could tweak it so that I have several smaller ones (one for each scale) as opposed to 1 large one?


Quote from: ML
Like I said, instead of it needing to have a scaled VP, I rather click the scale, then have it take the 1:1 vp and ask me for an insertion point in Model.

Hi Mark

Why not keep the Menu structure that you have but just assign the routine to each Scale Factor -> User click's the appropriate Scale Factor from the Menu -> Routine is run eg

ID_1to10 [Scale Factor 1:10]^C^C(autoload "vpl" '("vpl"));vpl;
ID_1to20 [Scale Factor 1:20]^C^C(autoload "vpl" '("vpl"));vpl;
ID_1to50 [Scale Factor 1:50]^C^C(autoload "vpl" '("vpl"));vpl;
etc

The User doesn't need to know that the same routine is being run.... the above is just a thought.

The routine does allow you to pick the insertion point in Modelspace....

You should really look at the routine CAB found from JTB World, in my humble opinion soooooo much superior.

CAB your above routine comes a close second to JTB World's one, your one also works with with Polygonal Floating Viewports :) But when used with such an Object it copies two Objects to Modelspace -

Polyline Outline
+
Viewport Object

Have a good one, Mike
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: daron on November 19, 2004, 08:03:09 AM
Quote from: MikePerry
CAB your above routine comes a close second to JTB World's one, your one also works with with Polygonal Floating Viewports :) But when used with such an Object it copies two Objects to Modelspace -


+
Viewport Object

Have a good one, Mike


Mike, I'm sure you know the reason why you get two objects, but for those who haven't figured it out just yet, I'd like to explain it a bit. When creating polygonal (clipped) viewports, you are essentially drawing a pline that encases the parameters of a viewport object. For some reason, Autodesk decided that this was the best way to go about it instead of just taking the viewport object and removing the constraints (<that's MDT talk for reactors/events). Personallly, I think they could've recoded the viewport object to have constraints when rectangular and remove the constraints when converting to polygonal. Anyway, the user draws the polygonal viewport, which creates a pline and the viewport is also adjusted to match. That is why there are two objects.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: MikePerry on November 19, 2004, 08:22:59 AM
Hi Daron

Daron, nice clear explanation above :)

Just to clear-up my comments -

CAB's routine when used on a Polygonal Floating Viewport works but it creates two Objects in Modelspace.

JTB World's routine when used on a Polygonal Floating Viewport creates only one Object in Modelspace - a Polyline outline.

The other routines that have been floating about during this thread (and related ones) only work with regular Floating Viewports (ok! except CADaver's macro that used the ChSpace command).

Cheers, Mike
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: daron on November 19, 2004, 08:34:23 AM
Mike, thanks for the kind words.

Hmm. Maybe I need to study the JTB World lisp. I learned of the two objects when Se7en taught me ActiveXLisp by working with me through a function that toggled the locking/unlocking of viewports. To add visual effect for the user, we forced a layer specific to viewports and made the native layer color red. The color was changed on any viewport that was locked to green. Kind of a red = don't zoom or pan in the viewport, green = you are free to roam without danger of losing your scale.

Anyway, I found a bug in the system when I tried it on a polygonal viewport.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 19, 2004, 08:51:15 AM
Hey Mike

Your idea with the pulldown is well taken but doesn't the user still have to scale their viewport first? Then select if for the routine to grab the parameters it needs?

May be I am not quite understanding what you are explaining to me.

Thanks again

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: MikePerry on November 19, 2004, 09:17:21 AM
Hi Mark

Sorry I'm now really confused, what's the Floating Viewport Scale Factor have to do with the routine (as it works regardless of the Scale Factor, it takes the scale factor from the picked Floating Viewport).

OR

Are you now referring to the initial setting-up of a Floating Viewport and the correct setting of it's Zoom XP Scale Factor?

If yes, then surely that's a totally different process that not even your initial macro attempted to tackle. As I understood the Floating Viewport would already be present and set at the correct Zoom XP Scale Factor; a routine was required to copy a picked Floating Viewport into Modelspace....

Have a good one, Mike
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 19, 2004, 10:01:40 AM
Here we go again,
I think I got the vp copy licked, the new object is not a vp.
Works with all shapes of view ports.
But the UCS thing kicks my butt. :?

Code: [Select]
;;;  cvp.lsp by Charles Alan Butler
;;;         Copyright 2004
;;;  by Precision Drafting & Design All Rights Reserved.
;;;  Contact at ab2draft@TampaBay.rr.com
;;;
;;;   Version 1.2 Beta  Nov 19,2004
;;;
;;; DESCRIPTION
;;;  Copy a selected viewport to model space , converting it
;;;  to a pline on layer defpoints with color green
;;;  The copy is scaled to match vp scale
;;;  NOTE very limited testing
;;;
(defun c:cvp (/ vp obj cp-pt cm-pt lowerc upcor)
  ;;  function to select a viewport & activate it
  ;;  returns the vp entlist
  (defun vp_sel (/ vpflag sel-vport vp-ent entvport vp-elst)
    (setvar "TileMode" 0) ;  Force PaperSpace
    (if (/= (getvar "cvport") 1)
      (command "._pspace") ; close the view port
    )
    (setq vpflag (getvar "cvport")) ; get viewport #
    (while (= vpflag 1) ; No active viewport, Loop until one is picked
      (setq sel-vport (entsel "\nSelect view port: "))
      (if (= sel-vport nil)
        (alert "You must select a viewport\n    --=<  Try again!  >=--")
        (progn
          (setq entvport (entget (car sel-vport)))
          (if (and ;; not all vp objects are LWPolylines
                   ;;(= (cdr (assoc 0 entvport)) "LWPOLYLINE")
                   (setq vp-ent (member '(102 . "{ACAD_REACTORS") entvport))
                   (setq vp-ent (member '(102 . "}") (reverse vp-ent)))
                   (assoc 330 vp-ent)
              )
            ;;  got the object associated with a non-standard viewport
            ;;  so get the actual vp object
            (setq vp-elst  entvport
                  entvport (entget (cdr (assoc 330 vp-ent)))
            )
          )

          ;;  calculate the viewport scale
          (if (= (cdr (assoc 0 entvport)) "VIEWPORT")
            (progn
              (setq vps (/ (cdr (assoc 45 entvport))
                           (cdr (assoc 41 entvport))
                        )
              ) ;---returns absolute viewport scale as integer
              (if (< vps 1)
                (setq vps (/ 1 vps))
              ) ;---sets viewport scale to real
              (setq vpflag (cdr (assoc 69 entvport)))
              (command "._mspace")
              (setvar "cvport" vpflag)
            ) ;  endif  viewport
          )
        )
      ) ;  endif cond  sel-vport
    ) ;endwhile (= vpFlag 1)
    ;; return vp-name  vp-scale  vp-elist if irregular vp
    (list (car sel-vport) vps vp-elst)
  )
  ;;  function to strip unwanted dxf codes for a new entity
  ;;  retuens a ent list ready for entmake
  (defun strip (entl)
    ;;  ent expected to be an entity name or entlist or ename w/ point list
    (cond
      ((= (type entl) "ENAME")
       (setq entl (entget entl))
      )
      ((= (length entl) 2)
       (setq entl (car entl))
      )
    )
    (foreach n '(-2 -1 5 102 300 330 331 350 360)
      (while (assoc n entl)
        (setq entl (vl-remove (assoc n entl) entl))))    
   
    entl
  )
  ;;=============================================
  (if (setq vp (vp_sel))
    (progn
      (setq cm-pt (getvar "viewctr")) ;  get center of vp in ms
      (command "._pspace")
      ;;  zoom view port borders
      (vl-load-com)
      (setq obj (vlax-ename->vla-object (car vp)))
      (vla-getboundingbox obj 'lowerc 'upcor)
      (vla-zoomwindow (vlax-get-acad-object) lowerc upcor)

      (setq cp-pt (getvar "viewctr")) ; get center of vp in ps
      ;;  make a copy of the vp
      (if (setq vp-elst (caddr vp)) ; got an entity other than a vp
        (entmake (setq tmp (strip vp-elst)))
        ;;  else got a rectangular vp
        (command "._rectangle" (vlax-safearray->list lowerc)
                 (vlax-safearray->list upcor))
      )
      (command "._copybase" cp-pt (entlast) "")
      ;(setq vp-oline (entget (entlast)))
      (entdel (entlast))

      (command "._zoom" "P")
      (setvar "tilemode" 1) ;
      (command "._pasteblock" "S" (cadr vp) cm-pt)
      (command "._explode" (entlast))
      (command "._change" (entlast) "" "_P" "_LA" "DefPoints"
               "_C" "Green" "")
    )
  )
  (princ)
)

(prompt "\nViewport Copy to Model space loaded.... Enter cvp to run.")
(princ)
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: craigr on November 19, 2004, 02:38:52 PM
Win2000 pro, 2ghz, 1 gig Ram, AutoCad LT98.

I know little about viewports, but ..... :oops:

Okay, I've read all of the posts for this subject. I even tried the copyclip a viewport, (with a floor plan in it), to MS from PS. All I get is an empty rectangle. I glanced at the VBA / Lisps / Macros but didn't try them. All LT allows is macros.

   My first question is, once the viewport is copyclipped and pasteclipped from PS to MS, should one be able to access it in MS as you do from PS?- In other words, is another 'viewport' created within the first viewport?

    Should my floor plan still be visible in the 'New' viewport?

craigr
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CADaver on November 19, 2004, 02:50:51 PM
Quote from: craigr
Win2000 pro, 2ghz, 1 gig Ram, AutoCad LT98.

I know little about viewports, but ..... :oops:

Okay, I've read all of the posts for this subject. I even tried the copyclip a viewport, (with a floor plan in it), to MS from PS. All I get is an empty rectangle. I glanced at the VBA / Lisps / Macros but didn't try them. All LT allows is macros.

   My first question is, once the viewport is copyclipped and pasteclipped from PS to MS, should one be able to access it in MS as you do from PS?- In other words, is another 'viewport' created within the first viewport?

    Should my floor plan still be visible in the 'New' viewport?

craigr


ONce pasted, It must be turned on.  Either whisper in it's ear, or open the properties box, click on the viewport.  Down about 2/3's the way und "MISC you'll see "ON", in the li'l window next to it, dbl-click.

Another method of turning on viewports id the MVIEW -> ON <select viewport> command line sequence.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 19, 2004, 03:09:48 PM
Well the view port project here was to actually create an outline in model space so
you could, while in model space see the area the view port represented. This allows
you to arrange things to fit within the outline of the vp. It has nothing to do with
a 'model space view port'
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 19, 2004, 04:40:08 PM
That's right!

Thank you CAB. You are like the first one that is acknowledging one of my initial reasons for this post.

As far as actual viewports, it is not a good prctice to have them in Model and they can not be turned on in Model. After I insert my Title BLocks via a menu macro, Mview;on; is part of it so that the mview does get turned on after it is inserted.

Now, as far as the scale AGAIN  :oops:

I don't want the viewport to have to be scaled first.

I want the user to put the scale in.


This is why posting gets frustrating      :(
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: MikePerry on November 19, 2004, 05:19:12 PM
Hi Mark
Quote from: ML
Thank you CAB. You are like the first one that is acknowledging one of my initial reasons for this post.

No comment.

Quote from: ML
Now, as far as the scale AGAIN  :oops:

I don't want the viewport to have to be scaled first.

I want the user to put the scale in.

What scale -

1. The actual ZoomXP Scale Factor to set the Floating Viewport Scale.

2. The Scale your initial Macro had hard coded (96), that was only used to correctly scale the Polyline Rectangle when Pasted into Modelspace.

3. Some other Scale.

If 1 then that was never part of your initial requirement, nor did your initial Macro take that into account; therefore this is something new you require the routine to accomplish.

If 2 then the routines offered should meet your needs as they correctly Scale the Polyline Outline when placed into Modelspace.

If 3 then please explain a little more.

Have a good one, Mike
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 19, 2004, 05:57:08 PM
Quote from: MikePerry

What scale -

1. The actual ZoomXP Scale Factor to set the Floating Viewport Scale.

2. The Scale your initial Macro had hard coded (96), that was only used to correctly scale the Polyline Rectangle when Pasted into Modelspace.

3. Some other Scale.

If 1 then that was never part of your initial requirement, nor did your initial Macro take that into account; therefore this is something new you require the routine to accomplish.

If 2 then the routines offered should meet your needs as they correctly Scale the Polyline Outline when placed into Modelspace.

If 3 then please explain a little more.

Have a good one, Mike


Mike, How about that moving target :shock:

In my openion the scale should be set when you create the vp and the
routine just reads the scale. If it were me I set the scale, align & LOCK the vp
But thats just the way I do things. I'm still trying to figure out exactly how Mark is doing things.
Mark, are you saying you want the routine to set the vp scale first, then create the outline?
I assume the user has aligned the center, or does that matter?
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 19, 2004, 06:47:50 PM
LOL

OK, I will try again.

I insert the title block in via a macro.

Now, at this point, the viewport comes in with the title block at 1:1

I want to simply click on the viewport and at the command line have it ask me what scale factor I would like to use, at that point, I put in a scale factor, let's use 96 as an example"only"

After I've entered 96 at the command prompt, I would then like to be prompted in Model for an insertion point. I click somewhere in Model and VOILA, there is my polylined recatangle.

At risk of sounding ungrateful, the routines in here are outstanding but either I am speaking another language, totally missing something or you guys are just understanding the simplicity of my post.

This is the total downside to posting.

One on one is SO much easier

Thanks

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 19, 2004, 09:01:39 PM
Mark Said:
OK, I will try again.

I insert the title block in via a macro.
I assume in paper space
Now, at this point, the viewport comes in with the title block at 1:1
What vp, did you create the vp, what size, what shape, what scale?
I want to simply click on the viewport and at the command line have it ask me what
scale factor I would like to use, at that point, I put in a scale factor, let's
use 96 as an example"only"
Why not have the title block macro create the vp, it could erase any existing vps.
This way it would be aligned with the title block
After I've entered 96 at the command prompt, I would then like to be prompted in Model
for an insertion point. I click somewhere in Model and VOILA, there is my polylined rectangle.
How about a pop-up pick list of scales?
At risk of sounding ungrateful, the routines in here are outstanding but either I am speaking
another language, totally missing something or you guys are just understanding the
simplicity of my post.
Pseudo code! It goes along way in defining the task.
This is the total downside to posting.
One on one is SO much easier
It's easer because you have a two way conversation. In this situation what we thought you wanted
from the clues, was too much conjecture on our part.
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: CAB on November 19, 2004, 09:21:28 PM
Task :
Insert a title block in paperspace with a scaled viewport
and have a rectangle scaled to outline the viewport created.

Pseudo Code :
Users picks title block based on paper size & job requirements
..options: DCL pick list, command line entry, insert block from file list

Title block is inserted in paper space at 0,0 for lower left corner
Based on title block size a vp is created to fit inside the title block

User prompted for vp scale
..options: DCL pick list, command line entry, screen menu pick list

Scale vp & get size
Switch to model space
Create a pline rectangle based on the vp size & scale picked
..pline width 0, layer defpoints, color green
move new rectangle to user picked location
..options: move rectangle showing drag, pick LL corner the move or create rectangle

I have said it several times, that the pseudo code is often the most
difficult part of the routine.

Are we getting close?  :roll:

Please say we are :)  :)  :)

CAB
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 21, 2004, 05:21:20 PM
Quote

Task :
Insert a title block in paperspace with a scaled viewport
and have a rectangle scaled to outline the viewport created.


OK, may be I have found where the communication breakdown occured.
I am not sure how other people do this but I scale my viewport after it is inserted.

I may be wrong but it seemed to me that you need to scale the viewport first, then select your viewport in order for the above code to work.

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: MikePerry on November 22, 2004, 03:33:05 AM
Hi Mark

As I understand it you've already got a Macro / Routine that places your drawing frame and a single Floating Viewport into Paperspace (Layout).

If yes, I think that should be left as is.

If no, I think that would make a good single process.

Personally I would go with a two step process (Macro / Routine) approach, as CAB hinted to -

Quote
In my openion the scale should be set when you create the vp and the routine just reads the scale. If it were me I set the scale, align & LOCK the vp But thats just the way I do things.

1st Macro / Routine:

Set Floating Viewport Scale.

2nd Macro / Routine:

Select Floating Viewport outline, copy to Modelspace (scaled appropriately), allow user to pick location, place on Layer Defpoints, Colour forced to Green(3).

1st Macro / Routine: I'm sure you could easily write yourself simply by using the Zoom command with the XP option.

2nd Macro / Routine: Take your pick from the one's already given.

I would go with an approach like the above as it breaks down a number of tasks into smaller logical processes that I personally see as separate issues; could think of each as a useful Toolbox function.

You could go with a one Macro / Routine that does the lot, but personally I don't think such an approach offers much flexibility.

Have a good one, Mike
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: ML on November 22, 2004, 06:41:56 AM
Hi Mike

I think I am further understanding the confusion even more so now.

If I were building title blocks + macros for myself + myself only, then yes, it would make sense to possibly pre scale the viewport prior to having the macro insert the title block, but I am not creating them just for myself, and I am not the onlt one that decides how we do things.

So, having said that, it is what it is.

Having said that, I think we should both now be on the same page.

So, when I was talking about my pulldown, you can now understand why I want to click one scale out of the six or so choices on there, click the VP and the rest happens.

Thanks again

Mark
Title: Copying, Exploding or Changing Viewports in Model Space
Post by: whdjr on November 22, 2004, 03:34:18 PM
Mark,

Give this a try.  This assumes you already have your titleblock and viewport inserted and are in the layout tab.

Will
Code: [Select]
;;;This program hopefully answers a question at theswamp.org by ML.
;;;
;;;Copyright by Will DeLoach
;;;Can be rewritten or reused as you see fit.
;;;
;;;Loads the activeX controls if they are not already loaded.
;;;
(vl-load-com)
;;;
;;;This function uses ssget to return a single selection and continues
;;;to loop until something is selected or a right click is detected.
;;;
(defun ss_get (typ filter / ent)
  (if (> (getvar "CVPORT") 1)
    (command "._PSPACE")
  )
  (while (not ent)
    (prompt "\nSelect a Viewport to convert to modelspace:  ")
    (cond ((setq ent (ssget typ filter)))
 ((= (getvar "ErrNo") 52)
  (exit)
 )
 ((null ent)
  (princ "\nSelection missed.  Please try again.")
 )
    )
  )
  (ssname ent 0)
)
;;;
;;;This makes a variable length vbDouble safearray.
;;;
(defun make-array (pointlist)
  (vlax-make-variant
    (vlax-safearray-fill
      (vlax-make-safearray
vlax-vbDouble
(cons 0
     (1- (length
   pointlist
 )
     )
)
      )
      pointlist
    )
  )
)
;;;
;;;This collects the coordinates for the viewport and translates the to modelspace.
;;;
(defun translate_pts (obj / pnts)
  (vla-getboundingbox obj 'll 'ur)
  (setq pnts (mapcar 'vlax-safearray->list (list ll ur))
pnts (list (list (caar pnts) (cadar pnts))
  (list (caadr pnts) (cadar pnts))
  (list (caadr pnts) (cadadr pnts))
  (list (caar pnts) (cadadr pnts))
    )
pnts (3d->2d (mapcar
      '(lambda (x)
 (trans x 3 2)
)
      pnts
    )
    )
ll   (car pnts)
ur   (caddr pnts)
  )
  pnts
)
;;;
;;;This converts 3d points to 2d points for the lightweight polyline creation.
;;;
(defun 3d->2d (lst)
  (mapcar '(lambda (x)
    (list (float (car x)) (float (cadr x)))
  )
 lst
  )
)
;;;
;;;This sets the viewport scale before the points are translated.
;;;
(defun set_scl (ent int / obj)
  (setq obj (vlax-ename->vla-object ent))
  (vla-put-standardscale obj acVpCustomScale)
  (vla-put-customscale obj int)
  obj
)
;;;
;;;This is the main program.
;;;
(defun c:vp (/ ss scl pts obj space pline ll ur)
  (cond ((not (and (setq ss (ss_get ":S:E" '((0 . "VIEWPORT"))))
  (not (initget (+ 1 2 4)))
  (setq scl (getreal "\nEnter scale factor:  "))
  (setq obj (set_scl ss (/ 1.0 scl)))
     )
)
(princ "\nUser Error. ")
)
((not (setq pts (apply 'append (translate_pts obj))))
(princ
  "\nError: Could not translate points to model space. "
)
)
(T
(command "._MSPACE")
(setq space (vla-get-modelspace
      (vla-get-activedocument (vlax-get-acad-object))
    )
)
(setq pline (vla-addlightweightpolyline space (make-array pts)))
(vla-put-closed pline T)
(command "._PSPACE")
(setvar "CTAB" "MODEL")
(command "zoom" "window" ll ur)
)
  )
  (princ)
)