Script Editor - can't find image path after publishing script to rhp

Hi there,

I am just starting to use the script editor in Version 8 (8.3.24009.15002, 2024-01-09) on a Mac computer.
My script is written in python and I want to get an rhp that I can share with others, That works well until I start to insert an icon or image in my script. When I share the rhp and the image, I can’t figure out what path I have to call, so that it works.
My code down here for the image call works if I start the code from the script editor but not from the exported rhp in Rhino or on other machine.

self.script_dir = os.path.dirname(os.path.realpath(__file__)) self.image_filename = "pixolid-256-256.png" self.image_folder = "shared" self.image_path = os.path.join(self.script_dir, self.image_folder, self.image_filename) self.logo = drawing.Bitmap(self.image_path)

The error output in Rhino looks like this:

I couldn’t find any solution with google etc.
Thank you

Hi @lxgbrl
The issue happens because you are using relative paths to your images. Once your script is packaged into an .rhp file, the original working directory and relative paths might not be interpreted correctly by Rhino.
You could consider using an absolute Installation path or pack the RHP file with the resources (images etc) required.
Hope this helps,
Farouk

1 Like

Hi @lxgbrl, take a look at this thread. Note that rhi installer is not there anymore so you’ll have to work with yak instead.

btw. the fun with files relative to a compliled script’s plugin folder begins when you’ve installed your plugin multiple times because yak did not remove the previous version or when

Rhino.PlugIns.PlugIn.PathFromName(string name)

returns the path to a plugin with the same name but not the Rhino version you’re actually running. In these cases, the path returned may not be the correct one.

The issue has been there for many years unfortunately.

@farouk.serragedine, how would you do this with the ScriptCompiler ?

_
c.

Hi @clement ,
Any resource editor would work since RHP plugins are basically DLL files.
image

Farouk

1 Like

Thanks to all for your answers!

@clement that is exactly what I needed to know. Thanks. I will try with yak.

@farouk.serragedine Okay, so I found an sln file in the src folder after compiling with script editor. I guess I could use this with visual studio, add my image and go on from there?