Grasshopper double click on component to retrieve directory string


#1

Hi,

Is there any example to do the following without getting into creating custom windows forms:

I need to double click on the component,
Then similarly to Rhino Windows File Open command a window is opened to select directory.
Once the Open button is selected the directory is copied as a string inside component.


(Nathan 'jesterKing' Letwory) #2

Here us how I do it through a component menu item. You probably can figure out from there how to do that from a double-click:


#3

Thanks it works perfectly. Just one question incase of selecting not a file but folder.
Should I use something else instead of OpenFileDialog?

    protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu) {

        Menu_AppendItem(menu, "Select Directory...", (_, __) => {
            
            var fdi = new OpenFileDialog { };

            var res = fdi.ShowDialog();

            if (res == DialogResult.OK) {
                directory = fdi.InitialDirectory;
                Rhino.RhinoApp.WriteLine(fdi.FileName);
                ExpireSolution(true);
            }

        });

    }

#4

Found This seems to work, thank you:)

       protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu) {

        Menu_AppendItem(menu, "Select Directory...", (_, __) => {
            

            var folderDialog = new FolderBrowserDialog();
            var run = folderDialog.ShowDialog();

            if (run == DialogResult.OK) {
                directory = folderDialog.SelectedPath;
                Rhino.RhinoApp.WriteLine(directory);
                 ExpireSolution(true);
            }



        });




    }