Hi @eirannejad,
Following your docs on using Shared resources I made some code hoping to utilize shared .ini files to deploy custom display modes with a plugin.
The code executes “without error” and I have a print statement to check the paths and such…
The paths seem good from what I can tell because the .ini files do exist where the path print statements show them to be.
However it fails to have the DisplayMode imported into Rhino show up in Document Properties. In the .ini file it says AddToMenu=y so I’m assuming it’s not “hidden”
[DisplayMode\guidStringHere]
AddToMenu=y
If I print all Display Modes in file this imported display mode does not show up, leading me to believe it is not being imported correctly and that my code is at fault.
Here’s the print statement for the paths/debugging:
Plugin path: C:\Users\username\AppData\Roaming\McNeel\Rhinoceros\packages\8.0\MyTestPlugin\0.1.1\MyTestPlugin.rhp
Plugin directory: C:\Users\username\AppData\Roaming\McNeel\Rhinoceros\packages\8.0\MyTestPlugin\0.1.1
Resource path: C:\Users\username\AppData\Roaming\McNeel\Rhinoceros\packages\8.0\MyTestPlugin\0.1.1\shared\MyDisplayModeToImport.ini
Display mode successfully imported from: C:\Users\username\AppData\Roaming\McNeel\Rhinoceros\packages\8.0\MyTestPlugin\0.1.1\shared\MyDisplayModeToImport.ini
Here is that code if anyone could shed some light on what I am doing wrong it would be greatly appreciated!
import Rhino
import System
# Function to import display mode from file
def ImportDisplayMode(resource_name):
# Get plugin path
plugin_path = Rhino.PlugIns.PlugIn.PathFromName("MyTestPlugin")
if plugin_path:
# Get the directory containing the plugin, without the .rhp file
plugin_directory = System.IO.Path.GetDirectoryName(plugin_path)
print(f"Plugin path: {plugin_path}")
print(f"Plugin directory: {plugin_directory}")
# Build the path to the shared resource
shared_resource = str(System.IO.Path.Combine(plugin_directory, "shared", f"{resource_name}"))
print(f"Resource path: {shared_resource}")
# Try to import the display mode from file
display_mode_id = Rhino.Display.DisplayModeDescription.ImportFromFile(shared_resource)
if display_mode_id is None:
Rhino.RhinoApp.WriteLine(f"Failed to import display mode from file: {shared_resource}")
return None
# Try to get the display mode by ID
display_mode = Rhino.Display.DisplayModeDescription.GetDisplayMode(display_mode_id)
if display_mode:
Rhino.Display.DisplayModeDescription.AddDisplayMode(display_mode)
return shared_resource, display_mode
else:
Rhino.RhinoApp.WriteLine(f"Display mode not found for ID: {display_mode_id}")
return None
else:
Rhino.RhinoApp.WriteLine("Plugin path not found")
return None
if __name__ == "__main__":
resource_name = "MyDisplayModeToImport.ini"
result = ImportDisplayMode(resource_name)
if result:
shared_resource, display_mode = result
print(f"Display mode successfully imported from: {shared_resource}")
else:
print("Failed to import display mode")