2 Very Basic COFFEE Questions
-
On 17/05/2016 at 13:19, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform: Windows ;
Language(s) : C.O.F.F.E.E ; XPRESSO ;---------
HiI'm very new to scripting, so I apologize in advance for these stupid questions:
1. The default code inside a COFFEE Tag starts with "main(doc,op)" but in the Xpresso COFFEE node it starts only with "main()". I've figured out that the "doc" part is defined as "var doc = GetActiveDocument();" but how is the "op" defined? Also, am I right in my understanding that the "op" refers to the object to which the COFFEE/Xpresso tag is attached?
2. If I understand it correctly, one can use Functions to speed up a script since the code in the "main" part of the script is reduced by using the Function call. Is my understanding that Functions speed up the processing of the script correct or is it used to keep the script clean and uncluttered?
Thank you very much in advance for your help.
-
On 18/05/2016 at 02:41, xxxxxxxx wrote:
Originally posted by xxxxxxxx
1. The default code inside a COFFEE Tag starts with "main(doc,op)" but in the Xpresso COFFEE node it starts only with "main()". I've figured out that the "doc" part is defined as "var doc = GetActiveDocument();" but how is the "op" defined? Also, am I right in my understanding that the "op" refers to the object to which the COFFEE/Xpresso tag is attached?
In a COFFEE tag, "doc" is the active document and "op" is the object the tag is attached to.
In an XPresso COFFEE node, the main() doesn't provide any argument but the "DOC" global variable is defined as the active document. Note there's no "op" variable accessible.Originally posted by xxxxxxxx
2. If I understand it correctly, one can use Functions to speed up a script since the code in the "main" part of the script is reduced by using the Function call. Is my understanding that Functions speed up the processing of the script correct or is it used to keep the script clean and uncluttered?
In fact, using a lot of functions in scripting languages such as COFFEE can slowdown their execution. But using functions helps for better readability and understanding of code.
Please notice that the COFFEE programming language is outdated. You find more possibilities, better documentation and examples in the Python SDK.
-
On 18/05/2016 at 03:22, xxxxxxxx wrote:
Thank you very much for your reply.
Originally posted by xxxxxxxx
Originally posted by xxxxxxxx
1. The default code inside a COFFEE Tag starts with "main(doc,op)" but in the Xpresso COFFEE node it starts only with "main()". I've figured out that the "doc" part is defined as "var doc = GetActiveDocument();" but how is the "op" defined? Also, am I right in my understanding that the "op" refers to the object to which the COFFEE/Xpresso tag is attached?
In a COFFEE tag, "doc" is the active document and "op" is the object the tag is attached to.
In an XPresso COFFEE node, the main() doesn't provide any argument but the "DOC" global variable is defined as the active document. Note there's no "op" variable accessible.I think I maybe wasn't clear in my question. Because there's no "(doc,op)" in the Xpresso COFFEE node, I currently define the "doc" in the main part of the script with "var doc = GetActiveDocument();". Is there not a similar way I can reference the object to which the Xpresso tag is attached? At the moment, I reference it by adding a User Data link field but it would be nice if this wasn't neccessary.
Originally posted by xxxxxxxx
Originally posted by xxxxxxxx
2. If I understand it correctly, one can use Functions to speed up a script since the code in the "main" part of the script is reduced by using the Function call. Is my understanding that Functions speed up the processing of the script correct or is it used to keep the script clean and uncluttered?
In fact, using a lot of functions in scripting languages such as COFFEE can slowdown their execution. But using functions helps for better readability and understanding of code.
Please notice that the COFFEE programming language is outdated. You find more possibilities, better documentation and examples in the Python SDK.
It's a pity that functions won't speed up the code but that's not the end of the world.
-
On 19/05/2016 at 03:21, xxxxxxxx wrote:
Originally posted by xxxxxxxx
I think I maybe wasn't clear in my question. Because there's no "(doc,op)" in the Xpresso COFFEE node, I currently define the "doc" in the main part of the script with "var doc = GetActiveDocument();". Is there not a similar way I can reference the object to which the Xpresso tag is attached? At the moment, I reference it by adding a User Data link field but it would be nice if this wasn't neccessary.
Ok I understand better your question now.
Why do you need to reference the object to which the XPresso tag is attached?Also, you should retrieve the active document from the input object with obj- >GetDocument().
This way the COFFEE node will work as expected while rendering too. -
On 19/05/2016 at 04:08, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Why do you need to reference the object to which the XPresso tag is attached?
Also, you should retrieve the active document from the input object with obj- >GetDocument().
This way the COFFEE node will work as expected while rendering too.Thanks for getting back to me and thanks for the info on the defining of the active document. I will update my existing scripts with that.
To explain why I'd like to reference the "carrier" object, I can give you an example: I have written a script that I use to replace the target tag which allows me to set limits for rotation. I currently have to add the object that carries the tag to a user data link field. Although that's not a train crash, it would be great if I could simply copy the Xpresso tag to another object and it would automatically recognize the new object as the object which it should effect.
-
On 20/05/2016 at 03:04, xxxxxxxx wrote:
A scripting node shouldn't access the active object directly.
A better solution is to add an Object node to the XPresso setup. This node by default links the object that carries the XPresso tag in Relative Reference mode.
The Object node allows to access any of the object properties.
And if the XPresso tag is copied to another object, the Object node references the object the XPresso tag was copied to (Relative Reference). -
On 20/05/2016 at 09:34, xxxxxxxx wrote:
Originally posted by xxxxxxxx
A scripting node shouldn't access the active object directly.
A better solution is to add an Object node to the XPresso setup. This node by default links the object that carries the XPresso tag in Relative Reference mode.
The Object node allows to access any of the object properties.
And if the XPresso tag is copied to another object, the Object node references the object the XPresso tag was copied to (Relative Reference).I can't believe this hadn't occurred to me. Thank you very much. I'll just feed the object node into the input port which I previously used to feed from the user data.
Thanks again.