How to detect and activate a running session of Softimage?

64 views
Skip to first unread message

Szabolcs Matefy

unread,
Dec 15, 2011, 8:31:10 AM12/15/11
to soft...@listproc.autodesk.com

Hey folks,

 

I am working on the GoZ for Softimage, I have finished ALMOST everything (real connection, automated process, textures, displacement, normal maps are transferred), but I can’t do one final step:

 

HOW TO ACTIVATE A RUNNING SOFTIMAGE SESSION?! (preferably from a batch file, but if anyone of you guys would help me coding this small piece, it’d be a big help to me J)

 

 

Thanks!

 

 

 

Szabolcs

___
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. Crytek GmbH - http://www.crytek.com - Grüneburgweg 16-18, 60322 Frankfurt - HRB77322 Amtsgericht Frankfurt a. Main- UST IdentNr.: DE20432461 - Geschaeftsfuehrer: Avni Yerli, Cevat Yerli, Faruk Yerli

Juhani Karlsson

unread,
Dec 15, 2011, 8:45:06 AM12/15/11
to soft...@listproc.autodesk.com
Someone help him!!! : ) GoZ sounds neato!

2011/12/15 Szabolcs Matefy <szab...@crytek.com>

Stephen Blair

unread,
Dec 15, 2011, 9:20:54 AM12/15/11
to soft...@listproc.autodesk.com
Use wmic?

wmic process where name="xsi.exe" get ExecutablePath

From: softimag...@listproc.autodesk.com [mailto:softimag...@listproc.autodesk.com] On Behalf Of Szabolcs Matefy
Sent: December-15-11 8:31 AM
To: soft...@listproc.autodesk.com
Subject: How to detect and activate a running session of Softimage?

Hey folks,

I am working on the GoZ for Softimage, I have finished ALMOST everything (real connection, automated process, textures, displacement, normal maps are transferred), but I can't do one final step:

HOW TO ACTIVATE A RUNNING SOFTIMAGE SESSION?! (preferably from a batch file, but if anyone of you guys would help me coding this small piece, it'd be a big help to me :))

winmail.dat

Stephan Woermann

unread,
Dec 16, 2011, 2:43:55 AM12/16/11
to soft...@listproc.autodesk.com
I use this in C++

bool check_run()
{
    PROCESSENTRY32 pe32;
    HANDLE hSnapshot;
    HANDLE hHandle;
    DWORD oPID = 0;
    bool running = false;

    pe32.dwSize = sizeof( PROCESSENTRY32 );
    hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

    if( Process32First( hSnapshot, &pe32 ) )
    {
        do{
            if( strcmp( pe32.szExeFile, "xsi.exe" ) == 0 )
            {
                running = true;
                hHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
                oPID = pe32.th32ProcessID;
                break;
            }
        }while( Process32Next( hSnapshot, &pe32 ) );
    }else{
        running = false;
    }

    CloseHandle(hSnapshot);
    return running;
}

Szabolcs Matefy

unread,
Dec 19, 2011, 2:18:01 AM12/19/11
to soft...@listproc.autodesk.com

Wow,

 

And this will invoke any running session of Softimage? Could compile it to me? I do not have compiler…L

 

 

 

Szabolcs

Stephan Woermann

unread,
Dec 19, 2011, 9:40:25 AM12/19/11
to soft...@listproc.autodesk.com
This only detects a running session, break and returned true, when the first one is found.
hHandle gives you the process handle back. With this you can maybe min/maximize the Softimage-window or bring it to front.

It´s also not a working solution for your problem, but it can give you a hint how you can solve it...

face

Luc-Eric Rousseau

unread,
Dec 19, 2011, 1:22:31 PM12/19/11
to soft...@listproc.autodesk.com

Doesnt that code leak hHandle?

Stephan Woermann

unread,
Dec 19, 2011, 2:24:45 PM12/19/11
to soft...@listproc.autodesk.com
It was only a simple proposal.
This should be better...

bool check_run( HANDLE &hHandle, DWORD &oPID )
{
    PROCESSENTRY32 pe32;
    HANDLE hSnapshot;

   
    bool running = false;

    pe32.dwSize = sizeof( PROCESSENTRY32 );
    hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

    if( Process32First( hSnapshot, &pe32 ) )
    {
        do{
            if( strcmp( pe32.szExeFile, "xsi.exe" ) == 0 )
            {
                running = true;
                hHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
                oPID = pe32.th32ProcessID;
                break;
            }
        }while( Process32Next( hSnapshot, &pe32 ) );
    }else{
        running = false;
    }

    CloseHandle( hSnapshot );
    return running;
}

int main()
{
    HANDLE handle;
    DWORD PID = 0;

    if( check_run( handle, PID ) )
    {
        // fill in your code here //
    }

    CloseHandle( handle );
    return( true );
}

Alokgandhi

unread,
Dec 19, 2011, 8:06:30 PM12/19/11
to soft...@listproc.autodesk.com
IMHO, you don't even need "Handle handle". As you are already calling,

CloseHandle( hSnapshot );

There should be no handle leak.

In your code, you are not using the handle to do anything. If it is just to check whether xsi is running processes, 

strcmp( pe32.szExeFile, "xsi.exe" ) == 0 

is enough. 

You do not need,

 hHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
oPID = pe32.th32ProcessID;

However, if you want maximize xsi, then you do need,

oPID = pe32.th32ProcessID;

Then use,

EnumWnd() with a callback EnumWndProc() to enumerate all windows. In this callback, get the PID using GetWindowsThreadProcessID(), compare this with the oPID and get the Hwnd from this, and pass it to ShowWindow()  to maximise. 

Not a very solid workaround, but might work. Also, it should be noted that a process handle that you can get from OpenProcess() is entirely different from a main window handle, which you need to maximize the main window. To make matter complicated, there is no way in windows to get the main window handle from process id, directly.

The names of the above functions that I use might not be exact as I am not on a windows machine right now, but you can find them on msdn.

Sent from my iPad

Raffaele Fragapane

unread,
Dec 19, 2011, 10:05:40 PM12/19/11
to soft...@listproc.autodesk.com
I have to ask, what do you mean with "activate"?
Just detecting a running process isn't too much work, but taking control of it and running something inside of it isn't as simple as that just having its handle usually.

In Maya you have the server object, in XSI you'll need your own flavour to "talk" to it and get it to do anything. There is an example in the SDK doco/examples for an XSI server that can listen in.

Alternatively, the cheapo work-around is adding a button in XSI that will parse and run the contents of a text file, and writing to that text file from whatever other software (ZB in your case) so it will know what to import and what to do with it, or what to replace in the scene if you want to fake a persistent connection.

Szabolcs Matefy

unread,
Dec 20, 2011, 4:02:43 AM12/20/11
to soft...@listproc.autodesk.com

I’m making the GoZ plugin for ZBrush and Softimage (I made the GoSoftimage Lite), and everything is working so far, but I can’t make automatic activation of Softimage window. (I mean that when I export the tool from ZBrush, I can’t switch automatically to the running session of Softimage)

 

Unfortunately I am not C++ coder, just scripter…

 

Cheers

 

 

Szabolcs

 

 

 

From: softimag...@listproc.autodesk.com [mailto:softimag...@listproc.autodesk.com] On Behalf Of Raffaele Fragapane


Sent: Tuesday, December 20, 2011 4:06 AM
To: soft...@listproc.autodesk.com

Raffaele Fragapane

unread,
Dec 20, 2011, 4:28:56 AM12/20/11
to soft...@listproc.autodesk.com

Well, there is a py friendly win32 lib to help.
No direct experience, as I'm on linux both at home and work, but start here:
http://stackoverflow.com/questions/1007185/how-to-retrieve-the-selected-text-from-the-active-window

jo benayoun

unread,
Dec 20, 2011, 1:36:59 PM12/20/11
to soft...@listproc.autodesk.com
Find the hwnd of the softimage window that you are looking for (can be done by EnumWindows or other ways thru the win32 api) then make a call to SetActiveWindow() which will put the window in front. All can be done with py and ctypes.




2011/12/20 Raffaele Fragapane <raffsx...@googlemail.com>

Alokgandhi

unread,
Dec 20, 2011, 7:11:29 PM12/20/11
to soft...@listproc.autodesk.com
Hey Szabolcs, 

I have compiled up an .exe for you, just run or call it in your plugin and it will maximize any/all open softimage windows. Unfortunately I cannot attach it to my gmail but tomorrow I will send you the link to download it.

Cheers!!

Sent from my iPad

jo benayoun

unread,
Dec 21, 2011, 12:33:15 AM12/21/11
to soft...@listproc.autodesk.com
I dont see how an exe can be more convenient than a dll ... really wierd choice you made Alok ... :D
Anyway, now I'm at home, here is the python code to bring xsi at the front ... nothing more complicated than this little piece of code ... It will bring the first window it finds.
This should work and fit your needs (or needs of someone else, who knows ...) ... Let me know if something wrong happens. I really hope this will help you !
:)
jo


- src -

import ctypes


INT = ctypes.c_int
WIN32 = ctypes.windll.user32
HWND = ctypes.c_void_p


def windowtitle(hwnd):
  getlen = WIN32.GetWindowTextLengthA
  getlen.restype = INT
  getlen.argtypes = (HWND, )

  windtext = WIN32.GetWindowTextA
  windtext.restype = INT
  windtext.argtypes = (HWND, ctypes.c_char_p, INT)
  
  len_ = getlen(hwnd)
  buff = ctypes.create_string_buffer("", len_+1)
  windtext(hwnd, buff, len_ + 2)
  return buff.value


def ew_callback(hwnd, lp):
  if "Autodesk Softimage" in windowtitle(hwnd):
    showwind = WIN32.SwitchToThisWindow
    showwind.restype = INT
    showwind.argtypes = (HWND, INT)
    showwind(hwnd, 1)
  return 1


def raise_xsi():
  proc = ctypes.WINFUNCTYPE(INT, HWND, INT)
  enumwindows = WIN32.EnumWindows
  enumwindows.restype = INT
  enumwindows.argtypes = (proc, INT)
  enumwindows(proc(ew_callback), 0)
  return None


raise_xsi()

-src -

Alokgandhi

unread,
Dec 21, 2011, 1:11:46 AM12/21/11
to soft...@listproc.autodesk.com
Well exe was not defenitely a good choice, I agree. But as as I wanted to have have something cleaner which user can use from a batch process as well, without having to use any code, and no issues of any coding knowledge required. But yeah that's not what I would recommend.

Keep up the good work JB,


PS : Btw, my cpp code has the same exact logic as you are using here, getting title from enumwindows comparing with "Autodesk Softimage" and catching handle from there. :)
Cheers.

Sent from my iPad

Szabolcs Matefy

unread,
Dec 21, 2011, 2:37:56 AM12/21/11
to soft...@listproc.autodesk.com

Hey folks,

 

Thanks for ALLLLL the answers, and the effort you all invested

 

The reason I need an exe, is because I have to call this from ZBrush, and a from a batch file…

 

Thanks anyway!

 

 

 

Szabolcs

Alokgandhi

unread,
Dec 21, 2011, 2:53:54 AM12/21/11
to soft...@listproc.autodesk.com
So I was right in making the exe for you, glad to be of help. Will post the download link tomorrow.

Sent from my iPad

Szabolcs Matefy

unread,
Dec 21, 2011, 3:11:07 AM12/21/11
to soft...@listproc.autodesk.com

Thanks, I really appreciate it! And of course it’ll be a bless to Zbrush and Softimager user community as well :D

 

 

Cheers

 

 

Szabolcs

Stephan Woermann

unread,
Dec 21, 2011, 4:07:55 AM12/21/11
to soft...@listproc.autodesk.com
All in all i don´t know how an application will help you which maximise all running xsi windows.
GoZ should work in booth directions i think. So it is helpfull to know from which session the data is send to ZBrush.
When you send from xsi to zb, i would submit the handle or pid so that you can only maximise/use this xsi session when you send the data back from zb.
When you send from zb to xsi without a source in xsi, the handle/pid should be null, then i would maximise/use the first xsi session to get the data in.

Stephan

Alokgandhi

unread,
Dec 21, 2011, 12:46:49 PM12/21/11
to soft...@listproc.autodesk.com
Szabolcs, you can download the activateSoft.exe here 


Do let me know if you have any problems

Cheers !!

Sent from my iPad

Alokgandhi

unread,
Dec 21, 2011, 1:26:41 PM12/21/11
to soft...@listproc.autodesk.com
Oops added a wrong 'y' at the end of link, here's the right one:



Sent from my iPad

Alokgandhi

unread,
Dec 28, 2011, 3:53:31 PM12/28/11
to soft...@listproc.autodesk.com
Hi Szabolcs, just wondering did the activateSoft.exe worked for you ?

Sent from my iPad

Reply all
Reply to author
Forward
0 new messages