public static Rhino.PlugIns.WriteFileResult Export(string Filename, RhinoDoc RhinoDocument, Rhino.FileIO.FileWriteOptions Options) { string RhinoAppName = Rhino.RhinoApp.Name; string RhinoVersion = Rhino.RhinoApp.ExeVersion.ToString(); FDatasmithFacadeElement.SetCoordinateSystemType(FDatasmithFacadeElement.ECoordinateSystemType.RightHandedZup); FDatasmithFacadeElement.SetWorldUnitScale((float)Rhino.RhinoMath.UnitScale(RhinoDocument.ModelUnitSystem, UnitSystem.Centimeters)); FDatasmithFacadeScene DatasmithScene = new FDatasmithFacadeScene("Rhino", "Robert McNeel & Associates", "Rhino3D", RhinoVersion); DatasmithScene.PreExport(); try { RhinoApp.WriteLine(string.Format("Exporting to {0}.", System.IO.Path.GetFileName(Filename))); RhinoApp.WriteLine("Press Esc key to cancel..."); FDatasmithRhinoProgressManager.Instance.StartMainTaskProgress("Parsing Document", 0.1f); DatasmithRhinoSceneParser SceneParser = new DatasmithRhinoSceneParser(RhinoDocument, Options); SceneParser.ParseDocument(); if (ExportScene(SceneParser, DatasmithScene) == Rhino.Commands.Result.Success) { string SceneName = System.IO.Path.GetFileName(Filename); FDatasmithRhinoProgressManager.Instance.StartMainTaskProgress("Writing to files..", 1); DatasmithScene.ExportScene(Filename); } } catch (DatasmithExportCancelledException) { return(Rhino.PlugIns.WriteFileResult.Cancel); } catch (Exception e) { RhinoApp.WriteLine("An unexpected error has occured:"); RhinoApp.WriteLine(e.ToString()); return(Rhino.PlugIns.WriteFileResult.Failure); } finally { FDatasmithRhinoProgressManager.Instance.StopProgress(); } return(Rhino.PlugIns.WriteFileResult.Success); }
// OnViewBegin marks the beginning of a 3D view to be exported. public RenderNodeAction OnViewBegin( ViewNode InViewNode // render node associated with the 3D view ) { // Set the level of detail when tessellating faces (between -1 and 15). InViewNode.LevelOfDetail = LevelOfTessellation; // Initialize the world transform for the 3D view being processed. WorldTransformStack.Push(Transform.Identity); // Create an empty Datasmith scene. if (DirectLink != null) { DirectLink.OnBeginExport(); DatasmithScene = DirectLink.DatasmithScene; } else { DatasmithScene = new FDatasmithFacadeScene(HOST_NAME, VENDOR_NAME, PRODUCT_NAME, ProductVersion); } DatasmithScene.PreExport(); View3D ViewToExport = RevitDocument.GetElement(InViewNode.ViewId) as View3D; if (DatasmithFilePaths != null && !DatasmithFilePaths.TryGetValue(ViewToExport.Id, out CurrentDatasmithFilePath)) { return(RenderNodeAction.Skip); // TODO log error? } // Keep track of the active Revit document being exported. PushDocument(RevitDocument); // Add a new camera actor to the Datasmith scene for the 3D view camera. AddCameraActor(ViewToExport, InViewNode.GetCameraInfo()); // We want to export the 3D view. return(RenderNodeAction.Proceed); }