PDA

View Full Version : C++ API Set Attribute


theyoda3
09-27-2010, 10:15 PM
Okay, I hope this is a simple question. How do I set the value of a plug's attribute using the C++ API? The current method I am using is Plug.setValue() or Plug.setFloat() etc. The plug I am setting the value on is an input plug, so my thought is that if I change the input value the node will re-evaluate. Using either API call, the input value does indeed change, but the node never updates or re-evaluates its output value. I have established a dependent relationship between the input and the output. Also, the MEL command setAttr works just fine.

Thanks,
Chris

Robert Bateman
09-28-2010, 03:47 PM
Okay, I hope this is a simple question. How do I set the value of a plug's attribute using the C++ API? The current method I am using is Plug.setValue() or Plug.setFloat() etc.

That's correct. Historically it was just setValue, but due to python bindings they added explicit setFloat etc methods.


The plug I am setting the value on is an input plug, so my thought is that if I change the input value the node will re-evaluate.

Not at all. It's a pull system, not a push system! It will only re-evaluate next time the output value is requested. a getAttr "Node.Output" will force the evaluation....

theyoda3
09-28-2010, 04:43 PM
The documentation suggested that dirty propagation was push and node evaluation was pull, which is why I thought changing the input would cause a re-evaluation if I have an input affects output relationship.

Anyways, based on what you said I should be able to set the input value, then get the output value and the node should re-evaluate, but this does not work. I used the following calls in succession:

PlugInput.setValue( inputValue);
PlugOutput.getValue( OutputValue );

Any suggestions?

Thanks,
Chris

theyoda3
09-28-2010, 07:08 PM
Let me just add that PlugOutput.getValue( OutputValue ) does cause the node to re-evaluate, but only when it is called within the main thread. Is there a method to force node evaluation outside of the main thread, such as an asynchronous thread?

Thanks,
Chris

Keilun
09-28-2010, 08:31 PM
The documentation suggested that dirty propagation was push and node evaluation was pull, which is why I thought changing the input would cause a re-evaluation if I have an input affects output relationship.

Dirty is push yes.
Eval is pull.

This means that the dirty flag will propagate out when you change the input based on the AttributeAffects dependencies and connections. But there is a difference between being a dirty plug and evaluating a dirty plug. A dirty plug will not evaluate until something requests it (which is the pull based system that the Eval is based on).

Let me just add that PlugOutput.getValue( OutputValue ) does cause the node to re-evaluate, but only when it is called within the main thread. Is there a method to force node evaluation outside of the main thread, such as an asynchronous thread?

It's been a while, but last I checked you cannot interface with the DG system asynchronously. Once you have control inside your node for the compute() call, you're able to thread whatever computations/eval you want to do in there, but you cannot ask the DG to eval asynchronously. It is a single-threaded system.

theyoda3
09-28-2010, 11:01 PM
Can you force node evaluation outside of the main thread, but in a user callback function or does a callback function work just like an asynchronous thread?

CGTalk Moderation
09-28-2010, 11: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.