Relative path to install folder of plugin

plugin

(Mpreisig) #1

I have created a plugin consisting of a set of python scripts. Some of these scripts are linked to commands that create specific objects, and other scripts are linked to commands that should export these objects to a custom format that I need for importing the objects into another software (some finite element software).

The way I export these objects is that I open a template input file that contains not objects, but still a lot of software-related stuff such as settings and other stuff. At the corresponding sections of that input file I insert my objects and then save it under a new name.

The problem is that I don’t know how to distribute this template file with the plugin, which I tried to package with a .rhi file. Just copying it to the root directory of the .rhi archive the script cannot find it (it’s looking at “…Program Files/Rhinoceros 5 (64-bit)/System”. How can I provide a relative path to the Install folder of the plugin?

-Matthias


(Dale Fugier) #2

Hi @mpreisig,

How did you create your plug-in? One way,a plug-in can obtain a path to itself like this:

var path = System.Reflection.Assembly.GetExecutingAssembly().Location;

– Dale


(Mpreisig) #3

Thanks Dale for your reply.

path = System.Reflection.Assembly.GetExecutingAssembly().Location

points to “…\Program Files\Rhinoceros 5 (64-bit)\Plug-ins\IronPython”

To package the plugin I zipped all files (including the template input file) and changed the extension to rhi. The archive is installed to “…Program Files\Common Files\McNeel\Rhinoceros\5.0\Plug-ins\PythonPlugins”. This would be the path that I’d like to reference (I don’t need to write to the same location).

-Matthias


(Dale Fugier) #4

Hi @mpreisig,

Even though the folder may say “plugin”, your still excuting as a script.

See if this works any better.

import os
print(os.path.dirname(os.path.realpath(__file__)))

– Dale


(Mpreisig) #5

Ok, thanks! I think for now I’ll stick to distributing the scripts.

-Matthias