How to get PlugIn directory of compiled Python script


#1

@stevebaer, @Alain,

i have compiled a Rhino 5 python script to a plugin using the plugin compiler. In the resulting RHI file, i place some other data which gets installed with the plugin once the RHI file is executed. To access this data, the script in the compiled plugin needs to find its own install folder (the path to the plugin).

So far i’ve tried various things under Rhino5, getting any of these all fail:

import os, sys

p = os.path.realpath(__file__)
print "os.path.realpath = {}".format(p)

f = __file__
print "__file__ = {}".format(f)

s = os.path.dirname(sys.argv[0])
print "os.path.dirname(sys.argv[0]) = {}".format(s)

Next i’ve tried to locate the plugin id using the plugins name, get the instance of the plugin and then try to get the SettingsDirectory. If i do this, i get a directory which does not exist. The plugin is installed at:

C:\Users\UserName\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\CheckPathPlug (831ccbf8-2282-6b80-d4ca-987d5a63e342)\1.0.6232.37415

but the RhinoCommon method plugin.SettingsDirectory gives me this path:

C:\Users\UserName\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\CheckPathPlug (831ccbf8-2282-6b80-d4ca-987d5a63e342)\settings

Under RhinoScript (rvb) there has been a Rhino.PlugInInfo() method which made this step not so hard, but this is not implemented in python script. Is there a way to obtain the correct path with RhinoCommon ?

thanks,
c.


#2

Oh yeah, just found:

plugin.Assembly.Location

in this topic which seems to give the correct full path :wink: thanks to @stevebaer

I leave this here in case anyone tries to find the same using rhino python…

c.