public void OpenCsxSourceDialog() { var dialog = new Rhino.UI.OpenFileDialog() { InitialDirectory = Rhino.RhinoDoc.ActiveDoc.Path ?? Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), Filter = "Roslyn CSharp Script (*.csx)|*.csx", Title = "Open script" }; if (!dialog.ShowOpenDialog()) { return; } var path = LanguageService.ResolveScriptUri(dialog.FileName); if (path == null) { ClearRuntimeMessages(); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Can not find the script ${dialog.FileName}"); return; } CodeEditor.CreateNewScriptIfNeed(path); SourceUri = path; m_script.DefineSource(path); }
private void openCADFileToolStripMenuItem_Click(object sender, EventArgs e) { var fd = new Rhino.UI.OpenFileDialog { Filter = "CAD Files (*.3dm;*.step)|*.3dm;*.step" }; fileName = fd.FileName; if (fd.ShowOpenDialog() == true) { fileName = fd.FileName; // MessageBox.Show(fileName, "File directory"); } else { MessageBox.Show("no file is selected"); } if (fileName != null) { RhinoDoc.OpenFile(fileName); doc.Views.Redraw(); } //doc.Views.Redraw(); }
private void openXMLToolStripMenuItem_Click(object sender, EventArgs e) { var fdXml = new Rhino.UI.OpenFileDialog { Filter = "XML Files (*.xml)|*.xml" }; if (fdXml.ShowOpenDialog() == true) { xmlfileName = fdXml.FileName; result = XmlHelper.FromXmlFile <Product>(xmlfileName); if (result.filepath != null) { RhinoDoc.OpenFile(result.filepath); doc.Views.Redraw(); } else { MessageBox.Show("The given file cannot be successfully open"); } } else { MessageBox.Show("no file is selected"); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.UI.OpenFileDialog dialog = new Rhino.UI.OpenFileDialog(); dialog.Title = "Open pointcloud file"; dialog.ShowOpenDialog(); Rhino.Input.Custom.OptionInteger optStep = new Rhino.Input.Custom.OptionInteger(4, 1, 1000); Rhino.Input.Custom.GetOption getOpt = new Rhino.Input.Custom.GetOption(); getOpt.AddOptionInteger("Resolution", ref optStep); getOpt.SetCommandPrompt("Loading options"); string path = dialog.FileName; if (!System.IO.File.Exists(path)) { Rhino.RhinoApp.WriteLine("Farhino: Failed to find file..."); return(Result.Failure); } getOpt.Get(); Rhino.RhinoApp.WriteLine("Farhino: Step value: " + optStep.CurrentValue.ToString()); RFContext.LoadScan(path, optStep.CurrentValue); return(Result.Success); }
public void OpenFile() { var fdi = new Rhino.UI.OpenFileDialog { Filter = "GSA Files(*.gwb)|*.gwb|All files (*.*)|*.*" }; //"GSA Files(*.gwa; *.gwb)|*.gwa;*.gwb|All files (*.*)|*.*" var res = fdi.ShowOpenDialog(); if (res) // == DialogResult.OK) { string file = fdi.FileName; // instantiate new panel var panel = new Grasshopper.Kernel.Special.GH_Panel(); panel.CreateAttributes(); // set the location relative to the open component on the canvas panel.Attributes.Pivot = new PointF((float)Attributes.DocObject.Attributes.Bounds.Left - panel.Attributes.Bounds.Width - 30, (float)Params.Input[0].Attributes.Pivot.Y - panel.Attributes.Bounds.Height / 2); // check for existing input while (Params.Input[0].Sources.Count > 0) { var input = Params.Input[0].Sources[0]; // check if input is the one we automatically create below if (Params.Input[0].Sources[0].InstanceGuid == panelGUID) { // update the UserText in existing panel //RecordUndoEvent("Changed OpenGSA Component input"); panel = input as Grasshopper.Kernel.Special.GH_Panel; panel.UserText = file; panel.ExpireSolution(true); // update the display of the panel } // remove input Params.Input[0].RemoveSource(input); } //populate panel with our own content panel.UserText = file; // record the panel's GUID if new, so that we can update it on change panelGUID = panel.InstanceGuid; //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[0].AddSource(panel); (this as IGH_VariableParameterComponent).VariableParameterMaintenance(); Params.OnParametersChanged(); Params.Input[0].ClearRuntimeMessages(); CancellationSources.Add(new System.Threading.CancellationTokenSource()); ClearData(); } }
public static Rhino.Commands.Result SpriteDrawing(RhinoDoc doc) { var sprite_mode = new Rhino.Input.Custom.OptionToggle(m_draw_single_sprite, "SpriteList", "SingleSprite"); var size_option = new Rhino.Input.Custom.OptionDouble(m_sprite_size); var space_option = new Rhino.Input.Custom.OptionToggle(m_draw_world_location, "Screen", "World"); var go = new Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("Sprite drawing mode"); go.AddOptionToggle("Mode", ref sprite_mode); go.AddOptionDouble("Size", ref size_option); go.AddOptionToggle("DrawSpace", ref space_option); int option_go = go.AddOption("Spin"); int option_file = go.AddOption("FileSprite"); Rhino.Display.DisplayPipeline.PostDrawObjects += DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox += DisplayPipeline_CalculateBoundingBox; doc.Views.Redraw(); while (go.Get() == Rhino.Input.GetResult.Option) { m_draw_single_sprite = sprite_mode.CurrentValue; m_sprite_size = (float)size_option.CurrentValue; m_draw_world_location = space_option.CurrentValue; if (go.OptionIndex() == option_go) { var gs = new Rhino.Input.Custom.GetOption(); gs.SetCommandPrompt("press enter/escape to end"); gs.SetWaitDuration(1); var vp = doc.Views.ActiveView.MainViewport; while (gs.Get() == Rhino.Input.GetResult.Timeout) { vp.Rotate(0.1, Vector3d.ZAxis, Point3d.Origin); doc.Views.Redraw(); } } else if (go.OptionIndex() == option_file) { var dlg = new Rhino.UI.OpenFileDialog(); if (dlg.ShowDialog()) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(dlg.FileName); m_sprite = new Rhino.Display.DisplayBitmap(bmp); } doc.Views.Redraw(); } else { doc.Views.Redraw(); } } Rhino.Display.DisplayPipeline.PostDrawObjects -= DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox -= DisplayPipeline_CalculateBoundingBox; return(Rhino.Commands.Result.Success); }
protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode) { /////////////// if (is64) { dir = dir64; Rhino.RhinoApp.WriteLine("64bit" + dir); } else { dir = dir32; Rhino.RhinoApp.WriteLine("32bit" + dir); } string[] searchpaths = Rhino.ApplicationSettings.FileSettings.GetSearchPaths(); if (searchpaths.Length == 0 || searchpaths[0] != dir) { Rhino.ApplicationSettings.FileSettings.AddSearchPath(dir, 0); } Rhino.ApplicationSettings.FileSettings.WorkingFolder = Rhino.ApplicationSettings.FileSettings.GetSearchPaths()[0]; Rhino.UI.OpenFileDialog open = new Rhino.UI.OpenFileDialog(); open.InitialDirectory = dir; url = TuringAndCorbusierPlugIn.InstanceClass.turing.ProjectAddress.Text; if (GetFileName().Length > 0) { Rhino.RhinoApp.Wait(); if (TuringAndCorbusierPlugIn.InstanceClass.isfirst) { Rhino.RhinoApp.RunScript("_-Open " + GetFileName() + " '_Enter", true); TuringAndCorbusierPlugIn.InstanceClass.isfirst = false; } else { Rhino.RhinoApp.RunScript("_-Open n " + GetFileName() + " '_Enter", true); } return(Rhino.Commands.Result.Success); } else { return(Rhino.Commands.Result.Failure); } }
/* * public static void XmlSerializeFoamToFile(PFoam foam, string fileName) * { * XmlSerializer serializer = new XmlSerializer(typeof(PFoam)); * TextWriter writer = new StreamWriter(fileName); * serializer.Serialize(writer, foam); * } * * public static PFoam XmlDeserializeFoamFromFile(string fileName) * { * // Creates an instance of the XmlSerializer class; * // specifies the type of object to be deserialized. * XmlSerializer serializer = new XmlSerializer(typeof(PFoam)); * FileStream fs = new FileStream(fileName, FileMode.Open); * PFoam foam = new PFoam(); * * foam = (PFoam)serializer.Deserialize(fs); * * return foam; * * } */ /* * public static void Serialize(PFoam obj) * { * using (FileStream fStream = File.Create("serialized.bin")) * * { * //BinarySerializer serializer = new DataContractSerializer(obj.GetType()); * IFormatter formatter = new BinaryFormatter(); * formatter.Serialize(fStream, obj); * //memoryStream.Position = 0; * //return reader.ReadToEnd(); * } * } * * public static string Serialize(object obj) * { * using (MemoryStream memoryStream = new MemoryStream()) * { * DataContractSerializer serializer = new DataContractSerializer(obj.GetType()); * serializer.WriteObject(memoryStream, obj); * string result = Encoding.UTF8.GetString(memoryStream.ToArray()); * memoryStream.Close(); * return result; * } * } * * public static object Deserialize(string xml, Type toType) * { * using (Stream stream = new MemoryStream()) * { * byte[] data = System.Text.Encoding.UTF8.GetBytes(xml); * stream.Write(data, 0, data.Length); * stream.Position = 0; * DataContractSerializer deserializer = new DataContractSerializer(toType); * return deserializer.ReadObject(stream); * } * } */ public static PFoam DeserializeFoamFromJsonFile() { string jsonData = ""; var fr = new Rhino.UI.OpenFileDialog { Filter = "Json Files (*.json)|*.json" }; if (fr.ShowOpenDialog()) { jsonData = File.ReadAllText(fr.FileName); } return(DeserializeFoam(jsonData)); }
public void OpenFile() { var fdi = new Rhino.UI.OpenFileDialog { Filter = "GSA Files(*.gwb)|*.gwb|All files (*.*)|*.*" }; var res = fdi.ShowOpenDialog(); if (res) // == DialogResult.OK) { fileName = fdi.FileName; (this as IGH_VariableParameterComponent).VariableParameterMaintenance(); Params.OnParametersChanged(); ExpireSolution(true); } }
//public void GetWindow() //{ // IntPtr currentwindow = GetWindow(Rhino.RhinoApp.MainWindowHandle(), 0); // System.Windows.Forms.Control cwc = System.Windows.Forms.Control.FromHandle(currentwindow); // Rhino.RhinoApp.WriteLine(cwc.Name); //} private void RhinoUI_Show_Click(object sender, RoutedEventArgs e) { //if (!RhinoWindowSetUp.isvisible) // RhinoWindowSetUp.SetUIForTC(Rhino.RhinoDoc.ActiveDoc); //else // RhinoWindowSetUp.ResetUI(Rhino.RhinoDoc.ActiveDoc); Rhino.UI.OpenFileDialog ofd = new Rhino.UI.OpenFileDialog(); ofd.Filter = "RhinoFiles (*.3dm)|*.3dm"; var result = ofd.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { Rhino.RhinoApp.RunScript("_-Open n " + ofd.FileName, true); } UIManager.getInstance().HideWindow(this, UIManager.WindowType.Menu); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Allow the user to select a bitmap file var fd = new Rhino.UI.OpenFileDialog { Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg" }; if (!fd.ShowOpenDialog()) { return(Rhino.Commands.Result.Cancel); } // Verify the file that was selected System.Drawing.Image image; try { image = System.Drawing.Image.FromFile(fd.FileName); } catch (Exception) { return(Rhino.Commands.Result.Failure); } var model = new ParticleConduitModel(Path.GetFileName(fd.FileName), 180, Color.FromArgb(100, 255, 0, 255), new Bitmap(image), true); RhinoFaceMePlugIn.Instance.FaceMeTable.Add(model); while (true) { var result = Rhino.Input.RhinoGet.GetPoint("Pick point", false, out var pt); if (result != Result.Success) { break; } model.AddParticle(pt); doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. // get image file Image image; var fileDialog = new Rhino.UI.OpenFileDialog { Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*" }; if (!fileDialog.ShowOpenDialog()) { return(Result.Cancel); } image = Image.FromFile(fileDialog.FileName); // get Dimensions var rc = RhinoGet.GetRectangle("Specify bounding rectangle", out var corners); double width = corners[1].DistanceTo(corners[0]); double height = corners[3].DistanceTo(corners[0]); // create material image data var plane = Plane.WorldXY; plane.Origin = corners[0]; var data = new MaterialImageData(plane, image, width, height); // create custom object var mObject = data.GetCustomObject(); // add custom object to doc doc.Objects.AddRhinoObject(mObject, mObject.CurveGeometry); // redraw the view doc.Views.Redraw(); // return success return(Result.Success); }
private void button1_Click(object sender, RoutedEventArgs e) { Rhino.FileIO.FileReadOptions readoption = new Rhino.FileIO.FileReadOptions(); readoption.ImportMode = true; Rhino.UI.OpenFileDialog ofd = new Rhino.UI.OpenFileDialog(); ofd.Filter = "Rhino Files or Cad Files (*.3dm;*.dwg;)|*.3dm;*.dwg;"; if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } try { Rhino.FileIO.File3dm.Read(ofd.FileName); } catch (Rhino.FileIO.BinaryArchiveException f) { MessageBox.Show(f + " " + ofd.FileName + " 파일이 존재하지 않습니다"); } }
public static Rhino.Commands.Result AddBackgroundBitmap(Rhino.RhinoDoc doc) { Rhino.RhinoApp.WriteLine("hey"); // Allow the user to select a bitmap file Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog(); fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg"; if (!fd.ShowDialog()) { return(Rhino.Commands.Result.Cancel); } // Verify the file that was selected System.Drawing.Image image; try { image = System.Drawing.Image.FromFile(fd.FileName); } catch (Exception) { return(Rhino.Commands.Result.Failure); } // Allow the user to pick the bitmap origin Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Bitmap Origin"); gp.ConstrainToConstructionPlane(true); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { return(gp.CommandResult()); } // Get the view that the point was picked in. // This will be the view that the bitmap appears in. Rhino.Display.RhinoView view = gp.View(); if (view == null) { view = doc.Views.ActiveView; if (view == null) { return(Rhino.Commands.Result.Failure); } } // Allow the user to specify the bitmap with in model units Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber(); gn.SetCommandPrompt("Bitmap width"); gn.SetLowerLimit(1.0, false); gn.Get(); if (gn.CommandResult() != Rhino.Commands.Result.Success) { return(gn.CommandResult()); } // Cook up some scale factors double w = gn.Number(); double image_width = image.Width; double image_height = image.Height; double h = w * (image_height / image_width); Rhino.Geometry.Plane plane = view.ActiveViewport.ConstructionPlane(); plane.Origin = gp.Point(); view.ActiveViewport.SetTraceImage(fd.FileName, plane, w, h, false, false); view.Redraw(); return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result AddTexture(Rhino.RhinoDoc doc) { // Select object to add texture const ObjectType filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh; Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to add texture", false, filter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.DocObjects.RhinoObject rhino_object = objref.Object(); if (rhino_object == null) { return(Rhino.Commands.Result.Failure); } // Select texture Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog(); fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg"; if (!fd.ShowDialog()) { return(Rhino.Commands.Result.Cancel); } // Verify texture string bitmap_filename = fd.FileName; if (string.IsNullOrEmpty(bitmap_filename) || !System.IO.File.Exists(bitmap_filename)) { return(Rhino.Commands.Result.Nothing); } // Make sure the object has it's material source set to "material_from_object" rhino_object.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject; // Make sure the object has a material assigned int material_index = rhino_object.Attributes.MaterialIndex; if (material_index < 0) { // Create a new material based on Rhino's default material material_index = doc.Materials.Add(); // Assign the new material (index) to the object. rhino_object.Attributes.MaterialIndex = material_index; } if (material_index >= 0) { Rhino.DocObjects.Material mat = doc.Materials[material_index]; mat.SetBumpTexture(bitmap_filename); mat.CommitChanges(); //Don't forget to update the object, if necessary rhino_object.CommitChanges(); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
/// <summary> /// Called by Rhino to "run" your command. /// </summary> protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { doc.Objects.Clear(); Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog { Filter = "XML File (*.xml)|*.xml" }; if (!fd.ShowOpenDialog()) { return(Result.Cancel); } //Read TopoCreator String xmlfile = fd.FileName; IntPtr topoData = TopoCreator.readXML(xmlfile); int n_part = TopoCreator.partNumber(topoData); //Part Layer int partlayer_index = getLayerOrCreate(doc, "Part"); //Boundary Layer int boundarylayer_index = getLayerOrCreate(doc, "Boundary"); for (int partID = 0; partID < n_part; partID++) { Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); TopoCreator.getPartMesh(partID, mesh, topoData); Guid mesh_guid = doc.Objects.AddMesh(mesh); //error: exit if (mesh_guid == Guid.Empty) { TopoCreator.deleteStructure(topoData); return(Result.Failure); } Rhino.DocObjects.RhinoObject obj = doc.Objects.Find(mesh_guid); int mat_index; if (TopoCreator.isBoundary(partID, topoData) == 1) { mat_index = doc.Materials.Find("PlasterBoundary", false); obj.Attributes.LayerIndex = boundarylayer_index; } else { mat_index = doc.Materials.Find("PlasterPart", false); obj.Attributes.LayerIndex = partlayer_index; } if (mat_index != -1) { obj.Attributes.MaterialIndex = mat_index; obj.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject; } obj.CommitChanges(); } //CrossMesh int crossMeshlayer_index = getLayerOrCreate(doc, "CrossMesh"); List <Rhino.Geometry.Polyline> polylines = new List <Rhino.Geometry.Polyline>(); IntPtr crossMesh = TopoCreator.initCrossMeshPtr(topoData); TopoCreator.getPolyLines(polylines, crossMesh); TopoCreator.deletePolyLineRhino(crossMesh); for (int id = 0; id < polylines.Count; id++) { Guid polyline_guid = doc.Objects.AddPolyline(polylines[id]); Rhino.DocObjects.RhinoObject obj = doc.Objects.Find(polyline_guid); obj.Attributes.LayerIndex = crossMeshlayer_index; obj.CommitChanges(); } //Rhino.RhinoApp.RunScript("_SelMesh", false); //Rhino.RhinoApp.RunScript("_MeshToNURB", false); //Rhino.RhinoApp.RunScript("_SelMesh", false); //Rhino.RhinoApp.RunScript("_Delete", false); //Rhino.RhinoApp.RunScript("_SelPolysrf", false); //Rhino.RhinoApp.RunScript("_MergeAllFaces", false); doc.Objects.UnselectAll(); TopoCreator.deleteStructure(topoData); return(Result.Success); }