예제 #1
0
        /// <summary>Defines file extensions that this export plug-in is designed to write.</summary>
        /// <param name="options">Options that specify how to write files.</param>
        /// <returns>A list of file types that can be exported.</returns>
        protected override Rhino.PlugIns.FileTypeList AddFileTypes(Rhino.FileIO.FileWriteOptions options)
        {
            var result = new Rhino.PlugIns.FileTypeList();

            result.AddFileType("Graphics Language Transfer Format (*.glTF)", "glTF");
            return(result);
        }
        private bool ImportDwg(RhinoDoc doc, RunMode mode)
        {
            bool result = false;

            try
            {
                string fileName = string.Empty;
                if (mode == Rhino.Commands.RunMode.Interactive)
                {
                    fileName = Rhino.Input.RhinoGet.GetFileName(Rhino.Input.Custom.GetFileNameMode.Open, null, "Import", Rhino.RhinoApp.MainWindow());
                }
                else
                {
                    Rhino.Input.RhinoGet.GetString("DWG file to import", false, ref fileName);
                }

                fileName = fileName.Trim();
                if (string.IsNullOrEmpty(fileName))
                {
                    return(false);
                }

                string rhinoFileName = fileName.Replace(".dwg", ".3dm");
                if (File.Exists(fileName) && Path.GetExtension(fileName).Contains("dwg"))
                {
                    /*
                     * FileReadOptions readOptions = new FileReadOptions();
                     * readOptions.BatchMode = true;
                     * bool opened = Rhino.RhinoDoc.ReadFile(fileName, readOptions);
                     */

                    string script    = string.Format("-Import \"{0}\" Enter", fileName);
                    bool   runScript = Rhino.RhinoApp.RunScript(script, false);

                    if (runScript)
                    {
                        Rhino.FileIO.FileWriteOptions options = new Rhino.FileIO.FileWriteOptions();
                        options.SuppressDialogBoxes = true;
                        bool saved = RhinoDoc.ActiveDoc.WriteFile(rhinoFileName, options);
                    }
                }
                if (File.Exists(rhinoFileName))
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(result);
        }
예제 #3
0
        /// <summary>
        /// Is called when a user requests to export a ."glTF file.
        /// It is actually up to this method to write 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 Rhino.PlugIns.WriteFileResult WriteFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileWriteOptions options)
        {
            ext = Path.GetExtension(filename);
            var originalDir = Path.GetDirectoryName(filename);
            var file        = Path.GetFileName(filename);

            file = Path.ChangeExtension(file, ".3dm");
            var tmp = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Guid.NewGuid().ToString());
            var dir = Directory.CreateDirectory(tmp);

            Watcher                     = new FileSystemWatcher(tmp);
            Watcher.Created            += Watcher_Created;
            Watcher.EnableRaisingEvents = true;

            var tmpName = Path.Combine(tmp, file);

            GLTFExporterMethods.Write3dm(doc, options, tmpName);
            GLTFExporterMethods.LaunchNodeProcess(tmpName);

            while (tmpFileName == null)
            {
            }

            // move file according to original filename

            File.Copy(tmpFileName, filename, true);

            tmpFileName = null;

            // cleanup

            Watcher.Created -= Watcher_Created;
            Watcher.Dispose();

            var di = new DirectoryInfo(tmp);

            foreach (FileInfo f in di.GetFiles())
            {
                f.Delete();
            }
            foreach (DirectoryInfo d in di.GetDirectories())
            {
                d.Delete(true);
            }

            Directory.Delete(tmp, true);

            return(Rhino.PlugIns.WriteFileResult.Success);
        }