How to get full viewport's height


#6

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

:beer:


#7

Read post #3.


#8

there is no any right function shown in this thread. no one works if … for example current view is an Extended Viewport (TrackView, etc.) :wink:


#9

it’s almost correct… but needs a little tweak. :wink:


#10

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 …


#11

ViewPanelManager? what max version is it?


#12

It was introduced with Max2013…


#13

what does it do if the active view is 0? (any extended viewport)


#14
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.


#15

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?


#16

oh! at long last! :slight_smile:


#17

here is my version:


fn windowRectAssembly =
(
	source  = "using System;
"
	source += "using System.Runtime.InteropServices;
"
	source += "class User32
"
	source += "{
"
	source += "		[DllImport(\"user32.dll\", EntryPoint=\"GetWindowRect\")]
"
	source += "		static extern bool GetWindowRect(IntPtr hWnd, out POS rect);
"
	source += "		struct POS
"
	source += "		{
"
	source += "			public int Left;
"
	source += "			public int Top;
"
	source += "			public int Right;
"
	source += "			public int Bottom;
"
	source += "		}
"
	source += "		public int[] GetWindowRect(Int64 hWnd)
"
	source += "		{
"
	source += "			POS rect;
"
	source += "			if (GetWindowRect((IntPtr)hWnd, out rect))
"
	source += "			{
"
	source += "				return new int[] { rect.Left, rect.Top, rect.Right, rect.Bottom };
"
	source += "			}
"
	source += "			return new int[4];
"
	source += "		}
"
	source += "}
"

	csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
					
	compilerParams.GenerateInMemory = true
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
	((compilerResults.CompiledAssembly).CreateInstance "User32").GetWindowRect
)
global getWindowRect = windowRectAssembly()

fn getMaximumViewSize = 
(
	local vp_hwnd = for c in (windows.getchildrenhwnd #max) where c[4] == "ViewPanel" do exit with c[1]
	
/*
	s = getWindowRect vp_hwnd
	[s[3]-s[1]-4, s[4]-s[2]-4] -- not stricly enough because of this (-4)
*/
	
	local xs = #(), ys = #()
	for c in (windows.getchildrenhwnd vp_hwnd) where c[4] == "Label" do 
	(
		s = getWindowRect c[1]
		join xs #(s[1], s[3])
		join ys #(s[2], s[4])
	)
	[amax xs, amax ys] - [amin xs, amin ys]
)
getMaximumViewSize()


#18

Well, that depends on what the OP is trying to achieve… I just thought they want the size of the viewpanel.


#19

You’ll be surprised to hear that they even exposed SetWindowPos


#20

he asked about maximum size of viewport. it’s what getViewSize returns for maximized view.


#21

wow! so wide expanse opens for rookies.


#22

I’ve test ,works like a charm.thanks


#23

you even can set the viewpanel to any arbitrary size via script now ( at least in Nitrous), totally independent from the application window dimensions

nitrousgraphicsmanager.PinViewPanelSize <integer>width <integer>height
nitrousgraphicsmanager.UnpinViewPanelSize()

or the whole application window

nitrousgraphicsmanager.SetAppWindowSize <integer>width <integer>height
nitrousgraphicsmanager.SetAppWindowPos <integer>x <integer>y

And there’s

nitrousgraphicsmanager.BackgroundProgressiveRenderingEnabled  <bool>

now…
But i’m sure nobody has any use for this, especially not PowerPreview users :wink:

what does it do if the active view is 0? (any extended viewport)

It simply captures the whole viewpanel DIB region.
Meaning you can’t really use it for viewport captures (as i suggested above), becuase you always would get overlapping max windows with this capture method. But for viewpanel size info it’s enough


#24

oh! how much the max was littered in recent times…


#25

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.