Keystroke to xpresso with python?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  04 April 2013
Keystroke to xpresso with python?

Is it possible to feed boole values to xpresso using python node when key on keyboard is pressed during animation?
 
  04 April 2013
it is possible. however, you might run into some problems, as python nodes tend to be
a bit tricky. the following snippet checks if F9 is pressed while an animation is running.

import c4d
from c4d import gui

def main():
    global output
    output = False
    bc = c4d.BaseContainer()
    if c4d.CheckIsRunning(c4d.CHECKISRUNNING_ANIMATIONRUN  NING):
        if gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_F9, bc):
            output = bc[c4d.BFM_INPUT_VALUE]

Last edited by littledevil : 04 April 2013 at 02:55 PM.
 
  04 April 2013
Originally Posted by littledevil: it is possible. however, you might run into some problems, as python nodes tend to be
a bit tricky. the following snippet checks if F9 is pressed while an animation is running.

import c4d
 from c4d import gui
 
 def main():
     global output
     output = False
     bc = c4d.BaseContainer()
     if c4d.CheckIsRunning(c4d.CHECKISRUNNING_ANIMATIONRUN  NING):
         if gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_F9, bc):
             output = bc[c4d.BFM_INPUT_VALUE]



Unfortunately I don't know anything about python and I wasn't able to make it work. I want to make this setup to use arrows on keyboard to drive some values in xpresso.
 
  04 April 2013
create a python node, delete all ports, add 4 boolean output ports named
isup, isdown , isleft, isright. check the execute only once per frame check-
box. the ports will be true when the key respective arrow key is pressed
while the timeline is playing.

ps: the general approach is a really bad idea (reading key strokes from
within a python node to manipulate the document) and will most likely end
in a mess.


def main():
    global isup, isdown , isleft, isright
    isup, isdown , isleft, isright = False, False, False, False
    
    bc = c4d.BaseContainer()
    if c4d.CheckIsRunning(c4d.CHECKISRUNNING_ANIMATIONRUN    NING):
        if gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_UP, bc):
             isup = bc[c4d.BFM_INPUT_VALUE]
        if gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_DOWN, bc):
             isdown = bc[c4d.BFM_INPUT_VALUE]
        if gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_LEFT, bc):
             isleft = bc[c4d.BFM_INPUT_VALUE]
        if gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_RIGHT, bc):
             isright = bc[c4d.BFM_INPUT_VALUE]
 
  04 April 2013
Thanks littledevil. Arrows seems to work ok when you hover mouse over python window but You're right, it's problematic, maybe numpad?
 
  04 April 2013
the polled key channel has nothing to do with it. the whole gvnode stuff hasn't
been made for stuff like that. the channel is actually being red correctly, but c4d
struggles to update the gvnode tree for some unknown reason.

here is stripped version which only polls up and down and prints the result to the
console and also passes it to the output variables. you will see the state is red and
printed properly by python, no matter where your mouse pointer is.

import c4d
from c4d import gui

def main():
    global isup, isdown , isleft, isright
    isup, isdown , isleft, isright = False, False, False, False
    
    bc = c4d.BaseContainer()
    if gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_UP, bc):
        if bc[c4d.BFM_INPUT_VALUE]:
            isup = True
            print 'Up'
    if gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.KEY_DOWN, bc):
        if bc[c4d.BFM_INPUT_VALUE]:
            isdown = True
            print 'Down'


trying to fix such things is always somehow possible in one more or less hacky way,
but you have to do it yourself and it is not worth the effort in most cases. just as an
example on how flawed xpresso is . 1. create any xpresso setup you want. 2. remove
all viewports from your layout. 3 Yeah, right, xpresso just stopped working.

describe your problem what you are after and i think there will be another solution.
 
  04 April 2013
I have this idea of driving animation by pressing keyboard keys. I know a little bit of xpresso so naturally i thought of driving some xpresso setup by keyboard.
Up and down arrows slow down animation to unusable speed, left and right works ok, so i thought keys have something to do with it. I was searching web for keys names but no luck.
 
  04 April 2013
executing such code/logic from a frame dependent node (xpresso, tag) will always cause
problems. c4d shows here its very outdated general approach. a possible solution which
could be called somewhat clean would be to write 4 scripts and then simply bind the up,
down, left and right keys to these scripts in the customize commands window.

however there will be still the problem that the arrow keys are already bound for most
windows in c4d (the same goes for the numpad arrows). so you would have to use other
keys (there are not many unbound single key combinations left). as a fix you could use
dialogs and/or a plugin, but things will get more complicated here.

not sure if it is worth all the effort, i think a simple viewport rig would e almost as simple to
use and much easier to be set up.
 
  04 April 2013
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:01 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.