Author Topic: How to calculate correct "ViewCenter/X"for viewport with TwistAngle  (Read 2168 times)

0 Members and 1 Guest are viewing this topic.

kruuger

  • Swamp Rat
  • Posts: 635
Hello,

I'm trying to calculate new values: "ViewCenter/X" and "ViewCenter/Y" for viewport with TwistAngle different than 0.

How lisp is working:
- user select a viewport in paper space,
- next step is to enter distance to shift left or right, lat say 1"
- next we can transfer center of viewport to modelspace with awesome gile routines PCS2WCS.

Problem is that PCS2WCS returns point in WCS but to function:
Code: [Select]
(setpropertyvalue Ename "ViewCenter/X" Value)we need to pass point, which includes TwistAnlge, points needs to be set to proper "viewport UCS".
When playing in model space we usually use
Code: [Select]
(getvar "UCSXDIR")but how about in this case, when we are in paperspace?


Hope i'm clear.
Thanks
kruuger

tombu

  • Bull Frog
  • Posts: 289
  • ByLayer=>Not0
Re: How to calculate correct "ViewCenter/X"for viewport with TwistAngle
« Reply #1 on: February 25, 2022, 08:13:41 AM »
Link to gile's PCS2WCS routine → http://www.theswamp.org/index.php?topic=29231.msg347755#msg347755

My functional but not complete Twist Viewport function that works in both MS or PS. It turns on, unlocks & thaws the viewport layer and thaws it's layer in the viewport if needed from either a picked or entered angle. Got to find time to clean up a few of these.
Code: [Select]
(defun c:TWistVP (/ *error* cmdecho nomutt cvport ang→ angbase snapang ss ent vpno ok viewtwist tilemode
VpLayFrz VpLayer VpLayEnt VpLayLst VpLay70 LayLckFrz matchang acDoc ActiveVport VpLock NotLock elist)

(defun SelVPobj ()
  (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
  (setq cmdecho (getvar 'cmdecho) ; Not saved, No command prompts = 0
nomutt (getvar 'nomutt) ; default = 0
tilemode (getvar 'tilemode) ; Model tab = 1 Layouts = 0
cvport (getvar 'cvport) ; Layout's PS = 1 MS default = 2
ang→ (getvar 'angdir) ; My default = 0 Counterclockwise
angbase (getvar 'angbase) ; My default = 0
viewtwist (getvar 'viewtwist)
  )
  (princ "\nang→ = ")(princ ang→)
  (princ "\nangdir = ")(princ (getvar 'angdir))
  (setvar 'angdir 1)
  (princ "\nangdir = ")(princ (getvar 'angdir))
  (setvar 'angbase 0)
  (setvar 'cmdecho 0)
  (vla-put-mspace acDoc :vlax-true) ; equal (command "._mspace")
  (setq ActiveVport (acet-currentviewport-ename)
               VpLayer (cdr (assoc 8 (entget ActiveVport)))
               VpLayEnt (tblobjname "layer" VpLayer)
               VpLayLstOrg (entget VpLayEnt)
               VpLayLst VpLayLstOrg
               VpLay70 (cdr (assoc 70 VpLayLst))
               VpLayCol (cdr (assoc 62 VpLayLst))
               LayLckFrz (boole 1 5 VpLay70)
  )
  (if (= cvport 1) ; Paper Space not in Viewport
    (progn ; (= cvport 1) In Layout Paper Space
      (if (< VpLayCol 0)(setq VpLayLst (subst (cons 62 (abs VpLayCol)) (assoc 62 VpLayLst) VpLayLst)))
      (if (> LayLckFrz 0)(setq VpLayLst (subst (cons 70 (- VpLay70 LayLckFrz)) (assoc 70 VpLayLst) VpLayLst)))

      (entmod VpLayLst)
          (vla-put-mspace acDoc :vlax-false) ; equal (command "._pspace")
      (setq ss (ssget "x" (list (cons 0 "VIEWPORT") '(68 . 1) (cons 69 (getvar "CVPORT")) (cons 410 (getvar "ctab"))))
            ActiveVport (ssname ss 0)
            ActiveVport (acet-currentviewport-ename)
            VpLayFrz (acet-viewport-frozen-layer-list ActiveVport)
      )
      (if VpLayFrz (foreach n VpLayFrz (command-s "vplayer" "Thaw" n "" "")))
      (vla-Regen acDoc acActiveViewport)
;      (entupd ActiveVport)
      (setvar "nomutt" 1)
      (prompt "Select boundary of Viewport: ")
      (or (setq ss (ssget ":E:S" '((0 . "VIEWPORT")))) ;Boundary selected
        (progn ;Boundary Not selected
          (setq ss (ssget "x" (list (cons 0 "VIEWPORT") '(68 . 1) (cons 69 (getvar "CVPORT")) (cons 410 (getvar "ctab"))))
                ActiveVport (ssname ss 0)
          )
          (setvar 'cvport (cdr (assoc 69 (entget ActiveVport)))) ;do I need this?
        ) ;progn
      ) ; or
      (setvar "nomutt" 0)
      (setq ActiveVport (ssname ss 0))
      (vla-put-mspace acDoc :vlax-true) ; equal (command "._mspace")
;      (setvar 'cvport (cdr (assoc 69 (entget ActiveVport))))
    ) ;progn ; (= cvport 1) In Layout Paper Space

    (progn ; (/= cvport 1) In Layout Model Space
      (setq ActiveVport (vlax-vla-object->ename (vla-get-activepviewport acDoc))
            ok  T
      ) ;setq
    ) ;progn ; (/= cvport 1) In Layout Model Space
  ) ;if (= cvport 1)

;|  (setq ActiveVport (vla-get-ActivePViewport acDoc)
        VpLock (vla-get-DisplayLocked ActiveVport)
  )
  (if (equal :vlax-true VpLock)
        (vla-put-DisplayLocked ActiveVport :vlax-false)
        (setq NotLock 1)
  ) ;if (equal :vlax-true VpLock) |;
  (if (> LayLckFrz 0)(setq VpLayLst (subst (cons 70 (- VpLay70 LayLckFrz)) (assoc 70 VpLayLst) VpLayLst)))
  (entmod VpLayLst)
;  (setvar 'snapang (getangle "\nPick or enter TWist angle : "))
; Angles that are passed to getangle are based on ANGDIR and ANGBASE current settings, once provided it's counterclockwise radians ignoring ANGDIR & ANGBASE.
;           (setvar 'angdir ang→)
;           (setvar 'angbase angbase)
;           (vla-put-twistAngle ActiveVport (-(getvar 'snapang)))
;           (setvar 'angdir ang→)
  (entmod VpLayLstOrg)
  (princ)
) ; defun SelVPobj

  (setq acDoc (vla-get-activedocument (vlax-get-acad-object))
tilemode (getvar 'tilemode) ; Model tab = 1 Layouts = 0
  )
  (vla-startundomark acDoc)
  (princ "\ntilemode = ")(princ (getvar 'tilemode))
  (princ "\ntilemode = ")(princ tilemode)
  (if(= 0 tilemode)(SelVPobj))
  (setq ActiveVport (vla-get-ActivePViewport acDoc)
        VpLock (vla-get-DisplayLocked ActiveVport)
  )
  (if (equal :vlax-true VpLock)
        (vla-put-DisplayLocked ActiveVport :vlax-false)
        (setq NotLock 1)
  ) ;if (equal :vlax-true VpLock)
  (princ "\ntilemode = ")(princ (getvar 'tilemode))
  (princ "\nangdir = ")(princ (getvar 'angdir))
  (princ "\nang→ = ")(princ ang→)
; Angles that are passed to getangle are based on ANGDIR and ANGBASE current settings, once provided it's counterclockwise radians ignoring ANGDIR & ANGBASE.
      (cond
       ((= 0 tilemode) ; on Layout
           (setvar 'snapang (getangle "\nPick or enter TWist angle : "))
; Angles that are passed to getangle are based on ANGDIR and ANGBASE current settings, once provided it's counterclockwise radians ignoring ANGDIR & ANGBASE.
           (setvar 'angdir ang→)
           (setvar 'angbase angbase)
           (vla-put-twistAngle ActiveVport (-(getvar 'snapang)))
           (setvar 'angdir ang→)
   (entmod VpLayLstOrg)
         ) ;(= 0 (getvar 'tilemode))
       ((= 1 tilemode) ; on Model tab
         (setvar 'snapang (getangle "\nPick or enter TWist angle : "))
         (setvar 'angdir ang→)
         (command "_.dview" "all" "" "_tw" (/(*(-(getvar 'snapang))180)pi) "")
       ) ;(= 1 (getvar 'tilemode)) ; on Model tab
      ) ;cond
        (if (= cvport 1)
  (progn
            (vla-put-mspace acDoc :vlax-false) ; equal (command "._pspace")
    (if VpLayFrz (foreach n VpLayFrz (command-s "vplayer" "Freeze" n "" "")))
;     (acet-viewport-frozen-layer-list-set ActiveVport VpLayFrz)
  )
        ) ;if (= cvport 1)
      (setvar 'angdir ang→)
      (setvar 'cmdecho cmdecho)
      (or (= NotLock 1)(vla-put-DisplayLocked ActiveVport :vlax-true))
  (vla-endundomark acDoc)
  (princ)
;  (*error* nil)
)
« Last Edit: February 25, 2022, 08:17:38 AM by tombu »
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: How to calculate correct "ViewCenter/X"for viewport with TwistAngle
« Reply #2 on: February 25, 2022, 08:27:36 AM »
This should be fine...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:centerofviewportpan ( / *error* cmde ucsf adoc vp vc cp cn )
  2.  
  3.   (vl-load-com) ;;; load AciveX extensions (VLA functions) ;;;
  4.  
  5.   (defun *error* ( m )
  6.     (if ucsf
  7.       (if command-s
  8.         (command-s "_.UCS" "_P")
  9.         (vl-cmdf "_.UCS" "_P")
  10.       )
  11.     )
  12.     (if (= 8 (logand 8 (getvar 'undoctl)))
  13.       (if command-s
  14.         (command-s "_.UNDO" "_E")
  15.         (vl-cmdf "_.UNDO" "_E")
  16.       )
  17.     )
  18.     (if cmde
  19.       (setvar 'cmdecho cmde)
  20.     )
  21.     (if m
  22.       (prompt m)
  23.     )
  24.     (princ)
  25.   )
  26.  
  27.   ;;; PRESETTINGS ;;;
  28.  
  29.   (setq cmde (getvar 'cmdecho))
  30.   (setvar 'cmdecho 0)
  31.   (if (= 8 (logand 8 (getvar 'undoctl)))
  32.     (vl-cmdf "_.UNDO" "_E")
  33.   )
  34.   (vl-cmdf "_.UNDO" "_G")
  35.   (if (= 0 (getvar 'worlducs))
  36.     (progn
  37.       (vl-cmdf "_.UCS" "_W")
  38.       (setq ucsf t)
  39.     )
  40.   )
  41.  
  42.   ;;; MAIN ;;;
  43.  
  44.   (if (= (getvar 'tilemode) 0)
  45.     (if (or (not (setq vp (car (entsel "\nPick Viewport in Paper Space...")))) (and vp (= (cdr (assoc 0 (entget vp))) "VIEWPORT")))
  46.       (progn
  47.         (vla-put-activePviewport adoc (vlax-ename->vla-object vp))
  48.         (vl-cmdf "_.UCS" "_V")
  49.         (setq vc (getvar 'viewctr))
  50.         (setq cp (trans vc 1 3))
  51.         (vl-cmdf "_.PSPACE")
  52.         (initget 1)
  53.         (setq cn (getpoint cp "\nPick or specify translation point of center of picked VIEWPORT : "))
  54.         (vla-put-activePviewport adoc (vlax-ename->vla-object vp))
  55.         (setq cn (trans cn 3 1))
  56.         (vl-cmdf "_.PAN" "_non" cn "_non" vc)
  57.         (vl-cmdf "_.UCS" "_P")
  58.         (vl-cmdf "_.PSPACE")
  59.       )
  60.     )
  61.     (alert "Please go to Paper Space and start routine again... Type : (setvar 'tilemode 0) ...")
  62.   )
  63.   (*error* nil)
  64. )
  65.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kruuger

  • Swamp Rat
  • Posts: 635
Re: How to calculate correct "ViewCenter/X"for viewport with TwistAngle
« Reply #3 on: February 28, 2022, 07:29:39 AM »
hello guys
thanks for codes.

@tombu not sure what exactly your code should do.

@marko error at line - 1st image

i would like to avoid "command".
quick and sharp point translation from paper, thru twisted viewport (TwistAngle) - 2nd image


is there any way to do this without activating viewport (no paper->model->paper flickering)
thanks

kruuger

  • Swamp Rat
  • Posts: 635
Re: How to calculate correct "ViewCenter/X"for viewport with TwistAngle
« Reply #4 on: October 12, 2022, 05:06:03 PM »
Hi,

I'm little closer, with this matrix function from Lee - http://www.lee-mac.com/matrixtransformationfunctions.html
After new point npt is calculated, we need to use matrix from Lee, but...it is still not enough :(
Code: [Select]

 (setpropertyvalue
      (car vp)
      "ViewCenter/Y"
      (cadr
        (car
          (LM:RotateByMatrix
            (list (PCS2WCS npt vp_vla))
            (list 0.0 0.0 0.0)
            (getpropertyvalue (car vp) "TwistAngle")
          )
        )
      )
    )
  )

Working on viewport splitter (lot of calculation to set correct view ViewCenter/X and ViewCenter/X). Works ok, until someone will messed up with camera (image view.png).
When we dump VIEWPORT we can see some values for Target and Direction (image target dir.png)

Is there any expert who knows how to include Target/Direction in calculation (for ViewCenter/X and ViewCenter/Y) or maybe reset those values for viewport?
Short video attached - left ok, right no :(

thanks
kruuger
« Last Edit: October 12, 2022, 05:18:32 PM by kruuger »

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: How to calculate correct "ViewCenter/X"for viewport with TwistAngle
« Reply #5 on: October 13, 2022, 12:23:03 AM »
Just stab in the dark...

Have you tried :

Code - Auto/Visual Lisp: [Select]
  1.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kruuger

  • Swamp Rat
  • Posts: 635
Re: How to calculate correct "ViewCenter/X"for viewport with TwistAngle
« Reply #6 on: October 13, 2022, 05:14:52 AM »
Just stab in the dark...

Have you tried :

Code - Auto/Visual Lisp: [Select]
  1.  

hello Marco,

zoom won't help. i think we need to fix target and direction, but without affecting current view in viewport.
code below fixed target/direction but view was broken.
Code: [Select]
      (vla-Put-Target vp
                      (vlax-make-variant
                        (vlax-safearray-fill
                          (vlax-make-safearray vlax-vbDouble '(0 . 2))
                          '(0 0 0)
                        )
                      )
      )
      (vla-Put-Direction vp
                         (vlax-make-variant
                           (vlax-safearray-fill
                             (vlax-make-safearray vlax-vbDouble '(0 . 2))
                             '(0 0 1)
                           )
                         )
      )
kruuger

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8704
  • AKA Daniel
Re: How to calculate correct "ViewCenter/X"for viewport with TwistAngle
« Reply #7 on: October 13, 2022, 05:28:09 AM »
maybe look at the express tools alignspace source for guidance

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: How to calculate correct "ViewCenter/X"for viewport with TwistAngle
« Reply #8 on: October 14, 2022, 02:30:14 AM »
Just not sure what your after, you can dimension in paperspace but pick objects in world ?
A man who never made a mistake never made anything

kruuger

  • Swamp Rat
  • Posts: 635
Re: How to calculate correct "ViewCenter/X"for viewport with TwistAngle
« Reply #9 on: October 15, 2022, 05:40:09 AM »
maybe look at the express tools alignspace source for guidance
thanks. reviewing lsp file now. there are acet functions used. will see if i can reuse something.
kruuger