[Closed] How to get full viewport's height
Hi,
Does anyone know how to get the full viewport’s height?not only the active viewport,I mean, the full viewport?
(
function GetVptSizeY =
(
local curMaxVptSize = 0
curlay = viewport.getLayout()
if curLayout != #layout_1 then
(
actview = viewport.activeViewport
viewport.setLayout #layout_1
curMaxVptSize = gw.getWinSizeY()
viewport.setLayout curLayout
viewport.activeViewport = actview
)
else curMaxVptSize = gw.getWinSizeY()
--
curMaxVptSize
)
GetVptSizeY()
)
hi maiuu,I got error after run your code.
>> MAXScript FileIn Exception: – Runtime error: The function needed argument of type: #layout_1 | #layout_2v | #layout_2h | #layout_2ht | #layout_2hb | #layout_3vl | #layout_3vr | #layout_3ht | #layout_3hb | #layout_4 | #layout_4vl | #layout_4vr | #layout_4ht | #layout_4hb, got: undefined <<
Get the handle of the viewpanel window and use pinvoke to GetClientRect. There are many examples on this forum.
O forgot to rename one of the variables. Fixed.
(
function GetVptSizeY =
(
local curMaxVptSize = 0
curLayout = viewport.getLayout()
if curLayout != #layout_1 then
(
actview = viewport.activeViewport
viewport.setLayout #layout_1
curMaxVptSize = gw.getWinSizeY()
viewport.setLayout curLayout
viewport.activeViewport = actview
)
else curMaxVptSize = gw.getWinSizeY()
--
curMaxVptSize
)
GetVptSizeY()
)
Yeah,worked,too many thanks.
I just wondering is there another way to do that without maximize viewport?I did myself several days below before this thread approved:
(
screen_snap=0
Fn Capture_screen=
(
max tool maximize
snap_a=getViewSize()
snap_a_y=snap_a[2] as integer
max tool maximize
snap_b=getViewSize()
snap_b_y=snap_b[2] as integer
if snap_a_y>snap_b_y then screen_snap=snap_a_y else screen_snap=snap_b_y
)
)
also need maximize the viewport,image it,if a scene is big enough,if we have to maximize the viewport to get the height,swithing viewport from normal to maximize would be slow,right?so if there is a direct way to get the height would be better
there is no any right function shown in this thread. no one works if … for example current view is an Extended Viewport (TrackView, etc.)
Quickest way ( but somewhat dirty and costly) to get the viewpanel size ( with the border outline already cropped )
function GetViewpanelSize=
(
bm=ViewPanelManager.GetActiveViewPanelDib()
[ bm.width-4 , bm.height-4 ]
)
Edit: of course you could use the bitmap for the whole snapshot too already…
Requires Max 2013 and up though …
fn createAssembly =
(
str="using System;
"
str+="using System.Runtime.InteropServices;
"
str+="namespace Win32Helper
"
str+="{
"
str+="public class User32
"
str+="{
"
str+=" public struct RECT { public int Left; public int Top; public int Right; public int Bottom; }
"
str+=" [DllImport(\"user32.dll\")]
"
str+=" private static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
"
str+=" public int[] GetWindowRect(IntPtr hWnd) {
"
str+=" RECT rect;
"
str+=" if (GetWindowRect(hWnd, out rect)) {
"
str+=" return new int[4] {rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top };
"
str+=" } else return null;
"
str+=" }}}
"
local csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
local compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.add "System.dll"
compilerParams.GenerateInMemory = on
local compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(str)
compilerResults.CompiledAssembly.CreateInstance "Win32Helper.User32"
)
global user32 = createAssembly()
fn getViewpanelRect =
(
local maxHwnd = windows.getMaxHwnd()
for w in windows.getChildrenHwnd maxHwnd parent:maxHwnd where w[4] == "ViewPanel" do
(
local r = ::user32.getWindowRect (dotnetObject "System.IntPtr" w[1])
return box2 r[1] r[2] r[3] r[4]
)
)
btw, if you are using max2014, you can just use
windows.getWindowPos
instead of the c# assembly.
correct… but needs a little tweak … box2.width-4 and box2.height-4… but how can we be sure that 4 is the right number?