[Python] Create Custom Library Folder?

Is it possible to use python to create a custom library folder. Like you could do manually by clicking on the New button in the libraries panel in the Rhino Options window? It’s okay if it isn’t, but it would be nice if it is. :slight_smile:

Thanks in advance.

Hi @williamjb741,

Use this:

– Dale

Thanks Dale. I will give it a try and see how it goes.

Hi Dale,

The reason I was hoping I could programmatically add paths to the Libraries custom folders list is because those paths show up in the drop down menu of the Library side panel, but paths I add to the Search Paths list don’t seem to show up there. Have I missed something?

And I will understand if what I want to do is not possible, I just wanted to be sure it wasn’t possible before I give up on it.

2024-04-17_2-23-26

Rhino 8 the # env can be added, which will add the folder to the sys.path: Rhino - ScriptEditor Command

Hi Scott,

I make a kit that includes a folder that contains a bunch of models (.3dm files). I want to make that folder available to the end user via the Libraries panel so they can drag and drop my models into their document from the side panel. Right now they have to set it up manually. I would prefer to set it up for them via a script.

Manually, this is done by adding the folder to a list of custom library folders in the Libraries panel of the Rhino Options window. I’m asking can I use python to add a folder to that list of custom library folders. I’m thinking it’s not possible.

Hi @williamjb741,

There is no API access to this. I’ve logged a few wishes.

https://mcneel.myjetbrains.com/youtrack/issue/RH-81594

https://mcneel.myjetbrains.com/youtrack/issue/RH-81595

Thanks,

– Dale

Okay, thanks, Dale.

import Rhino
import scriptcontext as sc

def custom_folder():

    # Adds a folder below the Custom radiobutton
    Rhino.Render.SupportOptions.Libraries_SetCustomPath("/Users/maxsoderstrom/Desktop");

    # Turns on the Show custom folders checkbox
    Rhino.Render.SupportOptions.Libraries_SetShowCustom(True);

    # Sets the inital folder to Custom custom_folder.
    Rhino.Render.SupportOptions.Libraries_SetInitialLocation(Rhino.Render.SupportOptions.RdkInitialLocation.CustomFolder);

    # Adds two folders to the folder list. The paths are separated with ;
    Rhino.Render.SupportOptions.Libraries_SetCustomPathList("/Users/maxsoderstrom/Documents;/Users/maxsoderstrom/Downloads")

    # False will turn the Custom radio open. True will turn the Use default library location on
    Rhino.Render.SupportOptions.Libraries_SetUseDefaultLocation(False);

custom_folder()
2 Likes

@williamjb741 Hope the above script my help

1 Like

Hi Max,

Thanks for coming up with those functions. I tried it, but I get this error. I get this error if I run it from the editor or if I run it from Tools > Script > Run. I only tried the Libraries_CustomPath() method, but all these new functions do appear in my Intellisense-like popup now.

Use Libraries_SetCustomPathList to set the paths. The CustomPath takes no arguments and returns the paths.

1 Like