Notifications
Clear all

[Closed] How to get the coordinates of the window frame ?

How to get the coordinates of the current window frame ?
And the creating of “Rectangle” on the coordinates.

Requests master help to answer, thanks ~

6 Replies

-- creates a rectangle around current orthographic viewport
(
 TM =viewport.getTM()
 p = mapScreenToView [0,0] 0.0
 rWidth = abs(2 * p[1])
 rLength = abs(2 * p[2])
 r = rectangle pos:[0,0,0] width:rWidth length:rLength corner_radius:(rWidth/10.0)
 r.transform = inverse TM
)

cheers

Thank you ~ Decon
How to get the coordinates of the currew frame of “camera” and “Perspective” ?
Requests master help to answer, thanks ~

where do you want it in space (or how big) ?


-- creates a rectangle around current  viewport
(
 TM = getViewTM()
 viewPt = TM.row4
 p = mapScreenToView [0,0] viewPt.z
 rWidth = abs(2 * p[1])
 rLength = abs(2 * p[2])
 r = rectangle pos:[0,0,0] width:rWidth length:rLength corner_radius:(rWidth/10.0)
 r.transform = inverse TM
 r.pos = [0,0,viewPt.z] * r.transform
)

one solution, dont ask more …

Thank you ~ Decon ~

I know how to creates the rectangle.
I have made a exercises.
Records the coordinate,
And uses “viewport.setTM <matrix3>” restore viewport coordinates,
But why “Top” , “Front” and so on,
the 2D viewport can not restore it?

Requests master help to answer, thanks ~


TM = getViewTM()
viewport.setTM  TM

well, at View menu, there is Save Active View option. Maybe you could use that . With script it might start up something like this:


-- First get current viewport values
  --Returns the active view size as point2 in pixels
  vSize = getViewSize()
  
  -- gives construction plane world coords at viewport corners
  p1 = mapScreenToCP [0,0]
  p2 = mapScreenToCP vSize
  
  -- scale factor
  ssf = getScreenScaleFactor [0,0,0]
  
  vWidth = abs((p2-p1).x)
  vHeight = abs((p2-p1).y)
--------------------------------------------------
-- move and/or zoom the viewport ....
--------------------------------------------------
-- after that, restore earlier values
 
-- first the zoom:
  ssf_new = getScreenScaleFactor [0,0,0]
  zoomFactor = ssf / ssf_new
  viewport.zoom zoomFactor
 
-- then other transforms:
  p1_new = mapScreenToCP [0,0]
  xVal = (p1_new - p1).x
  yVal = (p1_new - p1).y
  
  xVal = xVal / vWidth * vSize.x
  yVal = -yVal / vHeight * vSize.y
  
  viewport.pan  xVal yVal
  completeRedraw()
 

hope that gives some ideas

Thanks for your answers, it’s good for me.