View Full Version : Setting focus to viewport

05 May 2008, 10:13 PM
Is there a way to set focus to the viewport after executing a script? I'm having an issue after i run a collect and select script where after i run it, i'm allowed to navigate through a scene, but keyboard short cuts aren't working.

Example, i collect all the boxes in the scene using a collection line, and then select them. I am allowed to navigate through the scene, but i'm not able to switch to wireframe mode etc, or zoom in on selected.

The only way i've been able to solve this problem is clicking in the viewport, which usually makes me lose the items i've just selected.

Here's the code i am using, if it also helps, i'm running Draster's switcher as well.


global CollectRollout

try( destroyDialog CollectRollout)catch ()

rollout CollectRollout ""
edittext CollectBoxText fieldWidth:120 offset:[0,10]
groupBox CollectGroup "search" pos:[5,0] width: 145 height:40
button CloseButton "x" pos:[160, 2] width:14 height:14

on CloseButton pressed do DestroyDialog CollectRollout

on CollectBoxText entered txt do
if txt != "" do

with undo on
MultipleNodes = for o in objects where matchpattern pattern:("*"+CollectBoxText.text+"*") collect o

select MultipleNodes

CollectBoxText.text = ""





createdialog CollectRollout pos:[38,1003] width:175 height:40 align:#left style:#( #style_sysmenu,#style_resizing) modal:false escapeEnable:true lockHeight:true lockWidth:true


Has any one else come across this problem?


05 May 2008, 10:49 PM
viewport.activeviewport = N

Sets the active viewport to the Nth view, but whether that restores hotkey usage as well...

05 May 2008, 10:53 PM
unfortunately, at least on my machine, it appears it does not.

05 May 2008, 03:40 PM
It appears that i have to simulate a right click, then a left click in order to get my keyboard shortcut's back.

I have this code from dotNet given to me by a friend, excuse my ignorance, but how would i incoporate it into my MXS?

public class MakeAClick{

static extern bool SetCursorPos(int X, int Y);

[DllImport("user32.dll", SetLastError=true)]
public static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 cButtons, UInt32 dwExtraInfo)

public enum MouseEventFlags
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010


SetCursorPos(10, 50);

CGTalk Moderation
05 May 2008, 03:40 PM
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.