Results 1 to 7 of 7

Thread: Copy Floating Viewport outline to Modelspace

  1. #1
    Active Member -OTTP-Brembo's Avatar
    Join Date
    2004-06
    Location
    Darwin, Australia
    Posts
    75
    Login to Give a bone
    0

    Default Copy Floating Viewport outline to Modelspace

    I have an old routine that I use all the time called "VIEWGD.LSP"

    It allows you to double click in a viewport and it then draw a polyline the same size as the viewport in modelspace.

    The only problem with it now is that it only works for rectangular shaped vports.

    Has anyone updated this to use the new polygon and irregular shaped ones that are available in the newer releases?

  2. #2
    100 Club lance.81922's Avatar
    Join Date
    2005-01
    Location
    Santa Fe, NM
    Posts
    176
    Login to Give a bone
    0

    Default Re: Copy Floating Viewport outline to Modelspace

    I'd be interested in looking into updating the routine, but I have never seen it. Would you please post the code for the old program? The challenge will be seeing how AutoLISP treats irregular or polygonal viewports (I've never looked).

  3. #3
    The Silent Type Mike.Perry's Avatar
    Join Date
    2000-11
    Posts
    13,656
    Login to Give a bone
    0

    Default Re: Copy Floating Viewport outline to Modelspace

    Hi

    Check out the following thread -

    View From Viewport

    Have a good one, Mike

  4. #4
    100 Club lance.81922's Avatar
    Join Date
    2005-01
    Location
    Santa Fe, NM
    Posts
    176
    Login to Give a bone
    0

    Default Re: Copy Floating Viewport outline to Modelspace

    Thanks a bunch, Mike..............

  5. #5
    Active Member -OTTP-Brembo's Avatar
    Join Date
    2004-06
    Location
    Darwin, Australia
    Posts
    75
    Login to Give a bone
    0

    Default Re: Copy Floating Viewport outline to Modelspace

    Lance. Here you go...

    Code:
    ; List of Defined Functions
    ; C:GD  C:VPSC  DXF  ENDERR  GETMODE  INITERR  MVGUIDE
    ; SCLTXT  SETMODE  VPDTA  VPSC
    
    
    ; MVGUIDE - main routine
    
    (defun mvguide (/ ctr dx dy fl p1 p2 p3 p4 scl vno vpinf xc xsz yc ysz)
     (setq
      vpinf (vpdta "which requires guideline")
      fl  (nth 0 vpinf)
      vno (nth 1 vpinf)
      ctr (nth 2 vpinf)
      scl (nth 4 vpinf)
      xsz (nth 5 vpinf)
      ysz (nth 6 vpinf)
      xc  (car  ctr)
      yc  (cadr ctr)
      dx  (* xsz scl 0.5)
      dy  (* ysz scl 0.5)
      p1  (list (- xc dx) (- yc dy))
      p2  (list (+ xc dx) (- yc dy))
      p3  (list (+ xc dx) (+ yc dy))
      p4  (list (- xc dx) (+ yc dy))
     )
     (command
      "MSPACE"
      "LAYER" "M" "VPORT" ""
      "PLINE" p1 "W" 0 0 p2 p3 p4 "C"
      "CHANGE" (entlast) "" "P" "LA" "VPORT" ""
     )
     (if fl (command "PSPACE"))
     (if (= "11" (substr (getvar "ACADVER") 1 2))
      (princ (strcat "\nScale of Viewport #" (itoa vno) " is " (scltxt scl)))
      (alert
       (strcat
        "Scale of Viewport #" (itoa vno) " is 1:"
        (if (= scl (fix scl)) (itoa (fix scl)) (rtos scl 2 3))
     )))
    )
    
    
    ; C:GD - command line access to function
    
    (defun C:viewgd ()
     (initerr)
     (setq prgmod (getmode '("TILEMODE" "CLAYER" "OSMODE")))
     (setvar "OSMODE" 0)
     (mvguide)
     (setmode prgmod)
     (enderr)
     (princ)
    )
    
    
    ; VPSC - find scale of Viewport
    
    (defun vpsc (/ fl scl str vno vpinf)
     (setq
      vpinf (vpdta "for which scale required")
      fl  (nth 0 vpinf)
      vno (nth 1 vpinf)
      scl (nth 4 vpinf)
      str (strcat "Scale of Viewport #" (itoa vno) " is " (scltxt scl))
     )
     (if (= "11" (substr (getvar "ACADVER") 1 2))
      (princ (strcat "\n" str))
      (alert str)
     )
     (command (if fl "PSPACE" "MSPACE"))
    )
    
    
    ; C:VPSC - command line access to function
    
    (defun C:VPSC ()
     (initerr)
     (setq prgmod (getmode '("TILEMODE" "CLAYER")))
     (setvar "OSMODE" 0)
     (vpsc)
     (setmode prgmod)
     (enderr)
     (princ)
    )
    
    
    ; VPDTA - select viewport and return data
    
    
    (defun vpdta (prom / cnt ctr cvp en flag scl ss vno vsz xsz ysz)
     (if (= (getvar "TILEMODE") 1)
      (progn
       (setvar "TILEMODE" 0)
       (command "PSPACE")
     ))
     (if (/= (getvar "CVPORT") 1)
      (setq flag nil)
      (progn
       (setq flag T)
       (command "MSPACE")
       (getpoint (strcat "\nPick twice in Viewport " prom "\n"))
     ))
     (setq
      ctr (getvar "VIEWCTR")  ;centrepoint of viewport
      vsz (getvar "VIEWSIZE") ;height of viewport
      vno (getvar "CVPORT")   ;no. of current viewport
     )
     (command "PSPACE")
     (setq
      ss (ssget "X" '((0 . "VIEWPORT")))
      cnt -1
     )
     (while (and cnt (< (setq cnt (1+ cnt)) (sslength ss)))
      (setq en (entget (ssname ss cnt)))
      (if (= (dxf 69 en) vno) (setq cnt nil))
     )                               
     (setq
      xsz (dxf 40 en)
      ysz (dxf 41 en)
      scl (/ vsz ysz)
     )
     (if (not flag) (command "MSPACE"))
     (if (/= (dxf 8 en) "VP") (entmod (subst (cons 8 "VP") (assoc 8 en) en)))
     (list flag vno ctr vsz scl xsz ysz)
    )
    
    
    ; SCLTXT - convert scale factor to common text forms
    
    (defun scltxt (scl / dimz lup txtscl)
     (setq dimz (getvar "DIMZIN") lup (getvar "LUPREC"))
     (if (not scl) (setq scl (getvar "DIMSCALE")))
     (if (< (abs (- scl (fix (+ scl 0.002)))) 0.001)
      (setq scl (fix (+ scl 0.002)))
     )
     (if (= (getvar "LUNITS") 4)
      (setvar "LUPREC" (cond ((> scl 192) 5) ((> scl 96) 4) (T 3)))
     )
     (if scl
      (if (member scl (list 4 8 12 16 24 32 48 64 96 192 384)) ;Architectural scales
       (setq txtscl (strcat (rtos (/ 12.0 scl)) "=1'-0\""))
       (if (member scl (list 120 240 360 480 600 720 900 1200 1800 2400 3000 6000))
        (progn    ;Engineering scales
         (setvar "DIMZIN" 0)
         (setq txtscl (strcat "1\"=" (rtos scl)))
         (setvar "DIMZIN" dimz)
        )
        (setq txtscl ;all others including metric, full & half scale
         (cond
          ((= scl 1) "FULL")
          ((= scl 2) "HALF")
          (T (strcat "1:" (rtos scl 2 2)));if more precision needed, change last 2
      ))))
      (setq txtscl "not defined")
     )
     (setvar "LUPREC" lup)
     txtscl
    )
    
    
    ; GETMODE - establish changeable variables which are to be reset
    ;           at end of program and initialize error program
    
    (defun getmode (mod1 / mod)
     (repeat (length mod1)
      (setq 
       mod (append mod (list (list (car mod1) (getvar (car mod1)))))
       mod1 (cdr mod1)
     ))
     mod
    )
    
    
    ; SETMODE - reset variables and error system
    
    (defun setmode (mod1)
     (repeat (length mod1)
      (setvar (caar mod1) (cadar mod1))
      (setq mod1 (cdr mod1))
     )
    )
    
    
    ; DXF - extract DXF code from list
    
    (defun dxf (code elist) (cdr (assoc code elist)))
    
    
    ; INITERR - set up error at start of program
    
    (defun initerr ()
     (setq
      olderr *error*
      *error* gderr
      errmod (getmode '("BLIPMODE""CMDECHO""MENUECHO""ORTHOMODE""OSMODE""SNAPMODE"))
     )
     (setvar "CMDECHO" 0)
     (command "_.UNDO" "G")
    )
    
    
    ; ENDERR - clean up error at end of program
    
    (defun enderr ()
     (command "CMDECHO" 0)
     (if errmod (setmode errmod))
     (setq
      errmod nil
      prgmod nil
      libmod nil
     )
     (command "_.UNDO" "E")
     (setq *error* olderr)
    )
    
    
    ; *ERROR* - main error routine
    
    (defun gderr (msg)
     (command nil nil nil)
     (setvar "CMDECHO" 0)
     (reset msg)
     (grtext)
     (if (and (/= msg"console break")(/= msg "Function cancelled"))
      (grtext -1 "Program ERROR")
     )
     (princ)
    )
    
    
    ; RESET - clean up after error
    
    (defun reset (msg / x)
     (if msg
      (if (and (/= msg "console break")(/= msg "Function cancelled"))
       (prompt (strcat "Error: " msg "\n"))
       (prompt (strcat msg "\n"))
      )
      (prompt"\nResetting environment...")
     )
     (command "UNDO" "E")
     (command "U")
     (if errmod (setmode errmod))
     (if prgmod (setmode prgmod))
     (if libmod (setmode libmod))
     (if blkmod (setmode blkmod))
     (setq
      errmod nil
      prgmod nil
      libmod nil
      blkmod nil
     )
     (princ)
    )
    
    (princ "\nVIEWGD loaded. Type VIEWGD to make guide.  Type VPSC to display scale.")
    
    (princ)
    Last edited by Glenn Pope; 2005-03-08 at 02:57 AM. Reason: Placed routine in code tags

  6. #6
    100 Club lance.81922's Avatar
    Join Date
    2005-01
    Location
    Santa Fe, NM
    Posts
    176
    Login to Give a bone
    0

    Default Re: Copy Floating Viewport outline to Modelspace

    Thank you for sending that, Stephen. I just wanted to see how it works.

    I think you'll find
    Quote Originally Posted by tombu
    vp-outline.lsp by Jimmy Bergmark
    Website: www.jtbworld.com
    to work very well. I played with it using both a polygon viewport and an irregular closed viewport, and it seems to work well.

    Thanks again to Mike for referring to the other thread with this info in it.

  7. #7
    Active Member -OTTP-Brembo's Avatar
    Join Date
    2004-06
    Location
    Darwin, Australia
    Posts
    75
    Login to Give a bone
    0

    Default Re: Copy Floating Viewport outline to Modelspace

    Thanks for the link. Exactly what I was looking for, but have noticed that it doesn't do circle vports.
    Doesn't matter though, it will do for 99% of my jobs.

Similar Threads

  1. Replies: 2
    Last Post: 2017-08-09, 01:04 PM
  2. Replies: 13
    Last Post: 2011-09-10, 11:16 PM
  3. Xref in Modelspace only plots in one Floating Viewport
    By jmd3 in forum AutoCAD Plotting
    Replies: 2
    Last Post: 2007-02-06, 04:13 AM
  4. Replies: 16
    Last Post: 2006-03-05, 02:48 AM
  5. Set Floating Viewport to Modelspace limits
    By steve.86586 in forum AutoCAD General
    Replies: 4
    Last Post: 2005-08-03, 06:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •