CGTalk > Software Specific Forums > Maxon Cinema 4D
To minimize the ads you see on this page create a CGTalk account and log in HERE
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 04-09-2013, 01:58 PM   #1
AdsovonMelk
Frequenter
 
AdsovonMelk's Avatar
Grzegorz
Poland
 
Join Date: Apr 2006
Posts: 227
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?
 
Old 04-09-2013, 02:50 PM   #2
littledevil
Meh
 
littledevil's Avatar
portfolio
Ferdinand
Germany
 
Join Date: Aug 2002
Posts: 616
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.

Code:
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-09-2013 at 02:55 PM.
 
Old 04-09-2013, 05:11 PM   #3
AdsovonMelk
Frequenter
 
AdsovonMelk's Avatar
Grzegorz
Poland
 
Join Date: Apr 2006
Posts: 227
Quote:
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.

Code:
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.
 
Old 04-09-2013, 05:36 PM   #4
littledevil
Meh
 
littledevil's Avatar
portfolio
Ferdinand
Germany
 
Join Date: Aug 2002
Posts: 616
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.

Code:
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]
 
Old 04-09-2013, 06:53 PM   #5
AdsovonMelk
Frequenter
 
AdsovonMelk's Avatar
Grzegorz
Poland
 
Join Date: Apr 2006
Posts: 227
Thanks littledevil. Arrows seems to work ok when you hover mouse over python window but You're right, it's problematic, maybe numpad?
 
Old 04-09-2013, 07:40 PM   #6
littledevil
Meh
 
littledevil's Avatar
portfolio
Ferdinand
Germany
 
Join Date: Aug 2002
Posts: 616
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.

Code:
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.
 
Old 04-09-2013, 08:12 PM   #7
AdsovonMelk
Frequenter
 
AdsovonMelk's Avatar
Grzegorz
Poland
 
Join Date: Apr 2006
Posts: 227
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.
 
Old 04-09-2013, 09:03 PM   #8
littledevil
Meh
 
littledevil's Avatar
portfolio
Ferdinand
Germany
 
Join Date: Aug 2002
Posts: 616
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.
 
Old 04-09-2013, 09:03 PM   #9
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 02:36 PM.


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