Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/03/2009 at 05:29, xxxxxxxx wrote:
User Information: Cinema 4D Version: 10.5 Platform: Mac OSX ; Language(s) : C.O.F.F.E.E ;
--------- Hello,
This is a COFFEE MenuPlugin. Status is a global variable. The aim is to toggle status everytime the plugin gets executed. Like this, the script works and outputs:
0 -> 1 1 -> 0 0 -> 1
But if I change the end of the first line to status = 1; the output gets weird:
1 -> 0 1 -> 0 1 -> 0
> Toggle::Execute(doc) \> { \> if (status == NULL) status = 0; \> print(status); \> status = !status; \> println(" -> " + tostring(status)); \> } Changing status = !status; to
Toggle::Execute(doc) \> { \> if (status == NULL) status = 0; \> print(status); \> status = !status; \> println(" -> " + tostring(status)); \> }
> if (status == 0) status = 1; else status = 0; does not help either.
if (status == 0) status = 1; else status = 0;
Any help would be appreciated. Thanks
On 05/03/2009 at 05:46, xxxxxxxx wrote:
hi, can't confirm. should work and works fine. could you post a little bit more code?
On 05/03/2009 at 07:26, xxxxxxxx wrote:
Where do you store the status variable?
Once a Menu plugin is executed its "gone", afaik.
Cheers Lennart
On 05/03/2009 at 08:03, xxxxxxxx wrote:
This is the whole code:
> var PLUGIN_ID = 1000160; \> \> class Toggle : MenuPlugin \> { \> var status; \> \> public: \> Toggle(); \> \> GetID(); \> GetName(); \> GetHelp(); \> Execute(doc); \> GetState(); \> } \> \> Toggle::Toggle() \> { \> super(); \> } \> \> Toggle::GetID() \> { \> return PLUGIN_ID; \> } \> \> Toggle::GetState() \> { \> return CMD_ENABLED; \> } \> \> Toggle::GetName() \> { \> return "Toggle"; \> } \> \> Toggle::GetHelp() \> { \> return "Read the manual :)"; \> } \> \> Toggle::Execute(doc) \> { \> if (status == NULL) status = 1; \> print(status); \> if (status == 0) status = 1; else status = 0; \> println(" -> " + tostring(status)); \> } \> \> main() \> { \> Register(Toggle); \> }
var PLUGIN_ID = 1000160; \> \> class Toggle : MenuPlugin \> { \> var status; \> \> public: \> Toggle(); \> \> GetID(); \> GetName(); \> GetHelp(); \> Execute(doc); \> GetState(); \> } \> \> Toggle::Toggle() \> { \> super(); \> } \> \> Toggle::GetID() \> { \> return PLUGIN_ID; \> } \> \> Toggle::GetState() \> { \> return CMD_ENABLED; \> } \> \> Toggle::GetName() \> { \> return "Toggle"; \> } \> \> Toggle::GetHelp() \> { \> return "Read the manual :)"; \> } \> \> Toggle::Execute(doc) \> { \> if (status == NULL) status = 1; \> print(status); \> if (status == 0) status = 1; else status = 0; \> println(" -> " + tostring(status)); \> } \> \> main() \> { \> Register(Toggle); \> }
On 05/03/2009 at 08:16, xxxxxxxx wrote:
But when you have executed the MenuPlugin, there is no storage of your "status" variable anymore. Thus, each time you execute, status will be NULL and therefor be set to you pre defined value of 1.
To store the "status" you'd need a unique ID (Plugin Cafe ID) so you can store it in the object you have active (Using that ID).
(Unless I have missunderstood what you want to do)
On 05/03/2009 at 08:40, xxxxxxxx wrote:
By object, do you mean Cinema 4D objects, like a cube? This should be object-independent.
But why does replacing the execute method by the snippet from my very first post works?
On 05/03/2009 at 10:36, xxxxxxxx wrote:
The scope of a MenuPlugin class variable should be the entire session of Cinema 4D. Your main problem is that you don't 'initialize' 'status' at any time (like in Toggle::Toggle() perhaps?). Execute() only gets called when the plugin is executed and, as noted, 'status' is always 'reinitialized'.
Checking this out, yes, I'm correct. Make these changes:
> var PLUGIN_ID = 1000160; \> \> class Toggle : MenuPlugin \> { \> var status; \> \> public: \> Toggle(); \> \> GetID(); \> GetName(); \> GetHelp(); \> Execute(doc); \> GetState(); \> } \> \> Toggle::Toggle() \> { \> super(); \> status = 0; \> } \> \> Toggle::GetID() \> { \> return PLUGIN_ID; \> } \> \> Toggle::GetState() \> { \> return CMD_ENABLED; \> } \> \> Toggle::GetName() \> { \> return "Toggle"; \> } \> \> Toggle::GetHelp() \> { \> return "Read the manual :)"; \> } \> \> Toggle::Execute(doc) \> { \> println(tostring(status) + " -> " + tostring(!status)); \> status = !status; \> } \> \> main() \> { \> Register(Toggle); \> }
var PLUGIN_ID = 1000160; \> \> class Toggle : MenuPlugin \> { \> var status; \> \> public: \> Toggle(); \> \> GetID(); \> GetName(); \> GetHelp(); \> Execute(doc); \> GetState(); \> } \> \> Toggle::Toggle() \> { \> super(); \> status = 0; \> } \> \> Toggle::GetID() \> { \> return PLUGIN_ID; \> } \> \> Toggle::GetState() \> { \> return CMD_ENABLED; \> } \> \> Toggle::GetName() \> { \> return "Toggle"; \> } \> \> Toggle::GetHelp() \> { \> return "Read the manual :)"; \> } \> \> Toggle::Execute(doc) \> { \> println(tostring(status) + " -> " + tostring(!status)); \> status = !status; \> } \> \> main() \> { \> Register(Toggle); \> }
On 05/03/2009 at 16:44, xxxxxxxx wrote:
Robert, your code works for what I want. But the first line in the console is nil -> 1 So the initialization method has not been executed. I included a println in the constructor to check it out and no, there is no output from this println.
On 05/03/2009 at 16:58, xxxxxxxx wrote:
nil = 0 (since COFFEE is typeless, it interprets 0-NULL-nil as the same thing). Notice that after 'status' is established as an integer, it prints 0 instead.
The constructor would be called before the Console window even exists I think. Since there is no Init() method in MenuPlugin, the constructor is the place to initialize the 'status' variable but I donot know if println() would work there.
On 05/03/2009 at 17:02, xxxxxxxx wrote:
Quote: Originally posted by kuroyume0161 on 05 March 2009 > > * * * > > nil = 0 (since COFFEE is typeless, it interprets 0-NULL-nil as the same thing). Notice that after 'status' is established as an integer, it prints 0 instead. > > The constructor would be called before the Console window even exists I think. Since there is no Init() method in MenuPlugin, the constructor is the place to initialize the 'status' variable but I donot know if println() would work there. > > > * * *
Ah, ok that makes perfect sense. Thanks for clearing things up!