Can I add a variable to Rhino with python?

Hi guys,
I am trying to find an easy way to add a license key to a plugin and wonder if there is some easy way to add a value to Rhino, kind of how Sticky works on a session level, and how SetDocumentData works on a document level. (So I need an application level)

I have made a generator for the license keys and that works fast and reliable.

Criteria’s of right now:

  • Easy to do and maintain
  • Works on both OS’s
  • (preferably) Works for users who aren’t administrators

Right now my solution is that the user adds a .txt file to the folder where the plugin is installed.
(As it’s easy to find that folder) but I presume it requires Admin rights to write to it.

Thanks for any insight.

I haven’t tested it on MacOS but without admin, .txt files can be written using e.g.

with open(file_name, 'wt') as f:

Thanks, I want to store a string in ‘Rhino’, but writing a txt file to disk might also be a workaround… I’ll look into that.

I am using some MIT libraries which work on both macOS and Windows (but in .NET). License is just text file placed inside plugin folder and it works for me. It is distributed by package manager so plugin folder is in place where admin rights are not required for write permission.

I assume this may be already similar to solution which you already have, but in any case if you would like to get more details from me, just PM.

In my case if license file fails to save, plugin stores it in memory and tries to save again during OnCloseDocument.

1 Like

Thanks I’ll test it out more widely then.
And I am all for ‘The simpler the better’.

A more secure and effective solution could be:

  • Implementing a licensing system that uses a combination of a license key and an access token for authentication.
  • Storing the license information securely, for example, in an encrypted file in the standard Rhinofolder/system.
  • Sending the license information to a secure API endpoint for verification using a timer (IE verify the license every 90seconds).
  • Having a trusted web server verify the license key and access token, and return a response indicating the validity of the license.
  • Implementing appropriate security measures, such as encryption and secure communication protocols, to prevent unauthorized access and cracking of the licensing system.

While this solution may require a bit more effort to implement, it provides a much higher level of security and protection for your software. If you need any assistance with the implementation, I would be happy to help. I have experience in integrating secure licensing systems into software products.

1 Like

Hello Holo,

I wonder whether an environment variable could work for you ? 15.1. os — Miscellaneous operating system interfaces — Python 2.7.18 documentation

1 Like

Thanks, this is for the TerrainMesh plugin and I don’t expect to sell much of it, so I am more worried on spending too much time on maintenance of the licenses than piracy :slight_smile:
But I need a way to check for the license that is easy to implement in the plugin and that is most of all convenient for the customers. So ease of use is top priority.

In that case you can use Windows registry and store a license and an expiration date, It’s the simplest solution, very reliable. It’s pretty much a Sticky as you asked, as there are no txt files floating around, and you store on the user PC rather than the active rhino document.
Easy to crack but if you’re looking for simplicity this is the way. The user doesnt need any txt file or anything
This is the official documentation

1 Like

That’s a good idea, I use a version of this for locating the folder the plugin is installed at, and there I can put the license and access it later on.

I’ll check if I can add a “free” license there and overwrite it’s content if the user has purchased a key.
If not then the customer has to save the .txt file with the key there. That works too, but is not as smooth.

Here is the code i use to locate the path:

### Locate pluginfolder
import rhinoscriptsyntax as rs
import Rhino

def pluginFolder(pluginName):
    id= rs.PlugInId (pluginName)
    path = Rhino.PlugIns.PlugIn.PathFromId(id)
    # remove the name and the extension from the path
    nameLength = len(pluginName)+4 #+4 for '.rhp'
    path = path[:-nameLength]
    return path

print pluginFolder("TerrainMesh")
1 Like

Ok, that sounds nice, but then I need to learn how to do that on a mac too :wink:
I’ll read up!

I think just a text file in plugin folder with cryptographic signature inside (or evencomputer ID), public key in app and private key in license generator will do simple job for Minimum Viable Product, and it works on both platforms. Edition of license text file would make signature not valid anymore.

In the end if thing get serious than you have to build your own installer for Windows, Mac, get certification etc.

1 Like