Plug-in creation tutorial?

I have a couple of dozen Python scripts that I currently hand out to a small group of colleagues, and I thought it’s probably time that I put them together into a plug-in… I have avoided this in the past as the procedures I saw looked overly complicated… Has it gotten any simpler in V8? Any tutorial material out there?

The scripts have prompts that are localized in English, French, German and Italian and normally can run in either Py2 or Py3 - however Py2 is a must because some of the people who are using the scripts are still on V7. I’m not sure if that means that I have to compile two different plug-ins in that case.

@Helvetosaur

I make a small jewelry kit. It isn’t a plug-in, but it acts like one. Got a toolbar and an installation script and everything. The installation script prompts for a drive, then unzips the kit to that drive (so my installation script knows the location of the kit). Then it makes aliases based on the kit’s drive location. It also “installs” the toolbar, and the toolbar references aliases instead of literal script locations (that gives them the flexibility of choosing a drive).

It’s all python, and, you might not need a lot of the functionality of my installer script. For example, I have custom eto forms and a progress bar (but I have an audience on youtube and not a small group to whom I could maybe just explain things…like you need to wait two whole minutes while the kit unzips and it will look like Rhino is “hanging” during that time…thus the progress bar)

But you could detect the drives, prompt them for a drive with rs.listbox, make a folder for your kit, unzip your scripts there, then loop thru an array of alias names, and build an alias for each name.

If the group is small enough and advanced enough, you could just all agree that everyone will use the same drive and they could all unzip to that drive, and your script would only need to build the aliases.

At that point, the aliases will work. A toolbar is optional, but you can definitely make one. The script can “install” the toolbar, or you can show them how to activate a custom toolbar in the Rhino Options.

I have a free version of the kit, if you want to look at the installer.py file. It’s at cgtrader. Let me know if you want to look at it and I’ll put a link to it.

As @williamjb741 indicated, if the problem is the distribution of the scripts, I think it will be quite sufficient to use git and a cloud solution like Github/Bitbucket or Gitlab. As an alternative you can bypass this cloud solution and just provide a network drive where the sources are dumped. The idea is that people just clone your repository and fetch latest changes. They can go back to any commit you made. Its a matter of organisation. Git might be very intimidating at first. But once you memorised the most basic functions, then its extremely powerful and easy. The advantage of this process is, that people can contribute to your work and not just consume it. Since you don’t need to build anything this becomes quite straight-forward.

This is basically what I had in mind…except I commented out the actual rs.AddAlias() command. I can try to re-figure out the zip file stuff, if you’re interested.

#! python 2

import rhinoscriptsyntax as rs
import scriptcontext as sc
import math

import System
import System.Collections.Generic
import Rhino

import os
import clr
clr.AddReference("System.IO.FileSystem.DriveInfo")

# variables
alias_names = [
    "alias1",
    "alias2",
    "alias3"
    ]

alias_strings = []

drives = System.IO.DriveInfo.GetDrives()
good_drives = []
min_free_space = 180 #this is in MB, I think
kit_folder = "Helvetosaur"

# functions
def GetGoodDrives():
    for d in drives:
        if d.IsReady:
            space = int(d.AvailableFreeSpace / 1024 / 1024) #converts to MB, I think
            if space >= min_free_space:
                good_drives.append(str(d.Name))

def CreateAliasStrings():
    for name in alias_names:
        alias = os.path.join(drive, kit_folder, name + ".py")
        alias_strings.append(alias)

def CreateAliases():
    for i in range(len(alias_names)):
        print(alias_names[i], alias_strings[i])
        #rs.AddAlias(alias_names[i], alias_strings[i])

# MAIN
GetGoodDrives()
drive = rs.ListBox(good_drives)
CreateAliasStrings()
CreateAliases()


Oh, that’s way too complicated for this purpose - and my users have no idea about scripting, programming, GitHub or anything like that. They are just users (makers).

@williamjb741
Yes, basically I don’t even make it that complicated. I just supply a folder and tell them to put it somewhere on their computer - suggesting the native Rhino scripts folder, but not necessary - then give them instructions to open the old Python script editor and set a path to that folder. Once that’s done, the scripts can be run with very simple aliases that just have the script name - the path to the folder is not necessary.
NoEcho ! _-RunPythonScript "ScriptFileName.py"

Either they can add a list of aliases I supply or I can make a toolbar that has the aliases in the buttons and distribute it as an .rui.

However, I just thought that distributing a real plug-in that they can drag and drop might be cooler.

2 Likes

@Helvetosaur This is the direction we are going with in Rhino 8. The new script editor can publish rhino and grasshopper 1 plugins:

3 Likes

OK, thanks Ehsan, I will give it a go…

If I understood correctly, if I have all scripts that run in IronPython 2, I can make a plug-in that will run in Rhino 7? Do I have to compile a separate plug-in for Rhino 8?