Can't execute a plugin twice

On 01/10/2013 at 11:44, xxxxxxxx wrote:

I'm trying to create a CommandData plugin.
It is running fine the first time I choose it from the plugins menu.
The dialog appears and, when I press OK, it does its work and then it closes.
But, when I try to execute it a second time, I get an error in the console.
Something like this:

TypeError: Execute expected bool, not None

I'm following a code sample that I found here, called "ResBasedMenuPlugin.pyp"
What could be wrong?

Rui Batista

On 01/10/2013 at 13:02, xxxxxxxx wrote:

no code no proper answer.

CommandData.Execute() doesn't seem to return the correct return value type in all cases.
C4d does expect a boolean indicating the success of the command. None is the return value
type for void alike methods in python.

> def foo() :
> pass
> def moo() :
> return None
> print foo()
> print moo()
> >> None
> >> None

On 01/10/2013 at 13:18, xxxxxxxx wrote:

My code is like this:

class my_plugin(plugins.CommandData) :

dialog = None

def Execute(self, doc) :
        if self.dialog is None:
            self.dialog = my_dialog()

return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=256, defaulth=150, xpos=-1, ypos=-1)

def RestoreLayout(self, sec_ref) :
        if self.dialog is None:
           self.dialog = my_dialog()

return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)

On 01/10/2013 at 13:19, xxxxxxxx wrote:

That name sounds like my code. I have a plugin using that name.
At the time. I used to call GeDialog plugins "menu" plugins. Because they were launched from the plugins menu.
But I stopped using that naming scheme. Because it can be easily confused with sub menu plugins.
And could also possibly get confused with CommandData plugins too.

If it is my code that you're looking at. It was actually for a GeDialog plugin that uses the .res file.
Something that we don't have any examples of from Maxon.
It's not for a CommandData plugin.

Without seeing your code. It's hard to say what's causing the problem in your plugin.
But as a comparison example that might possibly be realted. In the old COFFEE 9.6 SDK examples. There's a plugin called "AsyncBounce.cof" that also has the same problem where it only runs once.
The problem in that old coffee example is coming from the "RestoreLayout" code.
When that code is removed. It runs fine no matter how many times you run it.
I remember how surprised I was when I found the culprit. It wasn't a very obvious error that would jump out at you when looking at the code.

Without seeing the code. It's really hard to help.


On 01/10/2013 at 13:26, xxxxxxxx wrote:

Yes, I believe it is your code, Scott.
And yes, I'm using a .res file to create my dialog.
I will try deleting the RestoreLayout code and see if it works.
Isn't this RestoreLayout stuff for the case of a docked interface that gets saved in a layout?

Rui Batista

On 01/10/2013 at 13:29, xxxxxxxx wrote:

Nope... even without the RestoreLayout stuff, it still returns the same error :-(

Is there any frameword for a CommandData plugin that uses .res files to create a dialog around?

Rui Batista

On 01/10/2013 at 13:45, xxxxxxxx wrote:

I have one posted on my plugins site:
In the python section. Called "Dialog Using Resources".


On 01/10/2013 at 13:48, xxxxxxxx wrote:

Thank you, Scott. But it is for C++. Isn't there anything available for python?

On 01/10/2013 at 14:03, xxxxxxxx wrote:

Scroll down.
There's a python plugins section below the C++ plugins section.

That reminds me. I gotta update that website.
It's pretty ugly.


On 01/10/2013 at 14:32, xxxxxxxx wrote:

Ok, ok... found it.

My Execute code had a tab too much. Damn! the whole problem was just a tab.
Thank you for all the help.

On 01/10/2013 at 15:00, xxxxxxxx wrote:


Been there. Done that. Got the T-Shirt.
I like Python a lot. But that tabbed spacing stuff is a royal P.I.T.A. And burned me more times than I care to admit.
After dealing with a few spacing errors like that. You don't mind typing {} braces in other languages anymore.


On 01/10/2013 at 17:40, xxxxxxxx wrote:

It does help to use a proper editor which can enforce PEP8 rules to your code. It won't
be able to fix really fundamental formatting syntax errors, but most of them. PEP8 are
the official python code formatting guidelines ( x = foo(y=5) instead of x = foo(y = 5) 
for example).

There also many (unofficial) branches specifically fitted into the various editors / IDEs.
Eclipse does come with some rock solid PEP8 enforcing, personally I am using SublimeText3

There is also CodeIntel for ST3 which can highlight various (possible) code problems for you,
including PEP8 violations.

On 02/10/2013 at 06:30, xxxxxxxx wrote:

I do have an excellent editor. I use Sublime Text 2.
This is one of those errors that can only be attributed to me. Code that could be executed nevertheless was only being executed if a condition was true.

Rui Batista

On 02/10/2013 at 08:28, xxxxxxxx wrote:

Not sure which version of Sublime supports it, but version 3 or even version 2 has an option to use
spaces instead of tabs. You won't have this problem when using tabs only, and sublime will automatically
convert tabs to spaces with the right options.


On 02/10/2013 at 08:35, xxxxxxxx wrote:

Sublime Text 2 can convert spaces into tabs and vice-versa.
And I always use tabs, instead of spaces :-)
However, when I copy/paste code from the SDK pages, sometimes the pasted code comes with spaces. But I always convert spaces to tabs.

On 02/10/2013 at 10:00, xxxxxxxx wrote:

All three links work with ST2/.3 The first link is the original PEP8 Autoformat script, which is kind 
of the official python autoformat and will obviously work on any text file. Link two and three are 
specific ST2/3 plugins.

I like autoformatting and I think it is a good idea to follow PEP8, considering the way python 
does define its syntax. CodeIntel also adds things like some sort of intellisense, displaying your 
classes and methods with its docstrings and parameters in the autocomplete dropdown. You can 
also hook it up with the great fake c4d lib from here :

About spaces and tabs, I think it is actually a PEP rule to use spaces ( edit : just looked it up, it is 
not a  rule, it is just a guideline, but still worth following for various reasons imho). With an editor 
like ST you won't recognize any difference in the workflow, as you can just use tab like you are 
used to.