Author Topic: Copying, Exploding or Changing Viewports in Model Space  (Read 16159 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #30 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

MikePerry

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #31 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

ML

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #32 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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Copying, Exploding or Changing Viewports in Model Space
« Reply #33 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
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MikePerry

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #34 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

ML

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #35 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

MikePerry

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #36 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

Have a good one, Mike

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Copying, Exploding or Changing Viewports in Model Space
« Reply #37 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)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ML

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #38 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

ML

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #39 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

ML

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #40 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

MikePerry

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #41 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

daron

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #42 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.

MikePerry

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #43 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

daron

  • Guest
Copying, Exploding or Changing Viewports in Model Space
« Reply #44 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.