public static Rhino.Commands.Result AddClippingPlane(Rhino.RhinoDoc doc) { // Define the corners of the clipping plane Rhino.Geometry.Point3d[] corners; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners); if (rc != Rhino.Commands.Result.Success) return rc; // Get the active view Rhino.Display.RhinoView view = doc.Views.ActiveView; if (view == null) return Rhino.Commands.Result.Failure; Rhino.Geometry.Point3d p0 = corners[0]; Rhino.Geometry.Point3d p1 = corners[1]; Rhino.Geometry.Point3d p3 = corners[3]; // Create a plane from the corner points Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(p0, p1, p3); // Add a clipping plane object to the document Guid id = doc.Objects.AddClippingPlane(plane, p0.DistanceTo(p1), p0.DistanceTo(p3), view.ActiveViewportID); if (id != Guid.Empty) { doc.Views.Redraw(); return Rhino.Commands.Result.Success; } return Rhino.Commands.Result.Failure; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Geometry.Point3d[] corners; Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners); if (rc != Result.Success) { return(rc); } Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(corners[0], corners[1], corners[2]); Rhino.Geometry.Interval x_interval = new Rhino.Geometry.Interval(0, corners[0].DistanceTo(corners[1])); Rhino.Geometry.Interval y_interval = new Rhino.Geometry.Interval(0, corners[1].DistanceTo(corners[2])); Rhino.Geometry.Mesh mesh = Rhino.Geometry.Mesh.CreateFromPlane(plane, x_interval, y_interval, 10, 10); //mesh.FaceNormals.ComputeFaceNormals(); //mesh.Normals.ComputeNormals(); SampleCsDrawMeshConduit conduit = new SampleCsDrawMeshConduit(); conduit.Mesh = mesh; conduit.Enabled = true; doc.Views.Redraw(); string out_str = null; rc = Rhino.Input.RhinoGet.GetString("Press <Enter> to continue", true, ref out_str); conduit.Enabled = false; doc.Views.Redraw(); return(Result.Success); }
protected override void SolveInstance(IGH_DataAccess DA) { var location = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(double.NaN, double.NaN, double.NaN), new Rhino.Geometry.Vector3d(double.NaN, double.NaN, double.NaN)); DA.GetData("Position", ref location); FamilySymbol familySymbol = null; DA.GetData("Type", ref familySymbol); Autodesk.Revit.DB.Level level = null; DA.GetData("Level", ref level); if (level == null) { level = Revit.ActiveDBDocument.FindLevelByElevation(location.Origin.Z / Revit.ModelUnits); } Autodesk.Revit.DB.HostObject host = null; DA.GetData("Host", ref host); DA.DisableGapLogic(); int Iteration = DA.Iteration; Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, location, familySymbol, host, level)); }
public static Rhino.Commands.Result Stretch(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to stretch", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); Rhino.Geometry.Line axis; rc = Rhino.Input.RhinoGet.GetLine(out axis); if (rc != Rhino.Commands.Result.Success || axis == null) { return(rc); } Rhino.Geometry.Morphs.StretchSpaceMorph morph = new Rhino.Geometry.Morphs.StretchSpaceMorph(axis.From, axis.To, axis.Length * 1.5); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result AddClippingPlane(Rhino.RhinoDoc doc) { // Define the corners of the clipping plane Rhino.Geometry.Point3d[] corners; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners); if (rc != Rhino.Commands.Result.Success) { return(rc); } // Get the active view Rhino.Display.RhinoView view = doc.Views.ActiveView; if (view == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Point3d p0 = corners[0]; Rhino.Geometry.Point3d p1 = corners[1]; Rhino.Geometry.Point3d p3 = corners[3]; // Create a plane from the corner points Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(p0, p1, p3); // Add a clipping plane object to the document Guid id = doc.Objects.AddClippingPlane(plane, p0.DistanceTo(p1), p0.DistanceTo(p3), view.ActiveViewportID); if (id != Guid.Empty) { doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
public bool Cone(int index, ref Rhino.Geometry.Cone cone, ref Rhino.Geometry.Plane truncation) { Rhino.Geometry.Point3d origin = new Rhino.Geometry.Point3d(); Rhino.Geometry.Vector3d xaxis = new Rhino.Geometry.Vector3d(); Rhino.Geometry.Vector3d yaxis = new Rhino.Geometry.Vector3d(); double height = 0.0; double radius = 0.0; Rhino.Geometry.Point3d t_origin = new Rhino.Geometry.Point3d(); Rhino.Geometry.Vector3d t_xaxis = new Rhino.Geometry.Vector3d(); Rhino.Geometry.Vector3d t_yaxis = new Rhino.Geometry.Vector3d(); if (UnsafeNativeMethods.Rdk_CustomMeshes_Cone(ConstPointer(), index, ref origin, ref xaxis, ref yaxis, ref height, ref radius, ref t_origin, ref t_xaxis, ref t_yaxis)) { cone = new Rhino.Geometry.Cone(new Rhino.Geometry.Plane(origin, xaxis, yaxis), height, radius); truncation = new Rhino.Geometry.Plane(t_origin, t_xaxis, t_yaxis); return(true); } return(false); }
void CommitInstance ( Document doc, IGH_DataAccess DA, int Iteration, Rhino.Geometry.Plane plane ) { var element = PreviousElement(doc, Iteration); try { if (!plane.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' is not valid.", Params.Input[0].Name)); } else { var scaleFactor = 1.0 / Revit.ModelUnits; if (scaleFactor != 1.0) { plane = plane.Scale(scaleFactor); } element = SketchPlane.Create(doc, plane.ToHost()); } } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message); } finally { ReplaceElement(doc, DA, Iteration, element); } }
void ReconstructSketchPlaneByPlane ( Document doc, ref Autodesk.Revit.DB.Element element, Rhino.Geometry.Plane plane ) { if (!plane.IsValid) { ThrowArgumentException(nameof(plane), "Plane is not valid."); } var scaleFactor = 1.0 / Revit.ModelUnits; plane = plane.ChangeUnits(scaleFactor); if (element is SketchPlane sketchPlane) { bool pinned = element.Pinned; element.Pinned = false; var plane0 = sketchPlane.GetPlane(); using (var plane1 = plane.ToHost()) { if (!plane0.Normal.IsParallelTo(plane1.Normal)) { var axisDirection = plane0.Normal.CrossProduct(plane1.Normal); double angle = plane0.Normal.AngleTo(plane1.Normal); using (var axis = Line.CreateUnbound(plane0.Origin, axisDirection)) ElementTransformUtils.RotateElement(doc, element.Id, axis, angle); plane0 = sketchPlane.GetPlane(); } { double angle = plane0.XVec.AngleOnPlaneTo(plane1.XVec, plane1.Normal); if (angle != 0.0) { using (var axis = Line.CreateUnbound(plane0.Origin, plane1.Normal)) ElementTransformUtils.RotateElement(doc, element.Id, axis, angle); } } var trans = plane1.Origin - plane0.Origin; if (!trans.IsZeroLength()) { ElementTransformUtils.MoveElement(doc, element.Id, trans); } } element.Pinned = pinned; } else { ReplaceElement(ref element, SketchPlane.Create(doc, plane.ToHost())); } }
public void drawColumn(Rhino.Geometry.Point3d point1, Rhino.Geometry.Point3d point2, double radius) { Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(point1, new Rhino.Geometry.Vector3d((point2 - point1))); Rhino.Geometry.Circle c = new Rhino.Geometry.Circle(plane, point1, radius); Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(c.ToNurbsCurve(), new Rhino.Geometry.Vector3d((point2 - point1))); SetPreview(srf.ToBrep()); }
/// <summary> /// Create FdCoordinateSystem from Rhino plane. /// </summary> internal static FdCoordinateSystem FromRhinoPlane(this Rhino.Geometry.Plane obj) { FdPoint3d origin = obj.Origin.FromRhino(); FdVector3d localX = obj.XAxis.FromRhino(); FdVector3d localY = obj.YAxis.FromRhino(); FdVector3d localZ = obj.ZAxis.FromRhino(); return(new FdCoordinateSystem(origin, localX, localY, localZ)); }
public void drawExtrusion(Rhino.Geometry.Point3d point1, double height, double width, double thickness) { Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(point1, Rhino.Geometry.Vector3d.ZAxis); Rhino.Geometry.Point3d cornerA = new Rhino.Geometry.Point3d(point1.X - width / 2, point1.Y - height / 2, point1.Z); Rhino.Geometry.Point3d cornerB = new Rhino.Geometry.Point3d(point1.X + width / 2, point1.Y + height / 2, point1.Z); Rhino.Geometry.Rectangle3d rect = new Rhino.Geometry.Rectangle3d(plane, cornerA, cornerB); Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(rect.ToNurbsCurve(), new Rhino.Geometry.Vector3d(0, 0, thickness)); SetPreview(srf.ToBrep()); }
static public bool CreateSections(Rhino.RhinoDoc doc, Rhino.Geometry.GeometryBase geo, Rhino.Geometry.Surface surfaceB, Rhino.Geometry.Curve curve, double interval, ref List <PlanePoint> points) { Rhino.Geometry.Interval domain = curve.Domain; // fixed issue for (double t = domain.T0; t < domain.T1; t += interval) { Rhino.Geometry.Point3d pt = curve.PointAt(t); Rhino.Geometry.Vector3d tangent = curve.TangentAt(t); Rhino.Geometry.Vector3d curvature = curve.CurvatureAt(t); Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(); curve.FrameAt(t, out plane); doc.Objects.AddPoint(pt); curvature = curvature * 10.0; Rhino.Geometry.Line line = new Rhino.Geometry.Line(pt, curvature); doc.Objects.AddLine(line); RhinoApp.WriteLine("Curve at {0}", t); Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(); bool ret = false; if (geo is Rhino.Geometry.Brep) { Rhino.Geometry.Brep brepA = (Rhino.Geometry.Brep)geo; ret = GetNormalVector(brepA, pt, ref normal); RhinoApp.WriteLine(" Added Brep point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z); } else if (geo is Rhino.Geometry.Surface) { Rhino.Geometry.Surface surfaceA = (Rhino.Geometry.Surface)geo; ret = GetNormalVector(surfaceA, pt, ref normal); RhinoApp.WriteLine(" Added surface point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z); } if (ret) { Rhino.Geometry.Vector3d ucoord = CrossProduct(tangent, normal); Rhino.Geometry.Plane plane2 = new Rhino.Geometry.Plane(pt, ucoord, tangent); // normal); double[] parameters = plane2.GetPlaneEquation(); PlanePoint PlanePoint = new PlanePoint(); PlanePoint.pt = pt; PlanePoint.A = parameters[0]; PlanePoint.B = parameters[1]; PlanePoint.C = parameters[2]; PlanePoint.D = parameters[3]; PlanePoint.curvature = curvature; points.Add(PlanePoint); Rhino.Geometry.Interval Interval1 = new Rhino.Geometry.Interval(-0.1, -0.1); Rhino.Geometry.Interval Interval2 = new Rhino.Geometry.Interval(0.1, 0.1); Rhino.Geometry.PlaneSurface PlaneSurface = new Rhino.Geometry.PlaneSurface(plane2, Interval1, Interval2); doc.Objects.AddSurface(PlaneSurface); } } return(true); }
/// <summary> /// Find the Perspective viewport in the 3dm file and sets up the default view. /// </summary> public void LoadCamera() { if (App.Manager.CurrentModel == null) { return; } Camera = new ViewportInfo(); bool cameraIsInitialized = false; int viewCount = App.Manager.CurrentModel.ModelFile.Views.Count; // find first perspective viewport projection in file if (viewCount > 0) { foreach (var view in App.Manager.CurrentModel.ModelFile.Views) { if (view.Viewport.IsPerspectiveProjection) { cameraIsInitialized = true; Camera = view.Viewport; Camera.TargetPoint = view.Viewport.TargetPoint; Camera.SetScreenPort(0, (int)View.Bounds.Size.Width, 0, (int)View.Bounds.Size.Height, 1, 1000); Camera.FrustumAspect = Camera.ScreenPortAspect; Camera.SetFrustumNearFar(App.Manager.CurrentModel.BBox); break; } } } // If there isn't one, then cook up a viewport from scratch... if (!cameraIsInitialized) { Camera.SetScreenPort(0, (int)View.Bounds.Size.Width, 0, (int)View.Bounds.Size.Height, 1, 1000); Camera.TargetPoint = new Rhino.Geometry.Point3d(0, 0, 0); var plane = new Rhino.Geometry.Plane(Rhino.Geometry.Point3d.Origin, new Rhino.Geometry.Vector3d(-1, -1, -1)); Camera.SetCameraLocation(new Rhino.Geometry.Point3d(10, 10, 10)); var dir = new Rhino.Geometry.Vector3d(-1, -1, -1); dir.Unitize(); Camera.SetCameraDirection(dir); Camera.SetCameraUp(plane.YAxis); Camera.SetFrustum(-1, 1, -1, 1, 0.1, 1000); Camera.FrustumAspect = Camera.ScreenPortAspect; Camera.IsPerspectiveProjection = true; Camera.Camera35mmLensLength = 50; if (App.Manager.CurrentModel != null) { if (App.Manager.CurrentModel.AllMeshes != null) { Camera.DollyExtents(App.Manager.CurrentModel.AllMeshes, 1.0); } } } }
/// <summary> /// Constructor /// </summary> public SampleCsArrayArgs() { CountX = 1; CountY = 1; CountZ = 1; DistanceX = 0.0; DistanceY = 0.0; DistanceZ = 0.0; Plane = Rhino.Geometry.Plane.WorldXY; Offsets = new List <Rhino.Geometry.Vector3d>(); }
public void Add(Rhino.Geometry.Cone cone, Rhino.Geometry.Plane truncation, RenderMaterial material) { UnsafeNativeMethods.Rdk_CustomMeshes_AddCone(NonConstPointer(), cone.BasePoint, cone.Plane.XAxis, cone.Plane.YAxis, cone.Height, cone.Radius, truncation.Origin, truncation.XAxis, truncation.YAxis, material.ConstPointer()); }
/// <summary> /// Intersects a curve and an infinite line. /// </summary> /// <param name="curve">Curve to intersect.</param> /// <param name="line">Infinite line to intesect.</param> /// <param name="tolerance">If the distance from a point on curve to line /// is <= tolerance, then the point will be part of an intersection /// event. If the tolerance <= 0.0, then 0.001 is used.</param> /// <param name="overlapTolerance">If t1 and t2 are parameters of curve's /// intersection events and the distance from curve(t) to line is <= /// overlapTolerance for every t1 <= t <= t2, then the event will /// be returened as an overlap event. If overlapTolerance <= 0.0, /// then tolerance * 2.0 is used.</param> /// <returns>A collection of intersection events.</returns> public static Rhino.Geometry.Intersect.CurveIntersections IntersectCurveLine( Rhino.Geometry.Curve curve, Rhino.Geometry.Line line, double tolerance, double overlapTolerance ) { if (!curve.IsValid || !line.IsValid || line.Length < Rhino.RhinoMath.SqrtEpsilon) { return(null); } // Extend the line through the curve's bounding box var bbox = curve.GetBoundingBox(false); if (!bbox.IsValid) { return(null); } var dir = line.Direction; dir.Unitize(); var points = bbox.GetCorners(); var plane = new Rhino.Geometry.Plane(line.From, dir); double max_dist; var min_dist = max_dist = plane.DistanceTo(points[0]); for (var i = 1; i < points.Length; i++) { var dist = plane.DistanceTo(points[i]); if (dist < min_dist) { min_dist = dist; } if (dist > max_dist) { max_dist = dist; } } // +- 1.0 makes the line a little bigger than the bounding box line.From = line.From + dir * (min_dist - 1.0); line.To = line.From + dir * (max_dist + 1.0); // Calculate curve-curve intersection var line_curve = new Rhino.Geometry.LineCurve(line); return(Rhino.Geometry.Intersect.Intersection.CurveCurve(curve, line_curve, tolerance, overlapTolerance)); }
public static Rhino.Commands.Result AddTorus(Rhino.RhinoDoc doc) { const double major_radius = 4.0; const double minor_radius = 2.0; Rhino.Geometry.Plane plane = Rhino.Geometry.Plane.WorldXY; Rhino.Geometry.Torus torus = new Rhino.Geometry.Torus(plane, major_radius, minor_radius); Rhino.Geometry.RevSurface revsrf = torus.ToRevSurface(); if (doc.Objects.AddSurface(revsrf) != Guid.Empty) { doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
public static Rhino.Commands.Result Maelstrom(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to maelstrom", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); double radius0 = Rhino.RhinoMath.UnsetValue; rc = Rhino.Input.RhinoGet.GetNumber("Starting radius", false, ref radius0); if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius0)) { return(rc); } double radius1 = Rhino.RhinoMath.UnsetValue; rc = Rhino.Input.RhinoGet.GetNumber("Ending radius", false, ref radius1); if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius1)) { return(rc); } double angle = Rhino.RhinoMath.UnsetValue; rc = Rhino.Input.RhinoGet.GetNumber("Twist angle in degrees", false, ref angle); if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(angle)) { return(rc); } Rhino.Geometry.Morphs.MaelstromSpaceMorph morph = new Rhino.Geometry.Morphs.MaelstromSpaceMorph(plane, radius0, radius1, Rhino.RhinoMath.ToRadians(angle)); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result AddCylinder(Rhino.RhinoDoc doc) { Rhino.Geometry.Point3d center_point = new Rhino.Geometry.Point3d(0, 0, 0); Rhino.Geometry.Point3d height_point = new Rhino.Geometry.Point3d(0, 0, 10); Rhino.Geometry.Vector3d zaxis = height_point - center_point; Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(center_point, zaxis); double radius = 5; Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, radius); Rhino.Geometry.Cylinder cylinder = new Rhino.Geometry.Cylinder(circle, zaxis.Length); Rhino.Geometry.Brep brep = cylinder.ToBrep(true, true); if (brep != null) { doc.Objects.AddBrep(brep); doc.Views.Redraw(); } return Rhino.Commands.Result.Success; }
/// <summary> /// Create Rhino open ArcCurve from Edge(Arc). /// </summary> public static Rhino.Geometry.ArcCurve ToRhinoArcCurve(Geometry.Edge obj) { if (obj.Points.Count == 3) { Rhino.Geometry.Arc arc = new Rhino.Geometry.Arc(obj.Points[0].ToRhino(), obj.Points[1].ToRhino(), obj.Points[2].ToRhino()); return(new Rhino.Geometry.ArcCurve(arc)); } else { Rhino.Geometry.Interval interval = new Rhino.Geometry.Interval(obj.StartAngle, obj.EndAngle); Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(obj.Points[0].ToRhino(), obj.XAxis.ToRhino(), obj.Normal.Cross(obj.XAxis).Normalize().ToRhino()); Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, obj.Radius); Rhino.Geometry.Arc arc = new Rhino.Geometry.Arc(circle, interval); return(new Rhino.Geometry.ArcCurve(arc)); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Geometry.Point3d[] corners; Result rc = Rhino.Input.RhinoGet.GetRectangle(out corners); if (rc != Result.Success) { return(rc); } Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(corners[0], corners[1], corners[2]); Rhino.Geometry.PlaneSurface plane_surface = new Rhino.Geometry.PlaneSurface( plane, new Rhino.Geometry.Interval(0, corners[0].DistanceTo(corners[1])), new Rhino.Geometry.Interval(0, corners[1].DistanceTo(corners[2])) ); rc = Result.Cancel; if (plane_surface.IsValid) { string layer_name = doc.Layers.GetUnusedLayerName(true); rc = Rhino.Input.RhinoGet.GetString("Name of layer to create", true, ref layer_name); if (rc == Result.Success && !string.IsNullOrEmpty(layer_name)) { int layer_index = doc.Layers.FindByFullPath(layer_name, true); if (-1 == layer_index) { layer_index = doc.Layers.Add(layer_name, System.Drawing.Color.Black); } if (layer_index >= 0) { Rhino.DocObjects.ObjectAttributes attribs = doc.CreateDefaultAttributes(); attribs.LayerIndex = layer_index; attribs.Name = layer_name; doc.Objects.AddSurface(plane_surface, attribs); doc.Views.Redraw(); rc = Result.Success; } } } return(rc); }
public static Rhino.Commands.Result AddAnnotationText(Rhino.RhinoDoc doc) { Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(10, 0, 0); const string text = "Hello RhinoCommon"; const double height = 2.0; const string font = "Arial"; Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); plane.Origin = pt; Guid id = doc.Objects.AddText(text, plane, height, font, false, false); if (id != Guid.Empty) { doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
public static Rhino.Commands.Result AddCylinder(Rhino.RhinoDoc doc) { Rhino.Geometry.Point3d center_point = new Rhino.Geometry.Point3d(0, 0, 0); Rhino.Geometry.Point3d height_point = new Rhino.Geometry.Point3d(0, 0, 10); Rhino.Geometry.Vector3d zaxis = height_point - center_point; Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(center_point, zaxis); const double radius = 5; Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, radius); Rhino.Geometry.Cylinder cylinder = new Rhino.Geometry.Cylinder(circle, zaxis.Length); Rhino.Geometry.Brep brep = cylinder.ToBrep(true, true); if (brep != null) { doc.Objects.AddBrep(brep); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Geometry.Brep ToRhino(Wall wall) { // i know the coordinates are not right, but it's work in progress and i'm past caring. var vector = new Rhino.Geometry.Vector3d(wall.BaseLine.EndPoint.X, wall.BaseLine.EndPoint.Y, wall.BaseLine.EndPoint.Z); var origin = new Rhino.Geometry.Point3d(wall.BaseLine.StartPoint.X, wall.BaseLine.StartPoint.Y, wall.BaseLine.StartPoint.Z); var plane = new Rhino.Geometry.Plane(origin, vector); Rhino.Geometry.Interval xInterval = new Rhino.Geometry.Interval(-wall.Length / 2, wall.Length / 2); Rhino.Geometry.Interval yInterval = new Rhino.Geometry.Interval(-wall.Thickness / 2, wall.Thickness / 2); Rhino.Geometry.Interval zInterval = new Rhino.Geometry.Interval(0, wall.Height); Rhino.Geometry.Box box = new Rhino.Geometry.Box(plane, xInterval, yInterval, zInterval); var brep = box.ToBrep(); brep.Rotate(Math.PI / 2, vector, origin); return(brep); }
public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to splop", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Surface to splop on"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; go.SubObjectSelect = false; go.EnablePreSelect(false, true); go.DeselectAllBeforePostSelect = false; go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.DocObjects.ObjRef srfref = go.Object(0); double u, v; srfref.SurfaceParameter(out u, out v); Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u, v); Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result AddCone(Rhino.RhinoDoc doc) { Rhino.Geometry.Plane plane = Rhino.Geometry.Plane.WorldXY; const double height = 10; const double radius = 5; Rhino.Geometry.Cone cone = new Rhino.Geometry.Cone(plane, height, radius); if (cone.IsValid) { const bool cap_bottom = true; Rhino.Geometry.Brep cone_brep = cone.ToBrep(cap_bottom); if (cone_brep != null) { doc.Objects.AddBrep(cone_brep); doc.Views.Redraw(); } } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc) { // Select objects to orient Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to orient"); go.SubObjectSelect = false; go.GroupSelect = true; go.GetMultiple(1, 0); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } // Point to orient from Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Point to orient from"); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { return(gp.CommandResult()); } // Define source plane Rhino.Display.RhinoView view = gp.View(); if (view == null) { view = doc.Views.ActiveView; if (view == null) { return(Rhino.Commands.Result.Failure); } } Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane(); source_plane.Origin = gp.Point(); // Surface to orient on Rhino.Input.Custom.GetObject gs = new Rhino.Input.Custom.GetObject(); gs.SetCommandPrompt("Surface to orient on"); gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; gs.SubObjectSelect = true; gs.DeselectAllBeforePostSelect = false; gs.OneByOnePostSelect = true; gs.Get(); if (gs.CommandResult() != Rhino.Commands.Result.Success) { return(gs.CommandResult()); } Rhino.DocObjects.ObjRef objref = gs.Object(0); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Rhino.Commands.Result.Failure); } // get selected surface (face) Rhino.Geometry.Surface surface = objref.Surface(); if (surface == null) { return(Rhino.Commands.Result.Failure); } // Unselect surface obj.Select(false); // Point on surface to orient to gp.SetCommandPrompt("Point on surface to orient to"); gp.Constrain(surface, false); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { return(gp.CommandResult()); } // Do transformation Rhino.Commands.Result rc = Rhino.Commands.Result.Failure; double u, v; if (surface.ClosestPoint(gp.Point(), out u, out v)) { Rhino.Geometry.Plane target_plane; if (surface.FrameAt(u, v, out target_plane)) { // Build transformation Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane); // Do the transformation. In this example, we will copy the original objects const bool delete_original = false; for (int i = 0; i < go.ObjectCount; i++) { doc.Objects.Transform(go.Object(i), xform, delete_original); } doc.Views.Redraw(); rc = Rhino.Commands.Result.Success; } } return(rc); }
void ReconstructFamilyInstanceByPointAtHost ( Document doc, ref Autodesk.Revit.DB.Element element, Rhino.Geometry.Plane location, Autodesk.Revit.DB.FamilySymbol type, Optional <Autodesk.Revit.DB.Level> level, [Optional] Autodesk.Revit.DB.Element host ) { var scaleFactor = 1.0 / Revit.ModelUnits; if (scaleFactor != 1.0) { location = location.Scale(scaleFactor); } if (!location.IsValid) { ThrowArgumentException(nameof(location), "Should be a valid point or plane."); } SolveOptionalLevel(ref level, doc, location.Origin.Z, nameof(level)); if (host == null && type.Family.FamilyPlacementType == FamilyPlacementType.OneLevelBasedHosted) { ThrowArgumentNullException(nameof(host), $"This family requires a host."); } if (!type.IsActive) { type.Activate(); } ChangeElementTypeId(ref element, type.Id); bool hasSameHost = false; if (element is FamilyInstance familyInstance) { hasSameHost = (familyInstance.Host?.Id ?? ElementId.InvalidElementId) == (host?.Id ?? ElementId.InvalidElementId); if (familyInstance.Host == null) { if (element?.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_PARAM) is Parameter freeHostParam) { var freeHostName = freeHostParam.AsString(); hasSameHost = freeHostName.EndsWith(host?.Name ?? level.Value.Name); } } } if ( hasSameHost && element is FamilyInstance && element.Location is LocationPoint locationPoint ) { using (var levelParam = element.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM)) { if (levelParam.AsElementId() != level.Value.Id) { levelParam.Set(level.Value.Id); doc.Regenerate(); } } var newOrigin = location.Origin.ToHost(); if (!newOrigin.IsAlmostEqualTo(locationPoint.Point)) { element.Pinned = false; locationPoint.Point = newOrigin; element.Pinned = true; } } else { var creationDataList = new List <Autodesk.Revit.Creation.FamilyInstanceCreationData>() { new Autodesk.Revit.Creation.FamilyInstanceCreationData(location.Origin.ToHost(), type, host, level.Value, Autodesk.Revit.DB.Structure.StructuralType.NonStructural) }; ICollection <ElementId> newElementIds = null; if (doc.IsFamilyDocument) { newElementIds = doc.FamilyCreate.NewFamilyInstances2(creationDataList); } else { newElementIds = doc.Create.NewFamilyInstances2(creationDataList); } if (newElementIds.Count != 1) { doc.Delete(newElementIds); throw new InvalidOperationException(); } var parametersMask = new BuiltInParameter[] { BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.ELEM_TYPE_PARAM, BuiltInParameter.FAMILY_LEVEL_PARAM }; ReplaceElement(ref element, doc.GetElement(newElementIds.First()), parametersMask); } if (element is FamilyInstance instance && instance.Host == null) { element.Pinned = false; SetTransform(instance, location.Origin.ToHost(), location.XAxis.ToHost(), location.YAxis.ToHost()); element.Pinned = true; } }
void ReconstructWallByCurve ( Document doc, ref Autodesk.Revit.DB.Element element, Rhino.Geometry.Curve curve, Optional <Autodesk.Revit.DB.WallType> type, Optional <Autodesk.Revit.DB.Level> level, [Optional] bool structural, [Optional] double height, [Optional] WallLocationLine locationLine, [Optional] bool flipped, [Optional, NickName("J")] bool allowJoins ) { var scaleFactor = 1.0 / Revit.ModelUnits; if ( scaleFactor != 1.0 ? !curve.Scale(scaleFactor) : true && curve.IsShort(Revit.ShortCurveTolerance) || !(curve.IsLinear(Revit.VertexTolerance) || curve.IsArc(Revit.VertexTolerance)) || !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) || axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0 ) { ThrowArgumentException(nameof(curve), "Curve must be a horizontal line or arc curve"); } SolveOptionalType(ref type, doc, ElementTypeGroup.WallType, nameof(type)); double axisMinZ = Math.Min(curve.PointAtStart.Z, curve.PointAtEnd.Z); bool levelIsEmpty = SolveOptionalLevel(ref level, doc, curve, nameof(level)); height *= scaleFactor; if (height < Revit.VertexTolerance) { height = (type.HasValue ? type.Value : null)?.GetCompoundStructure()?.SampleHeight ?? LiteralLengthValue(6.0) / Revit.ModelUnits; } // Axis var levelPlane = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0.0, 0.0, level.Value.Elevation), Rhino.Geometry.Vector3d.ZAxis); curve = Rhino.Geometry.Curve.ProjectToPlane(curve, levelPlane); var curves = curve.ToHost().ToArray(); Debug.Assert(curves.Length == 1); var centerLine = curves[0]; // LocationLine if (locationLine != WallLocationLine.WallCenterline) { double offsetDist = 0.0; var compoundStructure = type.Value.GetCompoundStructure(); if (compoundStructure == null) { switch (locationLine) { case WallLocationLine.WallCenterline: case WallLocationLine.CoreCenterline: break; case WallLocationLine.FinishFaceExterior: case WallLocationLine.CoreExterior: offsetDist = type.Value.Width / +2.0; break; case WallLocationLine.FinishFaceInterior: case WallLocationLine.CoreInterior: offsetDist = type.Value.Width / -2.0; break; } } else { if (!compoundStructure.IsVerticallyHomogeneous()) { compoundStructure = CompoundStructure.CreateSimpleCompoundStructure(compoundStructure.GetLayers()); } offsetDist = compoundStructure.GetOffsetForLocationLine(locationLine); } if (offsetDist != 0.0) { centerLine = centerLine.CreateOffset(flipped ? -offsetDist : offsetDist, XYZ.BasisZ); } } // Type ChangeElementTypeId(ref element, type.Value.Id); Wall newWall = null; if (element is Wall previousWall && previousWall.Location is LocationCurve locationCurve && centerLine.IsSameKindAs(locationCurve.Curve)) { newWall = previousWall; locationCurve.Curve = centerLine; }
/// <summary> /// Adds named construction plane to document. /// </summary> /// <param name="name"> /// If name is empty, a unique name is automatically created. /// If there is already a named onstruction plane with the same name, that /// construction plane is replaced. /// </param> /// <param name="plane">The plane value.</param> /// <returns> /// 0 based index of named construction plane. /// -1 on failure. /// </returns> public int Add(string name, Rhino.Geometry.Plane plane) { return(UnsafeNativeMethods.CRhinoDocProperties_AddCPlane(m_doc.m_docId, name, ref plane)); }
public void drawExtrusion(Rhino.Geometry.Point3d point1, double height, double width, double thickness) { Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(point1,Rhino.Geometry.Vector3d.ZAxis); Rhino.Geometry.Point3d cornerA = new Rhino.Geometry.Point3d(point1.X - width / 2, point1.Y - height / 2, point1.Z); Rhino.Geometry.Point3d cornerB = new Rhino.Geometry.Point3d(point1.X + width / 2, point1.Y + height / 2, point1.Z); Rhino.Geometry.Rectangle3d rect = new Rhino.Geometry.Rectangle3d(plane, cornerA, cornerB); Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(rect.ToNurbsCurve(), new Rhino.Geometry.Vector3d(0, 0, thickness)); SetPreview(srf.ToBrep()); }
/// <summary> /// Constructs a new instance of Text3d. /// </summary> /// <param name="text">Text string.</param> /// <param name="plane">3D Plane for text.</param> /// <param name="height">Height (in units) for text.</param> public Text3d(string text, Rhino.Geometry.Plane plane, double height) { m_text = text; m_plane = plane; m_height = height; }
Rhino.Geometry.Plane GetPlane(int which) { IntPtr pConstThis = ConstPointer(); Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(); if (!UnsafeNativeMethods.ON_Viewport_GetPlane(pConstThis, which, ref plane)) plane = Rhino.Geometry.Plane.Unset; return plane; }
void ReconstructFamilyInstanceByLocation ( DB.Document doc, ref DB.FamilyInstance element, [Description("Location where to place the element. Point or plane is accepted.")] Rhino.Geometry.Plane location, DB.FamilySymbol type, Optional <DB.Level> level, [Optional] DB.Element host ) { var scaleFactor = 1.0 / Revit.ModelUnits; location = location.ChangeUnits(scaleFactor); if (!location.IsValid) { ThrowArgumentException(nameof(location), "Should be a valid point or plane."); } SolveOptionalLevel(doc, location.Origin, ref level, out var bbox); if (host == null && type.Family.FamilyPlacementType == DB.FamilyPlacementType.OneLevelBasedHosted) { ThrowArgumentException(nameof(host), $"This family requires a host."); } if (!type.IsActive) { type.Activate(); } ChangeElementTypeId(ref element, type.Id); bool hasSameHost = false; if (element is DB.FamilyInstance) { hasSameHost = (element.Host?.Id ?? DB.ElementId.InvalidElementId) == (host?.Id ?? DB.ElementId.InvalidElementId); if (element.Host == null) { if (element?.get_Parameter(DB.BuiltInParameter.INSTANCE_FREE_HOST_PARAM) is DB.Parameter freeHostParam) { var freeHostName = freeHostParam.AsString(); hasSameHost = freeHostName.EndsWith(host?.Name ?? level.Value.Name); } } } if ( hasSameHost && element is DB.FamilyInstance && element.Location is DB.LocationPoint locationPoint ) { using (var levelParam = element.get_Parameter(DB.BuiltInParameter.FAMILY_LEVEL_PARAM)) { if (levelParam.AsElementId() != level.Value.Id) { levelParam.Set(level.Value.Id); doc.Regenerate(); } } if (host is object) { var newOrigin = location.Origin.ToHost(); if (!newOrigin.IsAlmostEqualTo(locationPoint.Point)) { element.Pinned = false; locationPoint.Point = newOrigin; element.Pinned = true; } } } else { var creationData = new List <Autodesk.Revit.Creation.FamilyInstanceCreationData>() { new Autodesk.Revit.Creation.FamilyInstanceCreationData(location.Origin.ToHost(), type, host, level.Value, DB.Structure.StructuralType.NonStructural) }; var newElementIds = doc.IsFamilyDocument ? doc.FamilyCreate.NewFamilyInstances2(creationData) : doc.Create.NewFamilyInstances2(creationData); if (newElementIds.Count != 1) { doc.Delete(newElementIds); throw new InvalidOperationException(); } var parametersMask = new DB.BuiltInParameter[] { DB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, DB.BuiltInParameter.ELEM_FAMILY_PARAM, DB.BuiltInParameter.ELEM_TYPE_PARAM, DB.BuiltInParameter.FAMILY_LEVEL_PARAM }; ReplaceElement(ref element, doc.GetElement(newElementIds.First()) as DB.FamilyInstance, parametersMask); doc.Regenerate(); } if (element is object && element.Host is null) { element.Pinned = false; element.SetTransform(location.Origin.ToHost(), location.XAxis.ToHost(), location.YAxis.ToHost()); element.Pinned = true; } }
public void drawColumn(Rhino.Geometry.Point3d point1, Rhino.Geometry.Point3d point2, double radius) { Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(point1, new Rhino.Geometry.Vector3d((point2 - point1))); Rhino.Geometry.Circle c = new Rhino.Geometry.Circle(plane,point1,radius); Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(c.ToNurbsCurve(), new Rhino.Geometry.Vector3d((point2 - point1))); SetPreview(srf.ToBrep()); }
void ReconstructView3DByPlane ( DB.Document doc, ref DB.View3D view, Rhino.Geometry.Plane plane, Optional <DB.ElementType> type, Optional <string> name, Optional <bool> perspective ) { SolveOptionalType(ref type, doc, DB.ElementTypeGroup.ViewType3D, nameof(type)); var orientation = new DB.ViewOrientation3D ( plane.Origin.ToXYZ(), plane.YAxis.ToXYZ(), plane.ZAxis.ToXYZ() ); if (view is null) { var newView = perspective.IsNullOrMissing ? DB.View3D.CreatePerspective ( doc, type.Value.Id ) : DB.View3D.CreateIsometric ( doc, type.Value.Id ); var parametersMask = new DB.BuiltInParameter[] { DB.BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, DB.BuiltInParameter.ELEM_FAMILY_PARAM, DB.BuiltInParameter.ELEM_TYPE_PARAM }; newView.SetOrientation(orientation); view.get_Parameter(DB.BuiltInParameter.VIEWER_CROP_REGION).Set(0); ReplaceElement(ref view, newView, parametersMask); } else { view.SetOrientation(orientation); if (perspective.HasValue) { view.get_Parameter(DB.BuiltInParameter.VIEWER_PERSPECTIVE).Set(perspective.Value ? 1 : 0); } ChangeElementTypeId(ref view, type.Value.Id); } if (name.HasValue && view is object) { try { view.Name = name.Value; } catch (Autodesk.Revit.Exceptions.ArgumentException e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, $"{e.Message.Replace($".{Environment.NewLine}", ". ")}"); } } }
public bool Cone(int index, ref Rhino.Geometry.Cone cone, ref Rhino.Geometry.Plane truncation) { Rhino.Geometry.Point3d origin = new Rhino.Geometry.Point3d(); Rhino.Geometry.Vector3d xaxis = new Rhino.Geometry.Vector3d(); Rhino.Geometry.Vector3d yaxis = new Rhino.Geometry.Vector3d(); double height = 0.0; double radius = 0.0; Rhino.Geometry.Point3d t_origin = new Rhino.Geometry.Point3d(); Rhino.Geometry.Vector3d t_xaxis = new Rhino.Geometry.Vector3d(); Rhino.Geometry.Vector3d t_yaxis = new Rhino.Geometry.Vector3d(); if (UnsafeNativeMethods.Rdk_CustomMeshes_Cone(ConstPointer(), index, ref origin, ref xaxis, ref yaxis, ref height, ref radius, ref t_origin, ref t_xaxis, ref t_yaxis)) { cone = new Rhino.Geometry.Cone(new Rhino.Geometry.Plane(origin, xaxis, yaxis), height, radius); truncation = new Rhino.Geometry.Plane(t_origin, t_xaxis, t_yaxis); return true; } return false; }