Author Topic: Changing current viewport in the middle of a routine.  (Read 11360 times)

0 Members and 1 Guest are viewing this topic.

CADaver

  • Guest
Changing current viewport in the middle of a routine.
« Reply #15 on: November 12, 2003, 10:17:37 AM »
Quote from: hendie
what happens after you display the slice ?


Could be several different things.  The routine will be the "engine" for a couple of other functions like saving the view for recalling in a layout viewport.

The concept is to provide an easy method of extracting col. line elevations and plan views of different floors for placing in layouts in preparation for annotation.

Quote
I think we may need some lateral thinking here.


I'll take any kind of thinking right now, lateral or otherwise.

Mark Thomas on the CADalog board suggested using grread and at first glance it didn't help, but a friend over on the AutoDESK boards came up with something quite different.  So here's the latest attempt, it has a couple of bugs with small viewports or moving the cursor too fast:


Code: [Select]

(setq dvsdeep 12.0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun DVSection (/ pt1 pt2 ang)
(command ".undo" "begin")
(if (= (getvar "cvport") 1)
  (command ".mspace")
)
(command "ucs" "v")
     (setq pt1 (getpoint "\nSelect Centerpoint of Section: "))
     (setq ang (getangle pt1 "\nEnter Viewing Point Angle from Section: "))
     (setq curvp (getvar "cvport"))
     (setq pt2 (polar pt1 ang 12))
(IF (SETQ Ndvsdeep (GETDIST (STRCAT "Enter Depth of Section: <" (RTOS dvsdeep) ">: ")))
(setq dvsdeep ndvsdeep)
)
  (setq pt1 (trans pt1 1 0) pt2 (trans pt2 1 0))
  (command "ucs" "w")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; the following by ruul morawetz

(defun rm:cvpc ( / grrd weida p pold viewsize trigger)
  (setq weida T
          viewsize (getvar "VIEWSIZE")
           trigger (* viewsize 0.1)
  )

(while weida (setq grrd (grread T))
  (cond
    ((= 5 (car grrd)) (setq p (cadr grrd))
  (cond
    ((and pold (> (distance p pold) trigger)) (setq weida nil) ) ) (setq pold p) ) ((= 2 (car grrd))(setq weida nil)) (T nil ) )
) ;;end while
) ;;end defun



(prompt "\n Select Viewport for Section Display (ENTER if necessary then) ")
(rm:cvpc)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
   (command "dview" "" "po" pt1 pt2 "cl" "f" (/ dvsdeep 2.0) "cl" "b" (- 1.0 (/ dvsdeep 2.0)) "")
   (command ".zoom" "e" ".zoom" ".8x")
(setvar "cvport" curvp)
(command ".undo" "end")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:dvs () (command ".undo" "begin")(dvsection)(command ".undo" "end"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

CADaver

  • Guest
Changing current viewport in the middle of a routine.
« Reply #16 on: December 06, 2003, 09:36:38 AM »
Thanks to Ruul Morawetz on another forum.  I thought you guys may like to see this.

Code: [Select]
;------------------------------------------------------------------
; original from CADaver with help from Mark Thomas
; modifications and viewport change function by ruul morawetz
; requires UNDO on
; v0.4 last edit 03/11/24
;------------------------------------------------------------------
(setq *dvsdeep* 12.0) ; default section depth
;------------------------------------------------------------------
(defun c:dvs ( / *error*)

   (defun *error* (msg)
      (cond
         (msg (command)(command)(princ (strcat "\nError: " msg)))
         (T nil)
      )
      (dvs:restore)
      (if msg (command "_u"))
   )
   (defun dvs:save ( / n)
      (setq *dvs* nil)
      (command "_undo" "_begin")
      (foreach n '("CMDECHO" "WORLDVIEW" "UCSFOLLOW" "EXPERT")
         (setq *dvs* (cons (cons n (getvar n)) *dvs*))
      )
   )
   (defun dvs:restore ()
      (foreach n *dvs*
         (setvar (car n) (cdr n))
      )
      (command "_undo" "_end")
   )
   (dvs:save)
   (if (not *dvsdeep*) (setq *dvsdeep* 12.0))
   (dvs:section)
   (*error* nil)
   (prin1)
)
;------------------------------------------------------------------
(defun dvs:section (/ pt1 pt2 ang Ndvsdeep)
   (setvar "EXPERT" 5)
   (setq curvp (getvar "cvport"))
   (command "_ucs" "_s" "__TMP")
   (command "_ucs" "_v")
   (cond
      ((null (setq pt1 (getpoint "\nSelect Centerpoint of Section: "))))
      ((null (setq ang (getangle pt1 "\nEnter Viewing Point Angle from Section: "))))
      ((null (setq pt2 (polar pt1 ang 12))))
      ((null  
         (if (setq Ndvsdeep
            (getdist (strcat "Enter Depth of Section: <" (rtos *dvsdeep*) ">: ")))
            (setq *dvsdeep* Ndvsdeep) T)))

      (T
         ;(command "_.undo" "_begin") ; moved to calling function
         (setq pt1 (trans pt1 1 0) pt2 (trans pt2 1 0))
;        (command "_ucs" "_w") ; moved down

         (prompt "\n Select Viewport for Section Display (ENTER if necessary then) ")
         (dvs:rm:cvpc)     ; vp-change function (possibly unreliable)
         ;(getstring)  ; simple and works

         (setvar "WORLDVIEW" 1)
         (setvar "UCSFOLLOW" 0)
         (command "_ucs" "_w") ; moved here (only necessary after viewport change)
         (command "_.dview" "" "_po" "_non" pt1 "_non" pt2 "_cl" "_f" (* *dvsdeep* 0.5) "_cl" "_b" (- 1.0 (* *dvsdeep* 0.5)) "")
         (command "_.zoom" "_e" "_.zoom" ".8x")
         (setvar "cvport" curvp)
         (command "_ucs" "_r" "__TMP" "_ucs" "_d" "__TMP")
      )
   )
)
;------------------------------------------------------------------
; ruul 03/11/11 - Crazy ViewPort Change
; adjust trigger if needed
; endless loop until clicked in another viewport
; if trigger isn't sufficient, enter also breaks the loop
(defun dvs:rm:cvpc ( / grrd weida p pold viewsize trigger)
   (setq weida T viewsize (getvar "VIEWSIZE")
         trigger (* viewsize 0.4)) ; adjust factor according to mouse speed etc
   (while weida
      (setq grrd (grread T )) ;(+ 1 2 4 8) 2
      (cond
         ((= 5 (car grrd))
            (setq p (cadr grrd))
            (cond
               ((and pold (> (distance p pold) trigger))
                  (setq weida nil)
               )
            )
            (setq pold p)
         )
         ((= 2 (car grrd))(setq weida nil))
         (T nil
         )
      )
   )
)
;------------------------------------------------------------------
(princ  "\nDVSection loaded. call with DVS. ")
;------------------------------------------------------------------
(prin1)
;------------------------------------------------------------------