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

0 Members and 1 Guest are viewing this topic.

ML

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

MikePerry

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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Copying, Exploding or Changing Viewports in Model Space
« Reply #47 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)
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.

craigr

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

CADaver

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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Copying, Exploding or Changing Viewports in Model Space
« Reply #50 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'
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 #51 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      :(

MikePerry

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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Copying, Exploding or Changing Viewports in Model Space
« Reply #53 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?
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 #54 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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Copying, Exploding or Changing Viewports in Model Space
« Reply #55 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.
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Copying, Exploding or Changing Viewports in Model Space
« Reply #56 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
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 #57 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

MikePerry

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

ML

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