Python Plugin with Rhino Script Compiler

does the mtexture plugin on the Food4Rhino page work with V6 Windows, and V6 Mac WIP ? tia :slight_smile:

Hello world!

I am new here and I do not know if I am asking in the right place and way. Here goes my question:

I have 3 python scripts:

  • BaseScript.py
  • Command1.py
  • Command2.py

When I use them inside the Rhino Python Editor, everything works. But if I compile them as a plugin (MyNewPythonPlugIn.RHP), they do not work. Well, Command2 works without problem, but the BaseScript does not. Name command appears, but nothing happens. Of course, I can see plugin in the plugins list and I can see commands as well. I am using Rhinoceros Script Compiler 2013 (I think it is the lastest version).

One comment: I want Command1.py to be a “Type: Hidden”. For this reason, Command1.py hasn’t the typical bottom code line: if name == ‘main’:

Thanks a lot for your help!

MyNewPythonPlugIn.rhp (8.5 KB)
BaseScript.py (317 Bytes) Command1.py (111 Bytes) Command2.py (225 Bytes)

Hello again!
I think the problem is the compiler, that doesn’t support this feature.
Let’s see if next upload comes with this.
Thanks anyway for your great job

AFAIK, this code in the bottom doesn’t make your command “hidden” you simply cannot execute it if directly running that script, you need additional code to invoke it.

Hello!
Thanks for your help, Ivelin.

Obviously, I did not explain myself very well, because you did not understand my explanations.

My plugin is a way to explore the possibilities of Rhino.Pyton. Then, I compiled 3 scrips in the same RHC. One of them (callwd Command1) was compiled as a “hidden command”. Then, it will be no visible for anybody in the list of commands available in plugin and Rhino line command. For this reason, I think this command does not need the bottom line, because it will be impossible to be used as an independent command. But some definitions that are inside of that command will be called from BaseScript. I do no know if I am right. Comments are all welcome. Thanks agains.

For better understanding, just see code in py files. They are very small files (7 or 8 lines od code).

the init.py is inside the package folder not outside it. Sorry I’m not yet that good in all that package module thingy

Hi @pau.natividad, that is correct. The RhinoScriptCompiler does not support the use of module files.

It is a long time wish of many users. Unfortunately the compiler has not been touched for a long time. I hope that @stevebaer someday finds some time to include it.

_
c.

does it support if you access package in a relative location of where that plugin is installed?

No. In order to use a function from a module, the module file needs to have this line:

if __name__=="__main__":
    SomeFunctionToCall()

If you include this, the module itself will not compile. But you need this in a module file, otherwise it is executed whenever the module is imported from another function.

_
c.

Thanks a lot!
Anyway, if my commands work fine in the Rhino Python Editor, I think structure and modules are well programmed, right?

Hi @pau.natividad,

i would include this code at the end of your 2 module files Command1.py and Command2.py:

if __name__=="__main__":
    print "This module cannot be run independently"

_
c.

In theory executing a python script is nothing more than executing the string inside it.

You can create a plugin using the code coming from a string or the python file embedded as base64 string.

I experimented with this a bit last year, and succeeded.
The RhinoScriptCompiler creates the Csharp files, if you can put them inside a project and modify them a bit you’ll get the behavior you expect. :wink:

CS/PY hybrid plugin. :smiley:

btw, if you put the IronPython code inside try:except: block, it will be virtually impossible to decompile.

Imho, executing a compiled python script is a different thing. Many of the rules with relative paths and variable scope do not apply. But if you can show how to circumvent it, especially when you update a rhi plugin installation and the compiler creates folders you cannot now the version naming from, it would be useful.

_
c.

yeah, I didn’t mean using the compiler for compiling the python plugin, just to generate the AssemblyInfo.cs file :wink:

The other compiling will happen with VisualStudio (or other alternatives)

Hey Ivelin,

How did you manage to get around the python module restriction? could you share what you had to do in the C# files to get it to work?

Thanks,
Best regards

Hi @Victor_malek ,

It’s been so long time ago. What do you mean by “python module restriction”?

Hi Ivelin,

The fact that the python script cannot be used a modules in the script compiler. However, the new script compiler appears to be able to handle this now (Rhino 8). Thanks though!

Victor

Hi @Victor_malek, really ? Did you try this with Python 3 or IronPython scripts ?
_
c.

testing it now but I had a call with Pedro from McNeel and the new script compiler will be able to handle both Python 3 and IronPython scripts with modules.

2 Likes