Example #1
0
        public void SaveAsFile()
        {
            var fdi = new Rhino.UI.SaveFileDialog {
                Filter = "GSA Files(*.gwb)|*.gwb|All files (*.*)|*.*"
            };
            var res = fdi.ShowSaveDialog();

            if (res) // == DialogResult.OK)
            {
                fileName        = fdi.FileName;
                usersetFileName = true;
                string mes = gsaSaveModel.SaveAs(fileName).ToString();
                if (mes == GsaAPI.ReturnValue.GS_OK.ToString())
                {
                    canOpen = true;
                    //CreateAttributes();
                    mes = "Saved file";

                    //add panel input with string
                    //delete existing inputs if any
                    while (Params.Input[2].Sources.Count > 0)
                    {
                        Grasshopper.Instances.ActiveCanvas.Document.RemoveObject(Params.Input[2].Sources[0], false);
                    }

                    //instantiate  new panel
                    var panel = new Grasshopper.Kernel.Special.GH_Panel();
                    panel.CreateAttributes();

                    panel.Attributes.Pivot = new PointF((float)Attributes.DocObject.Attributes.Bounds.Left -
                                                        panel.Attributes.Bounds.Width - 40, (float)Attributes.DocObject.Attributes.Bounds.Bottom - panel.Attributes.Bounds.Height);

                    //populate value list with our own data
                    panel.UserText = fileName;

                    //Until now, the panel is a hypothetical object.
                    // This command makes it 'real' and adds it to the canvas.
                    Grasshopper.Instances.ActiveCanvas.Document.AddObject(panel, false);

                    //Connect the new slider to this component
                    Params.Input[2].AddSource(panel);
                    Params.OnParametersChanged();
                    ExpireSolution(true);
                }
                else
                {
                    mes = Char.ToUpper(mes[3]) + mes.Substring(4).ToLower().Replace("_", " ");
                }
                this.Message = mes;
            }
        }
Example #2
0
        private void toolStripButtonZip_Click(object sender, EventArgs e)
        {
            string folder = GetActiveFolderFullPath();
            string zip    = folder + ".zip";

            if (!ModifierKeys.HasFlag(Keys.Control))
            {
                Rhino.UI.SaveFileDialog fd = new Rhino.UI.SaveFileDialog();
                fd.Title      = "Zip File to export to";
                fd.Filter     = "zip files (*.zip)|*.zip|All files (*.*)|*.*";
                fd.DefaultExt = "zip";
                if (!fd.ShowSaveDialog())
                {
                    return;
                }

                zip = fd.FileName;
            }

            ZipFile.CreateFromDirectory(folder, zip);
        }