PDA

View Full Version : help please with python node inside xpresso


MohamedSakr
08-08-2012, 02:34 PM
hi :)
it's my very first post here in this forums but i think people here can help me with this problem
yesterday i dled the R14 demo version and tested the new xpresso and found that in all my xpresso setups the iterator node is pretty slow/time consuming node

so i thought about using python node instead of iterator node ...used the ( for i in range)
but the problem it's only accepting last output :D
when i print it gives me all range i want...but as an output in xpresso only 1 output..

here's what i want

assume i got 2 plane objects...with same number of vertices(441 for example)
what i do with iterator is iterate from 0 to 440 then pass this to point index and do what i want for each point to point work

(for example i can do offset vectors via math node + point vector for each point)

if this can be done in coffee tell me :D (or python)

NiklasR
08-08-2012, 04:09 PM
Hello and welcome.

You can't use a Python Node as an iterator. Think about it twice, and then you'll understand. :)
This is an image I've done as an answer on the same question in a german forum:

http://www7.pic-upload.de/18.08.11/4fhjdw7btt1c.jpg

Cheers,
Niklas

mayajunky
08-08-2012, 06:11 PM
Well... not to say you can't do an iteration loop within the python node based on an input. In other words you can pass in the total point count, and use that as the condition for the loop. It may just be that it appears to only return one value per frame ( in a results node output ), the last value returned from the loop, but it's still running through the iteration loop every frame. You can print output values to the console within the loop ( at the end up the loop ) to see all your actual output values. Correct me if I'm wrong. :)
My understanding is the same behavior is observable when using an iteration node. It's just that the results node isn't going to display ( written to an array ) all the values returned from the loop, just the last value returned.

Oh okay after re-reading your post I see it's printing as expected. You should just have to have a second output variable then... You add up your index within the loop, and then pass that index value to your point node? That way you have the index position and associated values all being passed together...440 times per frame...or what whatever. ( You'd have to reset the index to zero after the loop ends, to be re-initialized for the next frame. I think... )

Hmm wait, maybe scratch all that! Now I see. So what Niklas is saying in a vague and cryptic way is that the python node executes as many times as the loop needs. ( within the node ) But the xGroup is only executing once per frame? Which explains why you only get one operation based on the final output value? ( trying to learn more about implementing python via xpresso here myself!! ) Why is it the iterator node is able to output mutliple values, and run multiple operations per xpresso tag read then?

Wouldn't be an issue if you handled all the manipulation within the python node I assume. In other words doing all your vector math within the loop, as well as updating the point position values of the object?

MohamedSakr
08-08-2012, 10:51 PM
hmm :D
as i expected thought there's a solution :(
so is there a way to excute the python node N times in a single frame step?
like this if no solution xpresso needs a total remake (ICE in softimage doesnt have this problem and thats why it can support giga polygons inside of it(pretty fast iterations like inside python))

MohamedSakr
08-10-2012, 10:52 AM
so here's another question
if i want to make a python( node family ) ...i mean by ( node family ) that i can pass data from node to node (for example if i make an array inside python..then pass that array into integer output it gives last array value only)
i want to make custom output for an array value(like real or integer want to make array :D)
using script or anything but how it can be done...i sense xpresso modifications using these python nodes is very limited (as Maxon said about the new xpresso performance view .....

{Enabling the Performance View will display the required calculation time for each Node (i.e., the most calculation-intensive Nodes will have a red title bar). This function can be used to locate Nodes that will take long to calculate so they can be replaced with optimized XPressions.})

i think maxon is making fool of people...who needs real update(so i can know what node is laggy and i dont have a choice to change it by python or coffee like iterator node)

douwe
08-10-2012, 01:54 PM
pass that array into integer output it gives last array value only)
i want to make custom output for an array value(like real or integer want to make array

Mohamed,

I think it's a very interesting mission, exploring how to optimize your xpresso setups, replacing nodes that are performing poorly with bits of python.

One advice: You always get more out of a topic if you narrow it down to one specific question, preferably accompanied by a scene file that illustrates a problem simplified to its essentials. That will make it a lot easier for others to chime in and give concrete answers. If you get lucky someone even "fixes" your scene file for you to study.

Now, without getting to the core of your quest, but maybe closing in on a bit of insight :
You know you can use an "InExcludeList"- Input and Output Port on a Python node, right ?
In other words: you can pass complete arrays from one node into the other.

You can check out a nice example by Joel Dubin / Tim Clapham in xpresso setup help for Tracer: get trace link list (http://forums.cgsociety.org/showpost.php?p=6992970&postcount=18) (http://forums.cgsociety.org/showpost.php?p=6992970&postcount=18)
Maybe this is useful to you.

d

MohamedSakr
08-10-2012, 05:33 PM
well thanks d for this file :)
will test it and tell u my feedback/calculation times :D
:bounce:

MohamedSakr
08-14-2012, 08:08 PM
so here's what i did
i put this code in a python tag and it worked...(didn't work in python xpresso node though,or actually i didn't know how to pass the object data to the python node so it reads its point positions in that node)

import c4d
from c4d import documents
from c4d import Vector


def main():

A = doc.SearchObject("Object 1")
B = doc.SearchObject("Object 2")
pointsA = A.GetAllPoints()
pointsB = B.GetAllPoints()
V = Vector(0,10.0,0)
for index, p in enumerate(pointsB):
p = pointsA[index] + V
pointsB[index] = p
B.SetAllPoints(pointsB)

B.Message(c4d.MSG_UPDATE)

main()

frame rate wasn't decent but was quite higher than the normal xpresso work...(xpresso frame rate was 3 FPS at 6k vertices on each object....python tag was 11 FPS at 102k vertices at each object)

any help on how to pass the object data using xpresso python node :)

edit: didn't know how to adjust the tab space to appear in the forums though its wrote in the post copy paste code :D
for loop ends after pointsB[index] = p

MohamedSakr
09-04-2012, 04:02 PM
up !!

so any one can advice me how to pass the data inside xpresso instead of using python tags
and why it worked in python tag and didn't work inside xpresso python node

douwe
09-04-2012, 04:52 PM
Maybe I misunderstand you,
but it seems to work here :

http://www.mediafire.com/conv/e619d6fbae209e8707a00e6c45f3dce968d0a9b553f51a710ee71f6868333a366g.jpg

http://www.mediafire.com/view/?y4so3fusmx8ym7p

MohamedSakr
09-05-2012, 12:02 AM
well thanks D for the reply :D
actually the strange thing i did the same setup !!
except when i checked it i find that u removed the output port and i forgot that ...somehow that output port was making it buggy and not reacting :)
now it works..thanks again

MohamedSakr
09-08-2012, 02:29 AM
so here's a new question :D
i want to import numpy which is an array functions
how to do this i tried sys.append then import but it didn't work
(note that i'm still new to python + the cinema4d is working difference with python than other online documents :D)

MohamedSakr
09-08-2012, 05:01 PM
well here's the latest thing that i could do :D
a friend of mine who know python told me how to use cinema4d python to install that library

it should work but when i call it ..it's not working but the message is kinda promising

import c4d
import numpy

after that i go to console and here's the message

__init__ line 127

"""Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there."""
any idea how to call that module (i tried parent directory but it didn't recognize numpy)

CGTalk Moderation
09-08-2012, 05:01 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.