public override void RenderScene(View dBView, DisplayStyle displayStyle) { try { BuildScene(dBView); DrawContext.SetWorldTransform(Transform.Identity.ScaleBasis(1.0 / Revit.ModelUnits)); var CropBox = new Rhino.Geometry.BoundingBox(dBView.CropBox.Min.ToRhino(), dBView.CropBox.Max.ToRhino()).Scale(Revit.ModelUnits); foreach (var primitive in primitives) { if (DrawContext.IsInterrupted()) { break; } if (dBView.CropBoxActive && !Rhino.Geometry.BoundingBox.Intersection(CropBox, primitive.ClippingBox).IsValid) { continue; } primitive.Draw(displayStyle); } } catch (Exception e) { Debug.Fail(e.Source, e.Message); } }
/// <summary> /// Fast test to check if a bounding box intersects a pick frustum. /// </summary> /// <param name="box"></param> /// <param name="boxCompletelyInFrustum"> /// Set to true if the box is completely contained in the pick frustum. /// When doing a window or crossing pick, you can immediately return a /// hit if the object's bounding box is completely inside of the pick frustum. /// </param> /// <returns> /// False if bbox is invalid or box does not intersect the pick frustum /// </returns> public bool PickFrustumTest(Rhino.Geometry.BoundingBox box, out bool boxCompletelyInFrustum) { boxCompletelyInFrustum = false; IntPtr pConstThis = ConstPointer(); return(UnsafeNativeMethods.CRhinoPickContext_PickBox(pConstThis, ref box, ref boxCompletelyInFrustum)); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Mesh; Rhino.DocObjects.ObjRef objref = null; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select mesh to contour", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Mesh mesh = objref.Geometry() as Rhino.Geometry.Mesh; if (null == mesh) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.BoundingBox bbox = mesh.GetBoundingBox(false); Rhino.Geometry.Point3d start_pt = bbox.Corner(true, true, true); Rhino.Geometry.Point3d end_pt = bbox.Corner(false, true, true); double interval = start_pt.DistanceTo(end_pt) / 10; Rhino.Geometry.Curve[] curves = Rhino.Geometry.Mesh.CreateContourCurves(mesh, start_pt, end_pt, interval); if (null != curves && curves.Length > 0) { for (int i = 0; i < curves.Length; i++) { doc.Objects.AddCurve(curves[i]); } doc.Views.Redraw(); } return(Result.Success); }
public void SetPoints(IEnumerable <Rhino.Geometry.Point3d> points, System.Drawing.Color blendColor) { m_order = new LinkedList <DirectedOrder>(); List <Rhino.Geometry.Point3d> _points = new List <Geometry.Point3d>(points); m_points = _points.ToArray(); m_colors_argb = new int[] { blendColor.ToArgb() }; m_bbox = new Geometry.BoundingBox(m_points); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Select objects to define block Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select surface or polysurface to box morph"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Brep; go.SubObjectSelect = false; go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.Geometry.Brep brep = go.Object(0).Brep(); if (null == brep) { return(Result.Failure); } Rhino.Geometry.BoundingBox bbox = brep.GetBoundingBox(true); // The original box points Rhino.Geometry.Point3d[] box = new Rhino.Geometry.Point3d[8]; box[0] = bbox.Corner(true, true, true); box[1] = bbox.Corner(false, true, true); box[2] = bbox.Corner(false, false, true); box[3] = bbox.Corner(true, false, true); box[4] = bbox.Corner(true, true, false); box[5] = bbox.Corner(false, true, false); box[6] = bbox.Corner(false, false, false); box[7] = bbox.Corner(true, false, false); // The modified box points Rhino.Geometry.Point3d[] corners = new Rhino.Geometry.Point3d[8]; corners[0] = box[0]; corners[1] = box[1]; corners[2] = box[2]; corners[3] = box[3]; corners[4] = box[4]; corners[5] = box[5]; corners[6] = box[6] * 2; // some goofy point corners[7] = box[7]; BoxMorph box_morph = new BoxMorph(box, corners); if (box_morph.IsValid() && !box_morph.IsIdentity()) { if (box_morph.Morph(brep)) { doc.Objects.Add(brep); doc.Views.Redraw(); } } return(Result.Success); }
public void Clear() { foreach (var buffer in primitives) { ((IDisposable)buffer).Dispose(); } primitives.Clear(); primitivesBoundingBox = Rhino.Geometry.BoundingBox.Empty; }
protected override void CalculateBoundingBox(Rhino.Display.CalculateBoundingBoxEventArgs e) { if (null != Mesh) { Rhino.Geometry.BoundingBox bbox = Mesh.GetBoundingBox(false); // Unites a bounding box with the current display bounding box in // order to ensure dynamic objects in "box" are drawn. e.IncludeBoundingBox(bbox); } }
/// <summary> /// Dynamically set the frustum based on the clipping /// </summary> protected void SetFrustum(ViewportInfo viewport, Rhino.Geometry.BoundingBox bBox) { ClippingInfo clipping = new ClippingInfo(); clipping.bbox = bBox; if (ClippingPlanes.CalcClippingPlanes(viewport, clipping)) { ClippingPlanes.SetupFrustum(viewport, clipping); } }
//Update illustrator doc bound if docbox changes in rhino. public static void docBoxChanges(Rhino.DocObjects.RhinoObject docBox) { //Parse rectangle from incoming RhinoObject. Guid incomingGuid = docBox.Id; Rhino.Geometry.Curve newCurve = null; Rhino.DocObjects.ObjRef oRef = new Rhino.DocObjects.ObjRef(incomingGuid); newCurve = oRef.Curve(); Rhino.Geometry.BoundingBox newDimsBox = newCurve.GetBoundingBox(false); Rhino.Geometry.Point3d newMinPoint = newDimsBox.Min; Rhino.Geometry.Point3d newMaxPoint = newDimsBox.Max; double newWidth = newMaxPoint.X - newMinPoint.X; double newHeight = newMaxPoint.Y - newMinPoint.Y; int conversion = utils.units.conversion(); //Compare previous size, or record if first run. string D01_Path = utils.file_structure.getPathFor("D01"); string jsxPath = utils.file_structure.getJavascriptPath(); if (System.IO.File.Exists(D01_Path) == false) { string newData = newWidth.ToString() + "|" + newHeight.ToString(); System.IO.File.WriteAllText(D01_Path, newData); } else if (System.IO.File.Exists(D01_Path) == true) { //If file exists, verify bounds changed. (Otherwise, box moved.) string[] oldData = System.IO.File.ReadAllText(D01_Path).Split('|'); double oldWidth = Convert.ToDouble(oldData[0]); double oldHeight = Convert.ToDouble(oldData[1]); //utils.debug.ping(0, "Width change: " + newWidth.ToString() + " - " + oldWidth.ToString()); if (oldWidth == newWidth && oldHeight == newHeight) { //outbound.push.fullReset(); } else { string newData = newWidth.ToString() + "|" + newHeight.ToString(); System.IO.File.WriteAllText(D01_Path, newData); echo.interop echo = new echo.interop(); echo.docBounds(newWidth, newHeight, conversion, jsxPath); //outbound.push.fullReset(); } } }
public static void ResetDocumentUnits(Rhino.RhinoDoc rhinoDoc, Document bricscadDoc = null) { bool docModified = rhinoDoc.Modified; if (bricscadDoc == null) { rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.None; } else { var units = bricscadDoc.Database.Insunits; rhinoDoc.ModelUnitSystem = units.ToRhino(); bool imperial = rhinoDoc.ModelUnitSystem == Rhino.UnitSystem.Feet || rhinoDoc.ModelUnitSystem == Rhino.UnitSystem.Inches; { var modelPlane = Rhino.Geometry.Plane.WorldXY; var modelGridSpacing = imperial ? 1.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Yards, rhinoDoc.ModelUnitSystem) : 1.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Meters, rhinoDoc.ModelUnitSystem); var modelSnapSpacing = imperial ? 1 / 16.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Inches, rhinoDoc.ModelUnitSystem) : 1.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Millimeters, rhinoDoc.ModelUnitSystem); var modelThickLineFrequency = imperial ? 6 : 5; foreach (var view in rhinoDoc.Views) { var cplane = view.MainViewport.GetConstructionPlane(); cplane.GridSpacing = modelGridSpacing; cplane.SnapSpacing = modelSnapSpacing; cplane.ThickLineFrequency = modelThickLineFrequency; view.MainViewport.SetConstructionPlane(cplane); var min = cplane.Plane.PointAt(-cplane.GridSpacing * cplane.GridLineCount, -cplane.GridSpacing * cplane.GridLineCount, 0.0); var max = cplane.Plane.PointAt(+cplane.GridSpacing * cplane.GridLineCount, +cplane.GridSpacing * cplane.GridLineCount, 0.0); var bbox = new Rhino.Geometry.BoundingBox(min, max); // Zoom to grid view.MainViewport.ZoomBoundingBox(bbox); // Adjust to extens in case There is anything in the viewports like Grasshopper previews. view.MainViewport.ZoomExtents(); } } } rhinoDoc.Modified = docModified; }
Rhino.Geometry.BoundingBox BuildScene(View dBView) { if (Interlocked.Exchange(ref RebuildPrimitives, 0) != 0) { primitivesBoundingBox = Rhino.Geometry.BoundingBox.Empty; // Dispose previous primitives { foreach (var primitive in primitives) { ((IDisposable)primitive).Dispose(); } primitives.Clear(); } var previewColour = activeDefinition.PreviewColour; var previewColourSelected = activeDefinition.PreviewColourSelected; foreach (var obj in activeDefinition.Objects.OfType <IGH_ActiveObject>()) { if (obj.Locked) { continue; } if (obj is IGH_PreviewObject previewObject) { if (previewObject.IsPreviewCapable) { primitivesBoundingBox = Rhino.Geometry.BoundingBox.Union(primitivesBoundingBox, previewObject.ClippingBox); if (obj is IGH_Component component) { foreach (var param in component.Params.Output) { DrawData(param.VolatileData, obj); } } else if (obj is IGH_Param param) { DrawData(param.VolatileData, obj); } } } } } return(primitivesBoundingBox); }
public static Rhino.Commands.Result AddBrepBox(Rhino.RhinoDoc doc) { Rhino.Geometry.Point3d pt0 = new Rhino.Geometry.Point3d(0, 0, 0); Rhino.Geometry.Point3d pt1 = new Rhino.Geometry.Point3d(10, 10, 10); Rhino.Geometry.BoundingBox box = new Rhino.Geometry.BoundingBox(pt0, pt1); Rhino.Geometry.Brep brep = box.ToBrep(); Rhino.Commands.Result rc = Rhino.Commands.Result.Failure; if( doc.Objects.AddBrep(brep) != System.Guid.Empty ) { rc = Rhino.Commands.Result.Success; doc.Views.Redraw(); } return rc; }
public static Rhino.Commands.Result AddBrepBox(Rhino.RhinoDoc doc) { Rhino.Geometry.Point3d pt0 = new Rhino.Geometry.Point3d(0, 0, 0); Rhino.Geometry.Point3d pt1 = new Rhino.Geometry.Point3d(10, 10, 10); Rhino.Geometry.BoundingBox box = new Rhino.Geometry.BoundingBox(pt0, pt1); Rhino.Geometry.Brep brep = box.ToBrep(); Rhino.Commands.Result rc = Rhino.Commands.Result.Failure; if (doc.Objects.AddBrep(brep) != System.Guid.Empty) { rc = Rhino.Commands.Result.Success; doc.Views.Redraw(); } return(rc); }
private static void UpdateViewConstructionPlanes(Rhino.RhinoDoc rhinoDoc, Document revitDoc) { if (!string.IsNullOrEmpty(rhinoDoc.TemplateFileUsed)) { return; } if (rhinoDoc.IsCreating) { Revit.EnqueueAction(doc => UpdateViewConstructionPlanes(rhinoDoc, doc)); return; } bool imperial = rhinoDoc.ModelUnitSystem == Rhino.UnitSystem.Feet || rhinoDoc.ModelUnitSystem == Rhino.UnitSystem.Inches; var modelGridSpacing = imperial ? 1.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Yards, rhinoDoc.ModelUnitSystem) : 1.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Meters, rhinoDoc.ModelUnitSystem); var modelSnapSpacing = imperial ? 1 / 16.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Inches, rhinoDoc.ModelUnitSystem) : 1.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Millimeters, rhinoDoc.ModelUnitSystem); var modelThickLineFrequency = imperial ? 6 : 5; // Views { foreach (var view in rhinoDoc.Views) { var cplane = view.MainViewport.GetConstructionPlane(); cplane.GridSpacing = modelGridSpacing; cplane.SnapSpacing = modelSnapSpacing; cplane.ThickLineFrequency = modelThickLineFrequency; view.MainViewport.SetConstructionPlane(cplane); var min = cplane.Plane.PointAt(-cplane.GridSpacing * cplane.GridLineCount, -cplane.GridSpacing * cplane.GridLineCount, 0.0); var max = cplane.Plane.PointAt(+cplane.GridSpacing * cplane.GridLineCount, +cplane.GridSpacing * cplane.GridLineCount, 0.0); var bbox = new Rhino.Geometry.BoundingBox(min, max); // Zoom to grid view.MainViewport.ZoomBoundingBox(bbox); // Adjust to extens in case There is anything in the viewports like Grasshopper previews. view.MainViewport.ZoomExtents(); } } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Define a unit Brep box Rhino.Geometry.Point3d min = new Rhino.Geometry.Point3d(0.0, 0.0, 0.0); Rhino.Geometry.Point3d max = new Rhino.Geometry.Point3d(1.0, 1.0, 1.0); Rhino.Geometry.BoundingBox bbox = new Rhino.Geometry.BoundingBox(min, max); Rhino.Geometry.Brep brep = Rhino.Geometry.Brep.CreateFromBox(bbox); // Add a copy to the document doc.Objects.AddBrep(brep); // Create and define the arguments of the array SampleCsArrayArgs args = new SampleCsArrayArgs(); args.CountX = 10; args.CountY = 10; args.CountZ = 10; args.DistanceX = 1.0; args.DistanceY = 1.0; args.DistanceZ = 1.0; // Calculate the offsets args.CalculateOffsets(); // Array the unit Brep box for (int i = 0; i < args.Offsets.Count; i++) { // Skip the first one... if (!args.Offsets[i].IsZero) { Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.Translation(args.Offsets[i]); if (xform.IsValid && xform != Rhino.Geometry.Transform.Identity) { Rhino.Geometry.Brep dupBrep = brep.DuplicateBrep(); dupBrep.Transform(xform); if (dupBrep.IsValid) { doc.Objects.AddBrep(dupBrep); } } } } doc.Views.Redraw(); return(Result.Success); }
public void SetPoints(IEnumerable <Rhino.Geometry.Point3d> points, IEnumerable <System.Drawing.Color> colors) { var _points = new List <Geometry.Point3d>(points); var _colors = new List <System.Drawing.Color>(colors); if (_points.Count != _colors.Count) { throw new ArgumentException("length of points must be the same as length of colors"); } m_order = new LinkedList <DirectedOrder>(); m_points = _points.ToArray(); m_colors_argb = new int[_colors.Count]; for (int i = 0; i < _colors.Count; i++) { m_colors_argb[i] = _colors[i].ToArgb(); } m_bbox = new Geometry.BoundingBox(m_points); }
Rhino.Geometry.BoundingBox BuildScene(View dBView) { if (!primitivesBoundingBox.IsValid) { var previewColour = activeDefinition.PreviewColour; var previewColourSelected = activeDefinition.PreviewColourSelected; foreach (var obj in activeDefinition.Objects.OfType <IGH_ActiveObject>()) { if (obj.Locked) { continue; } if (obj is IGH_PreviewObject previewObject) { if (previewObject.IsPreviewCapable) { primitivesBoundingBox = Rhino.Geometry.BoundingBox.Union(primitivesBoundingBox, previewObject.ClippingBox); if (obj is IGH_Component component) { foreach (var param in component.Params.Output) { DrawData(param.VolatileData, obj); } } else if (obj is IGH_Param param) { DrawData(param.VolatileData, obj); } } } } } return(primitivesBoundingBox); }
/// <summary> /// Called once at the start of an animation. This can be used to extend the scene bounding box to avoid clipping. /// </summary> /// <param name="doc">doc is the current document.</param> /// <param name="archive_start">archive_start is a archive to the data of the starting position.</param> /// <param name="archive_stop">archive_stop is a archive to the data of the ending position.</param> /// <param name="bbox">bbox is the current scene bounding box.</param> /// <since>6.0</since> public abstract void ExtendBoundingBoxForDocumentAnimation(RhinoDoc doc, BinaryArchiveReader archive_start, BinaryArchiveReader archive_stop, ref Rhino.Geometry.BoundingBox bbox);
protected override void SolveInstance(IGH_DataAccess DA) { var points = new List <Rhino.Geometry.Point3d>(); if (!DA.GetDataList("Points", points)) { return; } var tolerance = 0.0; if (!DA.GetData("Tolerance", ref tolerance)) { return; } var boundingBox = true; if (!DA.GetData("BoundingBox", ref boundingBox)) { return; } var strict = true; if (!DA.GetData("Strict", ref strict)) { return; } var inverted = false; if (!DA.GetData("Inverted", ref inverted)) { return; } var scaleFactor = 1.0 / Revit.ModelUnits; var targets = new List <Rhino.Geometry.Box>(); Autodesk.Revit.DB.ElementFilter filter = null; if (boundingBox) { var pointsBBox = new Rhino.Geometry.BoundingBox(points); { var box = new Rhino.Geometry.Box(pointsBBox); box.Inflate(tolerance); targets.Add(box); } pointsBBox = pointsBBox.ChangeUnits(scaleFactor); var outline = new Autodesk.Revit.DB.Outline(pointsBBox.Min.ToHost(), pointsBBox.Max.ToHost()); if (strict) { filter = new Autodesk.Revit.DB.BoundingBoxIsInsideFilter(outline, tolerance * scaleFactor, inverted); } else { filter = new Autodesk.Revit.DB.BoundingBoxIntersectsFilter(outline, tolerance * scaleFactor, inverted); } } else { var filters = points.Select <Rhino.Geometry.Point3d, Autodesk.Revit.DB.ElementFilter> (x => { var pointsBBox = new Rhino.Geometry.BoundingBox(x, x); { var box = new Rhino.Geometry.Box(pointsBBox); box.Inflate(tolerance); targets.Add(box); } x = x.ChangeUnits(scaleFactor); if (strict) { var outline = new Autodesk.Revit.DB.Outline(x.ToHost(), x.ToHost()); return(new Autodesk.Revit.DB.BoundingBoxIsInsideFilter(outline, tolerance * scaleFactor, inverted)); } else { return(new Autodesk.Revit.DB.BoundingBoxContainsPointFilter(x.ToHost(), tolerance * scaleFactor, inverted)); } }); var filterList = filters.ToArray(); filter = filterList.Length == 1 ? filterList[0] : new Autodesk.Revit.DB.LogicalOrFilter(filterList); } DA.SetData("Filter", filter); DA.SetDataList("Target", targets); }
public bool SolveOptionalLevel(DB.Document doc, Rhino.Geometry.Line line, ref Optional <DB.Level> level, out Rhino.Geometry.BoundingBox bbox) { bbox = line.BoundingBox; return(SolveOptionalLevel(doc, bbox.IsValid ? bbox.Min.Z : double.NaN, ref level)); }
public bool SolveOptionalLevel(DB.Document doc, Rhino.Geometry.GeometryBase geometry, ref Optional <DB.Level> level, out Rhino.Geometry.BoundingBox bbox) { bbox = geometry.GetBoundingBox(true); return(SolveOptionalLevel(doc, bbox.IsValid ? bbox.Min.Z : double.NaN, ref level)); }
public Primitive(Rhino.Geometry.Mesh m, Part p) { geometry = m; ClippingBox = geometry.GetBoundingBox(false); part = p; }
public Primitive(Rhino.Geometry.Curve c) { geometry = c; ClippingBox = geometry.GetBoundingBox(false); }
public Primitive(Rhino.Geometry.PointCloud pc, Part p) { geometry = pc; ClippingBox = geometry.GetBoundingBox(false); part = p; }
public Primitive(Rhino.Geometry.Point p) { geometry = p; ClippingBox = geometry.GetBoundingBox(false); }
public bool SolveOptionalLevel(DB.Document doc, Rhino.Geometry.Point3d point, ref Optional <DB.Level> level, out Rhino.Geometry.BoundingBox bbox) { bbox = new Rhino.Geometry.BoundingBox(point, point); return(SolveOptionalLevel(doc, point.IsValid ? point.Z : double.NaN, ref level)); }
public bool SolveOptionalLevel(DB.Document doc, IEnumerable <Rhino.Geometry.GeometryBase> geometries, ref Optional <DB.Level> level, out Rhino.Geometry.BoundingBox bbox) { bbox = Rhino.Geometry.BoundingBox.Empty; foreach (var geometry in geometries) { bbox = geometry.GetBoundingBox(true); } return(SolveOptionalLevel(doc, bbox.IsValid ? bbox.Min.Z : double.NaN, ref level)); }
/***************************************************/ public virtual Rhino.Geometry.BoundingBox GetBoundingBox(Rhino.Geometry.Transform xform) { Rhino.Geometry.BoundingBox box = Bounds(); box.Transform(xform); return(box); }
/// <summary> /// Called once at the start of an animation. This can be used to extend the scene bounding box to avoid clipping. /// </summary> /// <param name="doc">doc is the current document.</param> /// <param name="doc_object">doc_obj is the current object.</param> /// <param name="transform">transform is a transformation matrix. The matrix is set to identity the first time an object is associated with a snapshot. /// After that the matrix is updated when the object is transformed(scale, rotate etc.).</param> /// <param name="archive_start">archive_start is a archive to the data of the starting position.</param> /// <param name="archive_stop">archive_stop is a archive to the data of the ending position.</param> /// <param name="bbox">bbox is the current scene bounding box.</param> /// <since>6.0</since> public abstract void ExtendBoundingBoxForObjectAnimation(RhinoDoc doc, Rhino.DocObjects.RhinoObject doc_object, ref Rhino.Geometry.Transform transform, BinaryArchiveReader archive_start, BinaryArchiveReader archive_stop, ref Rhino.Geometry.BoundingBox bbox);
public static void ResetDocumentUnits(Rhino.RhinoDoc rhinoDoc, Document revitDoc = null) { bool docModified = rhinoDoc.Modified; if (revitDoc == null) { rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.None; rhinoDoc.ModelAbsoluteTolerance = Revit.VertexTolerance; rhinoDoc.ModelAngleToleranceRadians = Revit.AngleTolerance; } else { var units = revitDoc.GetUnits(); var lengthFormatoptions = units.GetFormatOptions(UnitType.UT_Length); switch (lengthFormatoptions.DisplayUnits) { case DisplayUnitType.DUT_METERS: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.Meters; break; case DisplayUnitType.DUT_METERS_CENTIMETERS: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.Meters; break; case DisplayUnitType.DUT_DECIMETERS: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.Decimeters; break; case DisplayUnitType.DUT_CENTIMETERS: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.Centimeters; break; case DisplayUnitType.DUT_MILLIMETERS: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.Millimeters; break; case DisplayUnitType.DUT_FRACTIONAL_INCHES: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.Inches; break; case DisplayUnitType.DUT_DECIMAL_INCHES: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.Inches; break; case DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.Feet; break; case DisplayUnitType.DUT_DECIMAL_FEET: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.Feet; break; default: rhinoDoc.ModelUnitSystem = Rhino.UnitSystem.None; break; } bool imperial = rhinoDoc.ModelUnitSystem == Rhino.UnitSystem.Feet || rhinoDoc.ModelUnitSystem == Rhino.UnitSystem.Inches; rhinoDoc.ModelAngleToleranceRadians = Revit.AngleTolerance; rhinoDoc.ModelDistanceDisplayPrecision = ((int)-Math.Log10(lengthFormatoptions.Accuracy)).Clamp(0, 7); rhinoDoc.ModelAbsoluteTolerance = Revit.VertexTolerance * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Feet, rhinoDoc.ModelUnitSystem); //switch (rhinoDoc.ModelUnitSystem) //{ // case Rhino.UnitSystem.None: break; // case Rhino.UnitSystem.Feet: // case Rhino.UnitSystem.Inches: // newDoc.ModelAbsoluteTolerance = (1.0 / 160.0) * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Inches, newDoc.ModelUnitSystem); // break; // default: // newDoc.ModelAbsoluteTolerance = 0.1 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Millimeters, newDoc.ModelUnitSystem); // break; //} // Construction Planes { var modelPlane = Rhino.Geometry.Plane.WorldXY; var modelGridSpacing = imperial ? 1.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Yards, rhinoDoc.ModelUnitSystem) : 1.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Meters, rhinoDoc.ModelUnitSystem); var modelSnapSpacing = imperial ? 1 / 16.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Inches, rhinoDoc.ModelUnitSystem) : 1.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Millimeters, rhinoDoc.ModelUnitSystem); var modelThickLineFrequency = imperial ? 6 : 5; foreach (var view in rhinoDoc.Views) { var cplane = view.MainViewport.GetConstructionPlane(); cplane.GridSpacing = modelGridSpacing; cplane.SnapSpacing = modelSnapSpacing; cplane.ThickLineFrequency = modelThickLineFrequency; view.MainViewport.SetConstructionPlane(cplane); var min = cplane.Plane.PointAt(-cplane.GridSpacing * cplane.GridLineCount, -cplane.GridSpacing * cplane.GridLineCount, 0.0); var max = cplane.Plane.PointAt(+cplane.GridSpacing * cplane.GridLineCount, +cplane.GridSpacing * cplane.GridLineCount, 0.0); var bbox = new Rhino.Geometry.BoundingBox(min, max); // Zoom to grid view.MainViewport.ZoomBoundingBox(bbox); // Adjust to extens in case There is anything in the viewports like Grasshopper previews. view.MainViewport.ZoomExtents(); } } } rhinoDoc.Modified = docModified; }