Jump to content
Alexey Vanzhula

position and size of current viewport

Recommended Posts

Guest mantragora

I don't get what you are asking. You want to know viewport position and it's pane information or do you want information about GU_Detail processed currently by viewport on the level you are at?

EDIT: OK. One fresh drink later and I get what you are asking about ;). Probably it's possible, the question is where you want to access this information? in the viewport hook or in the node? Why do you need this?

EDIT2: There are couple RE_Window classes (with NT, OSX, X letters for each system) that deals with windows but it's nothing that will give you information with one method. It's typical low level window management stuff you can find in any GUI framework.

Edited by mantragora

Share this post


Link to post
Share on other sites
Guest mantragora

#include <RE\RE_window.h>

auto list = r->getWindowList();
auto wincount = list->getNumWindows();
cout << wincount << endl;

auto i = 0;
while (i < wincount)
{
   auto currentWindow = list->getWindow(i);

   cout << "[" << currentWindow->getW() << ", " << currentWindow->getH() << "]" << endl;

   i++;
}

With this I can get info how many windows Houdini created. Now, if you have only Houdini open you will get MainWindowSize and ViewportSize. All you have to do is to figure out which is which :D

Share this post


Link to post
Share on other sites
Guest mantragora

One more drink later...

If you add this:

cout << "[" << currentWindow->getX() << ", " << currentWindow->getY() << "]" << endl;

you will get corner (I think top-left) of each window from which you can calculate other corners and your position (and you can because you have W and H already).

If Houdini always creates MainWindow and then Viewport than we can safely assume that the smaller one is a viewport. Maybe there is possibility to get it directly thru some ID check.

Edited by mantragora

Share this post


Link to post
Share on other sites

I work on maya<>houdini pipeline tool and want to snap maya viewport on top of houdini viewport from python script :) So, when maya get focus i want to update its widget geometry

Edited by Alexey Vanzhula

Share this post


Link to post
Share on other sites

Why your example does not work for me?


import inlinecpp

mymodule = inlinecpp.createLibrary(
name='test',
includes="#include <RE/RE_window.h>",
function_sources=[
'''
int windowCount()
{
auto list = r->getWindowList();
auto count = list->getNumWindows();
return count;
}
'''])

print mymodule.windowCount()[/CODE]

what is [b]r[/b] object?

And also forum formatting changed [b]RE/RE_window.h[/b] to [b]RE/RE_window.h[/b]

Edited by Alexey Vanzhula

Share this post


Link to post
Share on other sites
Guest mantragora

I posted parts of the code here so if you can't figure out how I made this to work, here is the rest ;):

https://www.mediafir...8kunl5zvfod28ez

Just press "D" in viewport and activate "DM_WindowData". If you leave this menu open you will get data from three windows.

EDIT: Oh yeah, compile and put it in your "dso" folder.

EDIT2: Oh yeah Two, it's version for C++11, so you need Houdini and compiler version that supports it :), otherwise you need to rewrite it.

Edited by mantragora

Share this post


Link to post
Share on other sites

I dont know how can i use it in python? In HOM i can find current scene viewer, viewport, pane - but how to get render cpp object to use in inlinecpp? :blink:

Edited by Alexey Vanzhula

Share this post


Link to post
Share on other sites
Guest mantragora

/*
Gets Houdini windows information (count, width/height, corner position).

author:
Mantragora 2013.
https://vimeo.com/mantragora
 */

import inlinecpp

mymodule = inlinecpp.createLibrary(
name="viewport_cpp",
includes=
"""
#include &lt;RE\RE_Render.h&gt;
#include &lt;RE\RE_window.h&gt;
#include &lt;ostream&gt;
""",
function_sources=[
"""
void WindowData()
{ 
    // get renderer
    auto render = RE_Render::getMainRender();

    // collect data
    auto list = render-&gt;getWindowList();
    auto wincount = list-&gt;getNumWindows();  
    std::cout &lt;&lt; wincount &lt;&lt; std::endl;

    auto i = 0;
    while (i &lt; wincount)
    {
        auto currentWindow = list-&gt;getWindow(i);
        std::cout &lt;&lt; "Width/Height: " &lt;&lt; "[" &lt;&lt; currentWindow-&gt;getW() &lt;&lt; ", " &lt;&lt; currentWindow-&gt;getH() &lt;&lt; "]" &lt;&lt; std::endl;
        std::cout &lt;&lt; "Corner Position: " &lt;&lt; "[" &lt;&lt; currentWindow-&gt;getX() &lt;&lt; ", " &lt;&lt; currentWindow-&gt;getY() &lt;&lt; "]" &lt;&lt; std::endl;
        std::cout &lt;&lt; "ID: " &lt;&lt; currentWindow-&gt;getWindowID() &lt;&lt; std::endl;

        i++;
    }
    std::cout &lt;&lt; "" &lt;&lt; std::endl;
}

"""])

print mymodule.WindowData()

PS. Remember that f*cking formating changes "Window" to "window" here:

#include <RE\RE_window.h>

Edited by mantragora

Share this post


Link to post
Share on other sites
Guest mantragora

1) Your function is called "test" while you trying to call "windowCount".

2) Change this line to

RE_Render* render = RE_Render::getMainRender();

But if it's not this, I don't know. gcc4.6 should support "auto" keyword.

Edited by mantragora

Share this post


Link to post
Share on other sites

mantragora, you very much helped me.

But you probably not correctly understood a question about viewport.

At now with simple cpp lines i can manage separate (floating) windows. But i need catch info about embedded viewport position\size.

maybe I approached close to the answer :) Still need to find solution

Edited by Alexey Vanzhula

Share this post


Link to post
Share on other sites
Guest mantragora
But i need catch info about embedded viewport position\size.

Than I still don't get it. What you mean by embedded viewport?

Share this post


Link to post
Share on other sites

viewport that in main houdini window - not in floating window.

render->getWindowList() give me all separated windows. Windows with ID=0 (ID in list) is a main houdini window - and i can control it.

But what further? How to get viewport in it?

Sory for bad english.

Share this post


Link to post
Share on other sites
Guest mantragora

Than we need E.D.W.A.R.D od TWOD because I have no idea how to manipulate panes.

Share this post


Link to post
Share on other sites
Guest mantragora

is a panes :)

No it's not. Position 0 in list is a Main window. Position 1 is Viewport, the one you can see your geometry. Any other position there is another window that you open, like the one when you press "D". But you can't manipulate panes with this. Panes split window. You can have multiple panes in window. I don't know how to get them.

But if you need only Viewport size and position you got all the info there, just like I said couple posts ago. Widht/Height and top-left corner is all you need. You just don't get pane this window reside in.

Edited by mantragora

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×