Python Plugin with Rhino Script Compiler

@gerard.guell, very sorry, after testing this on my system i see the same as you got, even when i install the plugin with the built Rhi installer when Rhino is closed. The plugin gets installed and loaded in V5 and V6 but nothing happens when running the command, my loading message is printed though.

Please take a look into this folder:

C:\Users\YourUserName\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins

Do you find (multiple) versions of your plugin there ?

@stevebaer, has the RhinoScriptCompiler (current version) been tested recently ? I’ve even tried to reference the x64 RhinoCommon.dll but get the same result. Does the plugin below load on your end (V5 or V6) and does the included HolaCommand prompt for a point ?

MyHolaPlugin.rhp (7 KB)
HolaCommand.py (200 Bytes)

_
c.

@gerard.guell,

i got the attached working, above posted python script was missing the imports. I’ve removed this:

if __name__=="__main__":
    Hola2()

and just called the function in below python file using:

HolaCommandTest()

while compiling it i had RH5 closed. The registered command is HolaCommand. Does it work on your end too ?

HolaCommand.py (249 Bytes)
MyHolaPlugin.rhp (7 KB)

_
c.

Hello @clement, thank you very much fore the new code, it works perfectly now!

Then the issue was only that I need to have RH5 closed when compiling the plug-in using the RhinoScriptCompiler?

Hi @gerard.guell, it could have been one of the issues if you where trying to write to a plugin which has been in use. Glad it works now on your end.

_
c.

Hi @clement or anybody else having experience with this,

I’m trying to create a RHI installer for the first time and get stuck. I’ve been going over the steps on this page 3 times but seem to miss something fundamental. Even when I just try to create the exact example they provide I get “An unexpected error has occurred during installation.” when trying to install. Anybody that can give me a clue here?

test.rhi (681 Bytes)

Hi @siemen, i never used this way to compile my scripts to a plugin as it failed for various reasons. If you want to have full control over (multiple) commands in one plugin, i would recommend to use the RhinoScriptCompiler for it.

Your script would then just look like below, the RunCommand structure is not required and you do not have to append _cmd to your script file name.

def MyFunctionName():
  print "Hello World"
  # get a point
  point = rs.GetPoint("Pick a point")
  if point:
    rs.AddPoint(point)
# call it 
MyFunctionName()

The command name it registers upon installation will be the name of the python script file, eg. If you name it MakePoint.py the command is called by typing MakePoint to the command line.
_
c.

1 Like

I see, does that work for v6 as well? Might give it a go

@pascal or @will, since your names are on the page I’m trying to use, could you help out and see what I’m doing wrong? If not just so that others don’t run into the same problem as I am.

Yes it works. If you’re experiencing any problems with it just post here or in the thread linked above.

_
c.

It worked thanks a lot!

Still, (not towards you, clement) I think it might be worth checking what I did wrong when I was following along the steps on the developers website. To find out whether I did something wrong (and what?) or something is wrong/not obvious with the steps described there.

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?