Create toolbar Button that references DocumentUserText

Hello,

via Grasshopper-Definition I can write a list of Rhino-Commands into a textfile. These commands differ from project to project and contain project-specific names and file paths, but the name of the textfile needs to be the same, so I can start it via a toolbar button I created that uses the -_ReadCommandFile command.

Now when working on several projects simultaneuosly I frequently hit my button while the command list isn’t updated - and all projects are completely mixed up and overwritten.

So my idea was to integrate the command list into the Rhino-File as DocumentUserTexts and the button should reference these. In the example I have two lists of commands and I would have two buttons: one calls CommandList1 and the second one calls CommandList2. (To keep it simple, there are just any commands in the example.)

How do I pass the content of the command lists into the toolbar buttons?

This would be an enormous improvement to the workflow!

DocUserText_ComandList.3dm (35.1 KB)

Hello - if I understand what you need, you can grab the text using a python script, and run that from a button. Would that do?

import rhinoscriptsyntax as rs

def test():
    
    cmdStr = rs.GetDocumentUserText("CommandList1")
    if cmdStr is not None:
        cmdList = cmdStr.Split('\n')

        for item in cmdList:
            print 'cmd =' + item
            rs.Command(item)
    pass
    
test()

-Pascal

1 Like

Hello Pascal,

This is exactly what I’m looking for!

I placed the .python-File in some Folder and had to set the path to this folder in the preferences and then it worked with
-_RunPythonScript “CommandList1.py”

Thank You very much!!

I have another question:
On every computer that uses the button i have to place the .py-files somewhere and set the path in Preferences. Is there a chance to place the Python-Code inside the Button-Command-Text?