Python Plugin with Rhino Script Compiler

Dear Community,

hello everyone, im very new to python programming and have my first issue :slight_smile:
i made a plugin with python (works well in the rhino python editor and works well when i copy the py file in the python plugins folder). now i wanted to generate a plugin to distribute. i took the process through the rhino script compiler, everything works well, afterwards its installing the plugin, but when i start rhino, enter the plugin-command (the plugin name appears, i can click it) but after, nothing is happening.
Maybe you have an idea what it could be or maybe i totally forgot something?

thanks a lot for your help. :innocent:
best
michael

@MichaelW,

check first under RhinoOptions / Plugins if your Plugin is properly listed and Loaded. Are all commands listed if you double click the plugin name in the plugin manager ? Did you compile rhp or as rhi file ?

c.

Yes the plugin is properly installed and loaded in the rhino options. All commands are listed. Its compiled as rhi file. Thanks for your help.
Michael

@MichaelW,

can you describe what your script / plugin is supposed to do or post it here so someone can try to compile and reproduce your error ?

c.

the plugin should download texture from an free web texture database (by inserting the url from the chosen texture) and apply it on a surface in rhino. attached you find the rhi file and the raw python file

steps in rhino after installation:
01: commandname: mtextur
02: choose surface
03: insert url from mtextur
04: choose filename of texture which is being saved on C:\mtextur

example url: https://www.mtextur.com/system/materials/images/000/020/512/medium/mtex_20512.jpg?1458434116

thanks a lot

mtextur.zip (11.3 KB)

@MichaelW,

i´ve tested the script and it failed to find rs.GetString.

These imports in your script i do not understand. They will not work / are not required:

import rhinoscript.userinterface
import rhinoscript.geometry
import rhinoscript.userinterface
import rhinoscript.geometry 

But this is required of course:

import rhinoscriptsyntax as rs

Your script used the below line and seems to be a command script:

__commandname__ = "mtextur"

You do not need that to compile or to run.

Are you sure that if your plugin has the same command name, it will be used or will it use the name of the command script ? I would just remove the command script from rhino so there are no conflicts, or use a different command name / script name when compiling it. To make your script run, either from the python editor or a plugin, you have to uncomment this line of course:

RunCommand(True)

I´ve left the removed lines as comments. Try to compile this: mtextur.py (3.8 KB)

c.

1 Like

wow, thanks a lot for the fast respond, i will check it out tomorrow…

perfect! it is working. thanks a lot.

Hello @clement, thank you for all your explanations in this post.

I have the same issue as @MichaelW but I have not been able to resolve them. I have created this trial command which I call “hola2” in which I ask the user to provide a point thru the interface, and the the command adds it.

To create the plug-in, I’m using the RhinoScriotCompiler and I create the files a .rhp

However, once the Plug-in is created, I drag and drop it to Rhino5. The plug-in is available and loaded in RhinoOptions\Plug-ins. However, when I type the command, nothing seems to happen and I cannot figure out.

Therefore, I wanted to ask you if you could take a look at what am I doing wrong.

Thank you very muchplugins_hola.zip (4.3 KB)

Hi @gerard.guell,

your problem is likely that you’ve created a command script. Try to use this code instead and compile it with the RhinoScriptCompiler:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def Hola2():
    # get a point
    point = rs.GetPoint("Pick a point")
    if point:
        rs.AddPoint(point)
	
Hola2()	

Note that i changed these imports from your script:

import rhinoscript.userinterface
import rhinoscript.geometry

to this instead:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

does it compile and work with above example ?
_
c.

Hello @clement thank you for the reply.

Unfortunately if doesn’t runt yet. Here are the list of steps I’m Following:

  1. Create hola2.py file with the aforementioned code:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def Hola10():
# get a point
point = rs.GetPoint(“Pick a point”)
if point:
rs.AddPoint(point)

  1. Open RhinoScriptCompiler

2.1) “N” for new project
2.2) “P” for plugging settings -> fille plug-in name and folder where I want to save plug-in (i.e. C.\Users\FolderX)
2.3) “C” for commands settings -> select hola2.py script
2.4) “B” for Build the current project -> “P” for just plug-in

  1. Once the plug-in is created, I open Rhino5 and go to folder where plug-in is saved (i.e C.\Users\FolderX).

  2. Then Drag and Drop plug-in file in Rhino.

  3. Type hola2 command in command line -> Command: hola2 appears but Nothing occurs afters that

I have to say I’m fearly new to Rhino (but have been coding in Python for several years). However, I’m not able to find what I’m doing wrong…

Thank you again

Hola10()

@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.