/// <summary> /// Is called when a user requests to import a ."sgy file. /// It is actually up to this method to read the file itself. /// </summary> /// <param name="filename">The complete path to the new file.</param> /// <param name="index">The index of the file type as it had been specified by the AddFileTypes method.</param> /// <param name="doc">The document to be written.</param> /// <param name="options">Options that specify how to write file.</param> /// <returns>A value that defines success or a specific failure.</returns> protected override bool ReadFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileReadOptions options) { bool read_success = false; var reader = new SegyReader(); ISegyFile file = reader.Read(filename); RhinoApp.WriteLine("SEGY: Header Text: {0}", file.Header.Text); RhinoApp.WriteLine("SEGY: Nº of Traces: {0}", file.Traces.Count); for (int i = 0; i < file.Traces.Count; i++) { var trace = file.Traces[0]; RhinoApp.WriteLine("SEGY: Trace #" + trace.Header.TraceNumber + " Count #: " + i + " Sample Count: {0}", trace.Header.SampleCount); RhinoApp.WriteLine("SEGY: Trace #" + trace.Header.TraceNumber + " Count #: " + i + " Crossline Nº: {0}", trace.Header.CrosslineNumber); RhinoApp.WriteLine("SEGY: Trace #" + trace.Header.TraceNumber + " Count #: " + i + " Inline Nº: {0}", trace.Header.InlineNumber); for (int j = 0; j < trace.Values.Count; j++) { RhinoApp.WriteLine("SEGY: Trace #" + trace.Header.TraceNumber + " Count #: " + i + " Value Nº " + j + ": {0}", trace.Values[j]); } } read_success = true; return(read_success); }
///<summary>Defines file extensions that this import plug-in is designed to read.</summary> /// <param name="options">Options that specify how to read files.</param> /// <returns>A list of file types that can be imported.</returns> protected override Rhino.PlugIns.FileTypeList AddFileTypes(Rhino.FileIO.FileReadOptions options) { var result = new Rhino.PlugIns.FileTypeList(); result.AddFileType("FSpy project file (*.fspy)", "fspy"); return(result); }
/// <summary> /// Is called when a user requests to import a .js file. /// It is actually up to this method to read the file itself. /// </summary> /// <param name="filename">The complete path to the new file.</param> /// <param name="index">The index of the file type as it had been specified by the AddFileTypes method.</param> /// <param name="doc">The document to be written.</param> /// <param name="options">Options that specify how to write file.</param> /// <returns>A value that defines success or a specific failure.</returns> protected override bool ReadFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileReadOptions options) { bool read_success = false; // TODO: Add code for reading file return(read_success); }
///<summary>Defines file extensions that this import plug-in is designed to read.</summary> /// <param name="options">Options that specify how to read files.</param> /// <returns>A list of file types that can be imported.</returns> protected override FileTypeList AddFileTypes(Rhino.FileIO.FileReadOptions options) { var result = new FileTypeList(); result.AddFileType("Javascript File (*.js)", "js"); return(result); }
///<summary>Defines file extensions that this import plug-in is designed to read.</summary> /// <param name="options">Options that specify how to read files.</param> /// <returns>A list of file types that can be imported.</returns> protected override Rhino.PlugIns.FileTypeList AddFileTypes(Rhino.FileIO.FileReadOptions options) { var result = new Rhino.PlugIns.FileTypeList(); result.AddFileType("GL Transmission Format (*.gltf, *.glb)", "glTF", "glb"); return(result); }
///<summary>Defines file extensions that this import plug-in is designed to read.</summary> /// <param name="options">Options that specify how to read files.</param> /// <returns>A list of file types that can be imported.</returns> protected override Rhino.PlugIns.FileTypeList AddFileTypes(Rhino.FileIO.FileReadOptions options) { var result = new Rhino.PlugIns.FileTypeList(); result.AddFileType("SEG-Y File (*.sgy)", "sgy"); return(result); }
public static void OpenFile(string tempFileName) { Rhino.FileIO.FileReadOptions readOptions = new Rhino.FileIO.FileReadOptions(); readOptions.ImportMode = false; readOptions.OpenMode = true; Rhino.RhinoDoc.ReadFile(tempFileName, readOptions); }
private void menu_openClicked(object sender, EventArgs e) { Rhino.FileIO.FileReadOptions readOptions = new Rhino.FileIO.FileReadOptions(); readOptions.ImportMode = false; readOptions.OpenMode = true; Rhino.RhinoDoc.ReadFile(filename, readOptions); }
protected override FileTypeList AddFileTypes(Rhino.FileIO.FileReadOptions options) { FileTypeList result = new FileTypeList(); result.AddFileType("glTF text file (*.gltf)", "gltf"); result.AddFileType("glTF binary file (*.glb)", "glb"); return(result); }
/// <summary> /// Is called when a user requests to import a ."glTF file. /// It is actually up to this method to read the file itself. /// </summary> /// <param name="filename">The complete path to the new file.</param> /// <param name="index">The index of the file type as it had been specified by the AddFileTypes method.</param> /// <param name="doc">The document to be written.</param> /// <param name="options">Options that specify how to write file.</param> /// <returns>A value that defines success or a specific failure.</returns> protected override bool ReadFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileReadOptions options) { bool read_success = false; ModelLoader.Load(filename, doc); read_success = true; return(read_success); }
protected override bool ReadFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileReadOptions options) { glTFLoader.Schema.Gltf gltf = glTFLoader.Interface.LoadModel(filename); GltfRhinoConverter converter = new GltfRhinoConverter(gltf, doc, filename); try { return(converter.Convert()); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); return(false); } }
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 + " 파일이 존재하지 않습니다"); } }
private static void InternalOnAddFileType(int plugin_serial_number, IntPtr pFileList, IntPtr readoptions) { FileImportPlugIn p = LookUpBySerialNumber(plugin_serial_number) as FileImportPlugIn; if (null == p || IntPtr.Zero == pFileList || IntPtr.Zero == readoptions) { HostUtils.DebugString("ERROR: Invalid input for InternalOnAddFileType"); } else { try { Rhino.FileIO.FileReadOptions ro = new Rhino.FileIO.FileReadOptions(readoptions); FileTypeList list = p.AddFileTypes(ro); ro.Dispose(); if (list != null) { Guid id = p.Id; System.Collections.Generic.List<FileType> fts = list.m_filetypes; for (int i = 0; i < fts.Count; i++) { FileType ft = fts[i]; if( !string.IsNullOrEmpty(ft.m_description) && ft.m_extensions.Count>0 ) { int index = UnsafeNativeMethods.CRhinoFileTypeList_Add(pFileList, id ,ft.m_description); for (int j = 0; j < ft.m_extensions.Count; j++ ) UnsafeNativeMethods.CRhinoFileTypeList_SetExtension(pFileList, index, ft.m_extensions[j]); } } } } catch (Exception ex) { string error_msg = "Error occured during plug-in AddFileType\n Details:\n"; error_msg += ex.Message; HostUtils.DebugString("Error " + error_msg); } } }
//Called whenever a Rhino document is being loaded and plug-in user data was //encountered written by a plug-in with this plug-in's GUID. // //If any ON_BinaryArchive::Read*() functions return false than you should //immediately return false otherwise return true when all data was read. protected override void ReadDocument(Rhino.RhinoDoc doc, Rhino.FileIO.BinaryArchiveReader archive, Rhino.FileIO.FileReadOptions options) { //Always read data in the EXACT same order you wrote it int major, minor; archive.Read3dmChunkVersion(out major, out minor); //If you've changed your reading/writing code over time, //you can use the version number of what you read //to figure out what can be read from the archive if ((major > 1 | minor > 0)) { return; } //the data you read/write will probably be member variables of your plug-in class, //but for simplicity this sample is just using locally defined strings string date_string = archive.ReadString(); string time_string = archive.ReadString(); //Get the commands for "Insert_Source" and "Insert_Receiver". This is where the Source and Receiver conduits are stored. UI.Pach_Source_Object S_command = Pach_Source_Object.Instance; UI.Pach_Receiver_Object R_command = Pach_Receiver_Object.Instance; System.Guid objectId = default(System.Guid); string Type = null; do { try { objectId = archive.ReadGuid(); Type = archive.ReadString(); if (Type == "Source") { Rhino.DocObjects.RhinoObject Source = doc.Objects.Find(objectId); if (Source != null) { SourceConduit.Instance.SetSource(Source); doc.Views.Redraw(); } } else if (Type == "Receiver") { Rhino.DocObjects.RhinoObject Receiver = doc.Objects.Find(objectId); if (Receiver != null) { ReceiverConduit.Instance.SetReceiver(Receiver); doc.Views.Redraw(); } } Type = null; }catch (Exception) { break; } }while (objectId != null); }
protected override void ReadDocument(RhinoDoc doc, Rhino.FileIO.BinaryArchiveReader archive, Rhino.FileIO.FileReadOptions options) { m_dict = archive.ReadDictionary(); }
private static int InternalOnReadFile(int plugin_serial_number, IntPtr filename, int index, int docId, IntPtr readoptions) { int rc = 0; FileImportPlugIn p = LookUpBySerialNumber(plugin_serial_number) as FileImportPlugIn; if (null == p || IntPtr.Zero == filename || IntPtr.Zero == readoptions) { HostUtils.DebugString("ERROR: Invalid input for InternalOnReadFile"); } else { try { Rhino.FileIO.FileReadOptions ropts = new Rhino.FileIO.FileReadOptions(readoptions); Rhino.RhinoDoc doc = Rhino.RhinoDoc.FromId(docId); string _filename = Marshal.PtrToStringUni(filename); rc = p.ReadFile(_filename, index, doc, ropts) ? 1 : 0; ropts.Dispose(); } catch (Exception ex) { string error_msg = "Error occured during plug-in ReadFile\n Details:\n"; error_msg += ex.Message; HostUtils.DebugString("Error " + error_msg); } } return rc; }
private static int InternalReadDocument(int plugin_serial_number, int doc_id, IntPtr pBinaryArchive, IntPtr pReadOptions) { int rc = 1; //TRUE PlugIn p = LookUpBySerialNumber(plugin_serial_number); RhinoDoc doc = RhinoDoc.FromId(doc_id); if (p != null && doc != null && pBinaryArchive != IntPtr.Zero && pReadOptions != IntPtr.Zero) { Rhino.FileIO.BinaryArchiveReader reader = new Rhino.FileIO.BinaryArchiveReader(pBinaryArchive); Rhino.FileIO.FileReadOptions ro = new Rhino.FileIO.FileReadOptions(pReadOptions); try { p.ReadDocument(doc, reader, ro); rc = reader.ReadErrorOccured ? 0 : 1; } catch (Exception ex) { HostUtils.ExceptionReport(ex); rc = 0; //FALSE } // in case someone tries to hold on to instances of these classes reader.ClearPointer(); ro.Dispose(); } return rc; }
private void pictureBox1_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(filename)) { return; } string ext = Path.GetExtension(filename).ToUpperInvariant(); if (FileUtils.ImageExtensions.Contains(ext)) { if (ModifierKeys.HasFlag(Keys.Control)) { string script = "!_-PictureFrame \"" + filename + "\""; Rhino.RhinoApp.RunScript(script, true); } else { using (Image image = Image.FromFile(filename)) { var clientRect = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ClientRectangle; var lineUpperLeft = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ClientToWorld(new Point(clientRect.X, clientRect.Y)); var lineLowerRight = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ClientToWorld(new Point(clientRect.X + clientRect.Width, clientRect.Y + clientRect.Height)); var lineLowerLeft = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ClientToWorld(new Point(clientRect.X, clientRect.Y + clientRect.Height)); var plane = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.ConstructionPlane(); double lineParam = 0; Rhino.Geometry.Intersect.Intersection.LinePlane(lineLowerLeft, plane, out lineParam); plane.Origin = lineLowerLeft.PointAt(lineParam); double distanceScreen = lineUpperLeft.DistanceTo(lineLowerRight.PointAt(0), false); double distanceImage = new Rhino.Geometry.Point2d(image.Width, image.Height).DistanceTo(Rhino.Geometry.Point2d.Origin); double scale = distanceScreen / distanceImage; Rhino.RhinoDoc.ActiveDoc.Objects.AddPictureFrame(plane, filename, false, image.Width * scale, image.Height * scale, false, false); Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); } } } if (ext.CompareTo(".GH") == 0) { string script = @"-grasshopper editor load document open """ + filename + @""""; Rhino.RhinoApp.RunScript(script, true); } if (ext.CompareTo(".RVB") == 0) { string file = File.ReadAllText(filename); if (file.IndexOf("Rhino.AddAlias") > 0) { string script = @"-_LoadScript """ + filename + @""""; Rhino.RhinoApp.RunScript(script, true); script = @"_RunScript"; Rhino.RhinoApp.RunScript(script, true); } else { string script = @"-_Runscript (" + file + ")"; Rhino.RhinoApp.RunScript(script, true); } } if (ext.CompareTo(".PY") == 0) { string script = @"-_RunPythonScript """ + filename + @""""; Rhino.RhinoApp.RunScript(script, true); } if (ext.CompareTo(".TXT") == 0) { System.Diagnostics.Process.Start(filename); } if (FileUtils.CadExtensions.Contains(ext)) { if (this.import) { Rhino.FileIO.FileReadOptions readOptions = new Rhino.FileIO.FileReadOptions(); readOptions.ImportMode = true; Rhino.RhinoDoc.ReadFile(filename, readOptions); } else { Rhino.FileIO.FileReadOptions readOptions = new Rhino.FileIO.FileReadOptions(); readOptions.ImportMode = false; readOptions.OpenMode = true; Rhino.RhinoDoc.ReadFile(filename, readOptions); } } }