Ejemplo n.º 1
0
        /// <summary>
        /// This node will obtain the outline of the Viewport title if one is used. This is the label outline.
        /// </summary>
        /// <param name="viewport">Viewport to obtain data from.</param>
        /// <returns name="labelOutline">The label outline of the viewport.</returns>
        /// <search>
        /// viewport, Viewport.LabelOutline, rhythm
        /// </search>
        public static List <Autodesk.DesignScript.Geometry.Curve> LabelOutline(global::Revit.Elements.Element viewport)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //obtain the element id from the sheet
            Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;

            //this obtains the label outline
            var labelOutline = internalViewport.GetLabelOutline();
            //create plane that corresponds to sheet plane
            Plane labelPlane   = Plane.ByOriginNormal(labelOutline.MaximumPoint.ToPoint(), Vector.ZAxis());
            var   labelCuboid  = Cuboid.ByCorners(labelOutline.MaximumPoint.ToPoint(), labelOutline.MinimumPoint.ToPoint());
            var   labelSurface = labelCuboid.Intersect(labelPlane);
            List <Autodesk.DesignScript.Geometry.Curve[]> labelCurves = new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (Surface surf in labelSurface)
            {
                labelCurves.Add(surf.PerimeterCurves());
            }
            List <Autodesk.DesignScript.Geometry.Curve> labelSheetCurves = new List <Autodesk.DesignScript.Geometry.Curve>();

            //pull the curves onto a plane at 0,0,0
            foreach (Autodesk.DesignScript.Geometry.Curve[] curve in labelCurves)
            {
                foreach (Autodesk.DesignScript.Geometry.Curve c in curve)
                {
                    labelSheetCurves.Add(c.PullOntoPlane(Plane.XY()));
                }
            }

            return(labelSheetCurves);
        }
Ejemplo n.º 2
0
        public RsTarget CreateTarget(DGeom.Plane targetPlane)
        {
            try
            {
                //create robtarget
                RsRobTarget robTarget = new RsRobTarget();
                robTarget.Name = rsTask.GetValidRapidName("Target", "_", 1);

                //translation
                double[] trans = PlaneToTransform(targetPlane);
                robTarget.Frame.Translation = new Vector3(trans[0], trans[1], trans[2]);
                robTarget.Frame.RX          = trans[3];
                robTarget.Frame.RY          = trans[4];
                robTarget.Frame.RZ          = trans[5];

                //add robtargets to datadeclaration
                // rsTask.DataDeclarations.Add(robTarget);

                //create target
                RsTarget target = new RsTarget(rsWobj, robTarget);
                target.Name = robTarget.Name;
                target.Attributes.Add(target.Name, true);

                //add targets to active task
                //rsTask.Targets.Add(target);

                return(target);
            }
            catch (Exception exception)
            {
            }
            return(null);
        }
Ejemplo n.º 3
0
 internal Dyn.Geometry EnsureUnit(Dyn.Geometry geo, bool disposeInput = false)
 {
     Dyn.Geometry scgeo = null;
     Dyn.Plane    xy    = Dyn.Plane.XY();
     if (targetUnit == baseUnit)
     {
         scgeo = geo.Scale(xy, 1, 1, 1);
     }
     else
     {
         if (baseUnit == "Meters" && targetUnit == "Feet")
         {
             double factor = 3.280841666667;
             scgeo = geo.Scale(xy, factor, factor, factor);
         }
         else if (baseUnit == "Feet" && targetUnit == "Meters")
         {
             double factor = 0.304800164592;
             scgeo = geo.Scale(xy, factor, factor, factor);
         }
         else
         {
         }
     }
     if (disposeInput)
     {
         geo.Dispose();
     }
     xy.Dispose();
     return(scgeo);
 }
Ejemplo n.º 4
0
 internal static double[] DSPlaneToDoubleArray(DSPlane pl, bool transpose)
 {
     double[] a;
     if (transpose)
     {
         a = new double[]
         {
             pl.XAxis.X, pl.XAxis.Y, pl.XAxis.Z, 0,
             pl.YAxis.X, pl.YAxis.Y, pl.YAxis.Z, 0,
             pl.Normal.X, pl.Normal.Y, pl.Normal.Z, 0,
             pl.Origin.X, pl.Origin.Y, pl.Origin.Z, 1
         };
     }
     else
     {
         a = new double[]
         {
             pl.XAxis.X, pl.YAxis.X, pl.Normal.X, pl.Origin.X,
             pl.XAxis.Y, pl.YAxis.Y, pl.Normal.Y, pl.Origin.Y,
             pl.XAxis.Z, pl.YAxis.Z, pl.Normal.Z, pl.Origin.Z,
             0, 0, 0, 1
         };
     }
     return(a);
 }
Ejemplo n.º 5
0
        public static Dictionary <string, object> CurveSinusoidalPoints(
            Autodesk.DesignScript.Geometry.Curve _Curve,
            double WaveLength = 5.0,
            double Amplitude  = 1.0,
            double Resolution = 2.0)
        {
            double n     = (_Curve.Length / WaveLength) * 4 * Resolution;
            double _Span = _Curve.Length / n;
            List <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>();
            List <double> ks = new List <double>();

            for (int i = 0; i < n; i++)
            {
                double k = Amplitude * Math.Sin(i * _Span * Math.PI * 2 / WaveLength + Math.PI * 2);
                Autodesk.DesignScript.Geometry.Plane pl = _Curve.PlaneAtParameter(_Curve.ParameterAtSegmentLength(i * _Span));
                Autodesk.DesignScript.Geometry.Point p  = _Curve.PointAtSegmentLength(i * _Span);
                points.Add((Autodesk.DesignScript.Geometry.Point)p.Translate(pl.YAxis, k));
                ks.Add(k);
            }

            return(new Dictionary <string, object>
            {
                { "Points", points },
                { "k", ks }
            });
        }
Ejemplo n.º 6
0
        public static Dictionary <string, object> CurveSinusoidalPointsWithVoxel(
            Autodesk.DesignScript.Geometry.Curve _Curve,
            VoxelImage Voxel,
            double WaveLength = 5.0,
            double Amplitude  = 1.0,
            double Resolution = 2.0)
        {
            VoxelChannel _VoxelChannel = Voxel.GetChannel(VoxelImageLayout.SHAPECHANNEL);

            double n     = (_Curve.Length / WaveLength) * 4 * Resolution;
            double _Span = _Curve.Length / n;
            List <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>();
            List <double> ks = new List <double>();

            for (int i = 0; i < n; i++)
            {
                Autodesk.DesignScript.Geometry.Plane pl = _Curve.PlaneAtParameter(_Curve.ParameterAtSegmentLength(i * _Span));
                Autodesk.DesignScript.Geometry.Point p  = _Curve.PointAtSegmentLength(i * _Span);
                double FieldValue = V2GVoxel.GetVoxelFieldValue(_VoxelChannel, p.X, p.Y, p.Z);

                double k = FieldValue * Amplitude * Math.Sin(i * _Span * Math.PI * 2 / WaveLength + Math.PI * 2);

                points.Add((Autodesk.DesignScript.Geometry.Point)p.Translate(pl.YAxis, k));
                ks.Add(k);
            }

            return(new Dictionary <string, object>
            {
                { "Points", points },
                { "k", ks }
            });
        }
Ejemplo n.º 7
0
        public void ByTextSketchPlaneAndPosition_ValidArgs()
        {
            var origin = Point.ByCoordinates(1, 2, 3);
            var normal = Vector.ByCoordinates(0, 0, 1);
            var plane  = Plane.ByOriginNormal(origin, normal);
            var text   = "Snickers - why wait?";

            var name          = "Model Text 1";
            var modelTextType = ModelTextType.ByName(name);

            var sketchPlane = SketchPlane.ByPlane(plane);
            var depth       = 1;
            var x           = 10;
            var y           = 3;
            var mt          = ModelText.ByTextSketchPlaneAndPosition(text, sketchPlane, x, y, depth, modelTextType);

            Assert.NotNull(mt);
            Assert.NotNull(mt.InternalElement);
            Assert.IsTrue(DocumentManager.Instance.ElementExistsInDocument(
                              new ElementUUID(mt.InternalElement.UniqueId)));

            mt.Depth.ShouldBeApproximately(depth);

            // with unit conversion
            InternalDepth(mt).ShouldBeApproximately(depth * UnitConverter.DynamoToHostFactor);

            var expectedInternalLoc =
                origin.InHostUnits()
                .Add(Vector.XAxis().Scale(x * UnitConverter.DynamoToHostFactor))
                .Add(Vector.YAxis().Scale(y * UnitConverter.DynamoToHostFactor));

            InternalLocation(mt).ShouldBeApproximately(expectedInternalLoc);
        }
Ejemplo n.º 8
0
        public static Dictionary <string, object> Display(Autodesk.DesignScript.Geometry.Plane plane, double length = 1000)
        {
            //Avoid zero length
            if (length == 0)
            {
                length = 1;
            }
            //Origin and Axes
            var pt     = plane.Origin;
            var lineX  = Line.ByStartPointDirectionLength(pt, plane.XAxis, length);
            var colorX = DSCore.Color.ByARGB(255, 255, 0, 0);
            var lineY  = Line.ByStartPointDirectionLength(pt, plane.YAxis, length);
            var colorY = DSCore.Color.ByARGB(255, 0, 255, 0);
            var lineN  = Line.ByStartPointDirectionLength(pt, plane.Normal, length);
            var colorN = DSCore.Color.ByARGB(255, 0, 0, 255);
            //Plane
            var rect   = Rectangle.ByWidthLength(plane, length, length);
            var colorR = DSCore.Color.ByARGB(50, 50, 50, 50);
            //Build List of Display
            List <Modifiers.GeometryColor> display = new List <Modifiers.GeometryColor>();

            display.Add(Modifiers.GeometryColor.ByGeometryColor(lineX, colorX));
            display.Add(Modifiers.GeometryColor.ByGeometryColor(lineY, colorY));
            display.Add(Modifiers.GeometryColor.ByGeometryColor(lineN, colorN));
            display.Add(Modifiers.GeometryColor.ByGeometryColor(rect, colorR));
            //Return values
            var d = new Dictionary <string, object>();

            d.Add("Display", display);
            d.Add("Origin", pt);
            d.Add("XAxis", plane.XAxis);
            d.Add("YAxis", plane.YAxis);
            d.Add("Normal", plane.Normal);
            return(d);
        }
Ejemplo n.º 9
0
    public static Plane ToPlane(this D.Plane p)
    {
        var origin = p.Origin.ToPoint3d();
        var xAxis  = p.XAxis.ToVector3d();
        var yAxis  = p.YAxis.ToVector3d();

        return(new(origin, xAxis, yAxis));
    }
Ejemplo n.º 10
0
        public bool isTargetReachable(DGeom.Plane targetPlane)
        {
            var target = CreateTarget(targetPlane);
            var isOk   = robot.Task.Mechanism.CanReachAsync(target.RobTarget, target.WorkObject, rsTask.ActiveTool);

            isOk.Wait();

            return(isOk.Result);
        }
Ejemplo n.º 11
0
        public static re.Element WallByProfile(List <dg.PolyCurve> closedProfiles, re.WallType wallType, re.Level level)
        {
            rdb.Document doc = DocumentManager.Instance.CurrentDBDocument;

            // Try to get a wall from trace
            var wallElem = ElementBinder.GetElementFromTrace <rdb.Wall>(doc);

            dg.PolyCurve closedProfile = closedProfiles[0];
            if (!closedProfile.IsClosed || !closedProfile.IsPlanar)
            {
                DeleteWall(wallElem, true);
                return(null);
            }

            // Verify the wall profile is vertical
            dg.Plane basePlane = closedProfile.BasePlane();
            if (Math.Abs(basePlane.Normal.Z) > 0.0001)
            {
                DeleteWall(wallElem, true);
                return(null);
            }

            // Convert Polycurve segments to a list of Revit curves;
            List <rdb.Curve> rCrvs = new List <rdb.Curve>();

            foreach (dg.PolyCurve pCrv in closedProfiles)
            {
                List <dg.Curve> dCrvs = pCrv.Curves().ToList();
                foreach (dg.Curve dCrv in dCrvs)
                {
                    rdb.Curve rCrv = dCrv.ToRevitType();
                    rCrvs.Add(rCrv);
                }
            }


            TransactionManager.Instance.EnsureInTransaction(doc);
            DeleteWall(wallElem, false);

            // Build a wall
            try
            {
                rdb.Wall w     = rdb.Wall.Create(doc, rCrvs, new rdb.ElementId(wallType.Id), new rdb.ElementId(level.Id), false);
                re.Wall  rWall = re.ElementWrapper.ToDSType(w, true) as re.Wall;
                TransactionManager.Instance.TransactionTaskDone();
                ElementBinder.CleanupAndSetElementForTrace(doc, w);
                return(rWall);
            }
            catch (Exception ex)
            {
                TransactionManager.Instance.TransactionTaskDone();

                ElementBinder.CleanupAndSetElementForTrace(doc, null);
            }
            return(null);
        }
Ejemplo n.º 12
0
    internal static Matrix4x4 DSPlaneToMatrix4x4(DSPlane plane)
    {
        double[]  pl = DSPlaneToDoubleArray(plane, false);
        Matrix4x4 m  = new Matrix4x4(
            (float)pl[0], (float)pl[1], (float)pl[2], (float)pl[3],
            (float)pl[4], (float)pl[5], (float)pl[6], (float)pl[7],
            (float)pl[8], (float)pl[9], (float)pl[10], (float)pl[11],
            (float)pl[12], (float)pl[13], (float)pl[14], (float)pl[15]);

        return(m);
    }
Ejemplo n.º 13
0
 /// <summary>
 /// Reorient all the tracked devices according to the new Plane you set as origin plane.
 /// </summary>
 /// <param name="NewOriginPlane">New base Plane.</param>
 /// <param name="calibrate">Should this plane be used for calibration?</param>
 public static void CalibrateOrigin([DefaultArgumentAttribute("Plane.XY();")] DSPlane NewOriginPlane, bool calibrate = true)
 {
     if (calibrate)
     {
         CalibrationTransform = Util.DSPlaneToMatrix4x4(NewOriginPlane);
         CalibrationTransform = Matrix4x4.Multiply(CalibrationTransform, Matrix4x4.Identity);
     }
     else
     {
         CalibrationTransform = Matrix4x4.Identity;
     }
 }
Ejemplo n.º 14
0
        public static Dictionary <string, object> LocationData(global::Revit.Elements.Element viewport)
        {
            //obtain the element id from the sheet
            Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement;
            //obtain the box center of the viewport
            var boxCenterInternal = internalViewport.GetBoxCenter().ToPoint();

            //Construct new point at sheet elevation of 0
            Autodesk.DesignScript.Geometry.Point boxCenter =
                Autodesk.DesignScript.Geometry.Point.ByCoordinates(boxCenterInternal.X, boxCenterInternal.Y, 0);
            //this obtains the box outline
            var boxOutline = internalViewport.GetBoxOutline();
            //temporary geometry
            var bBox      = BoundingBox.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint());
            var boxCuboid = Cuboid.ByCorners(boxOutline.MaximumPoint.ToPoint(), boxOutline.MinimumPoint.ToPoint());
            //create plane that corresponds to sheet plane
            Plane boxPlane   = Plane.ByOriginNormal(boxOutline.MaximumPoint.ToPoint(), Vector.ZAxis());
            var   boxSurface = boxCuboid.Intersect(boxPlane);
            List <Autodesk.DesignScript.Geometry.Curve[]> boxCurves = new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (var geometry in boxSurface)
            {
                var surf = (Surface)geometry;
                boxCurves.Add(surf.PerimeterCurves());
                surf.Dispose();
            }
            List <Autodesk.DesignScript.Geometry.Curve> boxSheetCurves = new List <Autodesk.DesignScript.Geometry.Curve>();

            //pull the curves onto a plane at 0,0,0
            foreach (Autodesk.DesignScript.Geometry.Curve[] curve in boxCurves)
            {
                foreach (Autodesk.DesignScript.Geometry.Curve c in curve)
                {
                    boxSheetCurves.Add(c.PullOntoPlane(Plane.XY()));
                    c.Dispose();
                }
            }

            //dispose of temporary geometries
            boxCuboid.Dispose();
            boxPlane.Dispose();
            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "bBox", bBox },
                { "boxCenter", boxCenter },
                { "boxOutline", boxSheetCurves }
            };

            return(outInfo);
        }
Ejemplo n.º 15
0
        private static double IntersectWithPlaneAlongVector(this Curve curve, Plane plane, Vector tangent, double length)
        {
            // translate the plane along a vector using a distance
            Plane offsetPlane = (Plane)plane.Translate(tangent, length);

            // Intersect the plane with the curve
            Geometry[] intersection = offsetPlane.Intersect(curve);

            // If the intersection is one element and it is a point return the parameter of this point
            // Otherwise return minus one
            if (intersection.Count() == 1 && intersection[0].GetType() == typeof(Point))
                return curve.ParameterAtPoint((Point)intersection[0]);
            else
                return -1;
        }
Ejemplo n.º 16
0
        private double[] PlaneToTransform(DGeom.Plane pl)
        {
            double[] result = new double[6];
            //position
            result[0] = pl.Origin.X;
            result[1] = pl.Origin.Y;
            result[2] = pl.Origin.Z;

            //rotation
            result[3] = (DGeom.Vector.XAxis().AngleWithVector(pl.XAxis) * Math.PI) / 180;
            result[3] = (DGeom.Vector.YAxis().AngleWithVector(pl.YAxis) * Math.PI) / 180;
            result[3] = (DGeom.Vector.ZAxis().AngleWithVector(pl.Normal) * Math.PI) / 180;

            return(result);
        }
Ejemplo n.º 17
0
        public void ByTextSketchPlaneAndPosition_BadArgs()
        {
            var origin = Point.ByCoordinates(1, 2, 3);
            var normal = Vector.ByCoordinates(0, 0, 1);
            var plane  = Plane.ByOriginNormal(origin, normal);
            var text   = "Snickers - why wait?";

            var name          = "Model Text 1";
            var modelTextType = ModelTextType.ByName(name);

            var sketchPlane = SketchPlane.ByPlane(plane);

            Assert.Throws(typeof(System.ArgumentNullException), () => ModelText.ByTextSketchPlaneAndPosition(null, sketchPlane, 0, 0, 1, modelTextType));
            Assert.Throws(typeof(System.ArgumentNullException), () => ModelText.ByTextSketchPlaneAndPosition(text, null, 0, 0, 1, modelTextType));
            Assert.Throws(typeof(System.ArgumentNullException), () => ModelText.ByTextSketchPlaneAndPosition(text, sketchPlane, 0, 0, 1, null));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// This node will get the bounds of the view in paper space (in feet).
        /// </summary>
        /// <param name="view">The view to get outline from.</param>
        /// <returns name="outline">The bounds of the view in paper space (in feet).</returns>
        /// <search>
        /// view, outline,rhythm
        /// </search>
        public static List <Autodesk.DesignScript.Geometry.Curve[]> GetOutline(global::Revit.Elements.Element view)
        {
            Autodesk.Revit.DB.View internalView = (Autodesk.Revit.DB.View)view.InternalElement;
            var viewBbox   = internalView.Outline;
            var viewCuboid = Cuboid.ByCorners(Point.ByCoordinates(viewBbox.Max.U, viewBbox.Max.V, 0),
                                              Point.ByCoordinates(viewBbox.Min.U, viewBbox.Min.V, 0));
            var viewOutlineSurface = viewCuboid.Intersect(Plane.XY());
            List <Autodesk.DesignScript.Geometry.Curve[]> viewOutlineCurves =
                new List <Autodesk.DesignScript.Geometry.Curve[]>();

            foreach (Surface surf in viewOutlineSurface)
            {
                viewOutlineCurves.Add(surf.PerimeterCurves());
            }

            return(viewOutlineCurves);
        }
Ejemplo n.º 19
0
        private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv)
        {
            var isFullEllipse = !crv.IsBound ||
                                Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2 * Math.PI) < 1e-6;

            if (isFullEllipse)
            {
                return
                    (Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors(
                         crv.Center.ToPoint(false),
                         (crv.XDirection * crv.RadiusX).ToVector(false),
                         (crv.YDirection * crv.RadiusY).ToVector(false)));
            }

            // We need to define the major and minor axis as the curve
            // will be trimmed starting from the major axis (not the xaxis)
            var major = Math.Max(crv.RadiusX, crv.RadiusY);
            var minor = Math.Min(crv.RadiusX, crv.RadiusY);

            Vector majorAxis;
            Vector minorAxis;

            double startParam;

            var span = Math.Abs(crv.GetEndParameter(0) - crv.GetEndParameter(1)).ToDegrees();

            if (crv.RadiusX > crv.RadiusY)
            {
                majorAxis  = crv.XDirection.ToVector();
                minorAxis  = crv.YDirection.ToVector();
                startParam = crv.GetEndParameter(0).ToDegrees();
            }
            else
            {
                majorAxis  = crv.YDirection.ToVector().Reverse();
                minorAxis  = crv.XDirection.ToVector();
                startParam = crv.GetEndParameter(0).ToDegrees() + 90;
            }

            using (var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(false), majorAxis, minorAxis))
            {
                return(EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, major, minor, startParam, span));
            }
        }
Ejemplo n.º 20
0
 //**CONSTRUCTORS
 /// <summary>
 /// Internal constructor for the class that has all geometric inputs to create sliced model
 /// </summary>
 /// <param name="solid">Solid: geometry that is to be parsed</param>
 /// <param name="plane">Plane: primary cutplane</param>
 /// <param name="line1">Line1: (optional) defines secondary cutplane</param>
 /// <param name="line2">Line2: (optional) defines tertiary cutplane</param>
 /// <param name="thickness">Thickness: the thickness of the slices, or the thickness of the material to be used for the assembly</param>
 /// <param name="spacing">Spacing: the distance between each slice</param>
 internal Slicer(Solid solid, Plane plane, Line line1, Line line2, double thickness, double spacing)
 {
     Solid = solid;
     Thickness = thickness;
     Spacing = spacing;
     CutPlanesPrimary.AddRange(GenerateCutPlanes(plane));
     InitialGeometry = new List<Geometry>();
     InitialGeometry.Add(plane);
     if (line1 != null)
     {
         CutPlanesSecondary.AddRange(GenerateCutPlanes(Plane.ByThreePoints(line1.StartPoint, line1.EndPoint, line1.StartPoint.Add(plane.Normal))));
         InitialGeometry.Add(line1);
     }
     if (line2 != null)
     {
         CutPlanesTertiary.AddRange(GenerateCutPlanes(Plane.ByThreePoints(line2.StartPoint, line2.EndPoint, line2.StartPoint.Add(plane.Normal))));
         InitialGeometry.Add(line2);
     }
 }
Ejemplo n.º 21
0
        private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv)
        {
            var isComplete = !crv.IsBound ||
                             Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2 * Math.PI) < 1e-6;

            if (!isComplete)
            {
                var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(),
                                                  crv.XDirection.ToVector(), crv.YDirection.ToVector());

                var s = crv.GetEndParameter(0).ToDegrees();
                var e = crv.GetEndParameter(1).ToDegrees();

                return(EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, crv.RadiusX, crv.RadiusY, s, e - s));
            }

            return(Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors(crv.Center.ToPoint(),
                                                                          (crv.XDirection * crv.RadiusX).ToVector(), (crv.YDirection * crv.RadiusY).ToVector()));
        }
Ejemplo n.º 22
0
        public async Task <double[]> CalulateIK(DGeom.Plane targetPlane)
        {
            double[] jointRot = new double[6];
            RsTarget rst      = CreateTarget(targetPlane);

            try
            {
                //robot.CalculateInverseKinematicsAsync(rst, rsTask.ActiveTool, true);
                var jData = await robot.Task.Mechanism.CalculateInverseKinematicsAsync(rst, rsTask.ActiveTool, false);

                return(jData);
            }
            catch (ABB.Robotics.BaseException exception)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw;
            }

            return(jointRot);
        }
Ejemplo n.º 23
0
        private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv)
        {
            var isFullEllipse = !crv.IsBound ||
                                Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2 * Math.PI) < 1e-6;

            if (isFullEllipse)
            {
                return
                    (Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors(
                         crv.Center.ToPoint(false),
                         (crv.XDirection * crv.RadiusX).ToVector(false),
                         (crv.YDirection * crv.RadiusY).ToVector(false)));
            }
            double startParam;

            var span = Math.Abs(crv.GetEndParameter(0) - crv.GetEndParameter(1)).ToDegrees();

            startParam = crv.GetEndParameter(0).ToDegrees();
            using (var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(false), crv.XDirection.ToVector(), crv.YDirection.ToVector()))
            {
                return(EllipseArc.ByPlaneRadiiAngles(pl, crv.RadiusX, crv.RadiusY, startParam, span));
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Split this surface using a plane as cutting tool.
        /// </summary>
        /// <param name="splittingPlane">Plane as cutting tool.</param>
        /// <returns>Array of surfaces.</returns>
        public Surface[] Split(Plane splittingPlane)
        {
            ISurfaceEntity[] splitSurfaces = SurfaceEntity.Split(splittingPlane.HostImpl as IPlaneEntity);

            if (null == splitSurfaces || splitSurfaces.Length < 1)
            {
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, "Surface.Split"));
            }

            return splitSurfaces.ConvertAll((ISurfaceEntity host) => host.ToSurf(true, this));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="curves"></param>
        /// <param name="planes"></param>
        /// <param name="surfaces"></param>
        /// <param name="solids"></param>
        /// <param name="selectPoint"></param>
        /// <param name="autoExtend"></param>
        /// <returns></returns>
        public Surface Trim(Curve[] curves, Plane[] planes, Surface[] surfaces, Solid[] solids, Point selectPoint, bool autoExtend)
        {
            if (null == selectPoint)
                throw new System.ArgumentNullException("selectPoint");

            ICurveEntity[] hostCurves = curves.ConvertAll(GeometryExtension.ToEntity<Curve, ICurveEntity>);
            IPlaneEntity[] hostPlanes = planes.ConvertAll(GeometryExtension.ToEntity<Plane, IPlaneEntity>);
            ISurfaceEntity[] hostSurfaces = surfaces.ConvertAll(GeometryExtension.ToEntity<Surface, ISurfaceEntity>);
            ISolidEntity[] hostSolids = solids.ConvertAll(GeometryExtension.ToEntity<Solid, ISolidEntity>);

            IPointEntity hostPoint = selectPoint.PointEntity;

            if (hostCurves == null && hostPlanes == null && hostSurfaces == null && hostSolids == null)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidInput, "Geometry", "Surface.Trim"));

            ISurfaceEntity trimSurface = SurfaceEntity.Trim(hostCurves, hostPlanes, hostSurfaces, hostSolids, hostPoint, autoExtend);

            //For trim operation, if the return value is not null, hide the original tools and surfaces.
            if (null != trimSurface)
            {
                Hide(curves);
                Hide(planes);
                Hide(surfaces);
                Hide(solids);
                SetVisibility(false);
            }

            return trimSurface.ToSurf(true, this);
        }
Ejemplo n.º 26
0
        public static List<double> PlaneToQuaternian(Plane plane)
        {
            //Point origin = plane.Origin;
            Vector xVect = plane.XAxis;
            Vector yVect = plane.YAxis;
            Vector zVect = plane.Normal;

            double s, trace;
            double x1, x2, x3, y1, y2, y3, z1, z2, z3;
            double q1, q2, q3, q4;

            x1 = xVect.X;
            x2 = xVect.Y;
            x3 = xVect.Z;
            y1 = yVect.X;
            y2 = yVect.Y;
            y3 = yVect.Z;
            z1 = zVect.X;
            z2 = zVect.Y;
            z3 = zVect.Z;

            trace = x1 + y2 + z3 + 1;

            if (trace > 0.00001)
            {
                // s = (trace) ^ (1 / 2) * 2
                s = Math.Sqrt(trace) * 2;
                q1 = s / 4;
                q2 = (-z2 + y3) / s;
                q3 = (-x3 + z1) / s;
                q4 = (-y1 + x2) / s;

            }
            else if (x1 > y2 && x1 > z3)
            {
                //s = (x1 - y2 - z3 + 1) ^ (1 / 2) * 2
                s = Math.Sqrt(x1 - y2 - z3 + 1) * 2;
                q1 = (z2 - y3) / s;
                q2 = s / 4;
                q3 = (y1 + x2) / s;
                q4 = (x3 + z1) / s;

            }
            else if (y2 > z3)
            {
                //s = (-x1 + y2 - z3 + 1) ^ (1 / 2) * 2
                s = Math.Sqrt(-x1 + y2 - z3 + 1) * 2;
                q1 = (x3 - z1) / s;
                q2 = (y1 + x2) / s;
                q3 = s / 4;
                q4 = (z2 + y3) / s;
            }

            else
            {
                //s = (-x1 - y2 + z3 + 1) ^ (1 / 2) * 2
                s = Math.Sqrt(-x1 - y2 + z3 + 1) * 2;
                q1 = (y1 - x2) / s;
                q2 = (x3 + z1) / s;
                q3 = (z2 + y3) / s;
                q4 = s / 4;

            }
            List<double> quatDoubles = new List<double>();
            quatDoubles.Add(q1);
            quatDoubles.Add(q2);
            quatDoubles.Add(q3);
            quatDoubles.Add(q4);
            return quatDoubles;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Draws plane at half the scale.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="plane"></param>
        /// <param name="name"></param>
        private void DrawPlane(ref IRenderPackage package, Plane plane, Planes name)
        {
            package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.ManipulatorPlane, Name, name);
            using (var vec1 = plane.XAxis.Scale(scale/3))
            using (var vec2 = plane.YAxis.Scale(scale/3))
            using (var vec3 = plane.YAxis.Scale(scale/3))
            {
                using (var p1 = Origin.Add(vec1))
                using (var p2 = p1.Add(vec2))
                using (var p3 = Origin.Add(vec3))
                {
                    var axis = plane.Normal;
                    var color = GetAxisColor(GetAlignedAxis(axis));

                    package.AddLineStripVertexCount(3);
                    package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                    package.AddLineStripVertex(p1.X, p1.Y, p1.Z);

                    package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                    package.AddLineStripVertex(p2.X, p2.Y, p2.Z);

                    package.AddLineStripVertexColor(color.R, color.G, color.B, color.A);
                    package.AddLineStripVertex(p3.X, p3.Y, p3.Z);
                    
                }
            }
        }
Ejemplo n.º 28
0
 internal override IGeometryEntity[] IntersectWithPlane(Plane plane)
 {
     return SurfaceEntity.IntersectWith(plane.PlaneEntity);
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Returns the projection of the curve on the plane with given direction
        /// Argument Requirement:
        /// direction.Length > 0
        /// </summary>
        /// <param name="contextPlane">Projection plane</param>
        /// <param name="direction">Projection direction</param>
        /// <returns>Projected curve on the context plane</returns>
        public Curve Project(Plane contextPlane, Vector direction)
        {
            string kMethodName = "Curve.Project";
            if (null == contextPlane)
                throw new System.ArgumentNullException("contextPlane");
            else if (null == direction)
                throw new System.ArgumentNullException("direction");
            if (direction.Length.EqualsTo(0.0))
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZero, "length of the direction vector"), "direction");
            if (direction.IsPerpendicular(contextPlane.Normal))
                return null;

            ICurveEntity entity = CurveEntity.ProjectOn(contextPlane.PlaneEntity, direction.IVector);
            if (null == entity)
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));

            return entity.ToCurve(true, this);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Constructors a point by projecting a point on a plane with given project direction.
        /// </summary>
        /// <param name="contextPlane">Plane of projection</param>
        /// <param name="direction">Projection direction</param>
        /// <returns>Point</returns>
        public Point Project(Plane contextPlane, Vector direction)
        {
            if (contextPlane == null)
            {
                throw new ArgumentNullException("contextPlane");
            }
            else if (direction == null)
            {
                throw new ArgumentNullException("direction");
            }
            else if (direction.IsZeroVector())
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsZeroVector, "direction"));
            }
            else if (direction.IsPerpendicular(contextPlane.Normal))
            {
                throw new ArgumentException(string.Format(Properties.Resources.IsParallel, "contextPlane", "direction", "Point.Project"));
            }

            var pt = contextPlane.Project(this, direction);
            pt.Context = contextPlane;
            pt.ReferencePoint = this;
            pt.Direction = direction;
            pt.Persist();
            return pt;
        }
Ejemplo n.º 31
0
 //**PRIVATE FUNCTIONS
 /// <summary>
 /// This function creates a list of cut planes;
 /// Initial cut plane is the plane specified in cosntructor
 /// and the rest of the planes are generated from the initial plane
 /// and the given spacing.
 /// </summary>
 /// <param name="plane">initial plane</param>
 /// <returns>List containing all cut planes</returns>
 private List<Plane> GenerateCutPlanes(Plane plane)
 {
     List<Plane> Planes = new List<Plane>();     // List for planes that will be returned
     List<Plane> upPlanes = new List<Plane>();   // List of planes in normal direction
     List<Plane> downPlanes = new List<Plane>(); // List of planes in reverse normal direction
     Plane cutplane = plane.Offset(Spacing);     // Plane object that is iterated to generate lists
     while (Solid.DoesIntersect(cutplane))
     {
         upPlanes.Add(cutplane);
         cutplane = cutplane.Offset(Spacing);
     }
     cutplane = plane.Offset(0.0 - Spacing);
     while (Solid.DoesIntersect(cutplane))
     {
         downPlanes.Add(cutplane);
         cutplane = cutplane.Offset(0.0 - Spacing);
     }
     downPlanes.Reverse();
     Planes.AddRange(downPlanes);
     Planes.Add(plane);
     Planes.AddRange(upPlanes);
     return Planes;
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Create robot Pose from plane.
 /// </summary>
 /// <param name="plane">Plane</param>
 /// <returns></returns>
 public static Pose RobotPoseAtPlane(Plane plane)
 {
     var r = new Pose();
     r.Trans.X = (float)plane.Origin.X;
     r.Trans.Y = (float)plane.Origin.Y;
     r.Trans.Z = (float)plane.Origin.Z;
     List<double> quatDoubles = RobotUtils.PlaneToQuaternian(plane);
     r.Rot.Q1 = (float)quatDoubles[0];
     r.Rot.Q2 = (float)quatDoubles[1];
     r.Rot.Q3 = (float)quatDoubles[2];
     r.Rot.Q4 = (float)quatDoubles[3];
     return r;
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Get list of quaternions from a plane.
        /// </summary>
        /// <param name="plane">The plane</param>
        /// <returns></returns>
        public static List<double> QuatListAtPlane(Plane plane)
        {
            List<double> quats = new List<double>();

            if (plane != null)
            {
                List<double> quatDoubles = RobotUtils.PlaneToQuaternian(plane);
                quats.Add(quatDoubles[0]);
                quats.Add(quatDoubles[1]);
                quats.Add(quatDoubles[2]);
                quats.Add(quatDoubles[3]);
            }
            return quats;
        }
Ejemplo n.º 34
0
        /// <summary><para>
        /// Returns an array of planes located on the curve with equal distance. 
        /// The tangents at the points are the normals of the planes. </para>
        /// <para> Argument Requirement:
        ///             numberOfPoints > 0
        /// </para>
        /// </summary>
        /// <param name="numberOfPlanes"></param>
        /// <returns></returns>
        public Plane[] PlanesAtEqualArcLength(int numberOfPlanes)
        {
            if (numberOfPlanes < 1)
                throw new System.ArgumentException(string.Format(Properties.Resources.LessThan, "number of planes", "one"), "numberOfPlanes");

            IPointEntity[] pts = PointsAtEqualArcLengthCore(numberOfPlanes);
            if (null == pts)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "number of planes"), "numberOfPlanes");

            Plane[] plns = new Plane[pts.Length];
            int i = 0;
            foreach (var p in pts)
            {
                double param = CurveEntity.ParameterAtPoint(p);
                try
                {
                    plns[i++] = PlaneAtParameter(param);
                }
                catch
                {
                    //Proceed with next iteration.
                }
                p.Dispose();
            }

            return plns;
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Convert a DS Plane to a Revit Plane.
 /// </summary>
 /// <param name="plane"></param>
 /// <returns></returns>
 public static Autodesk.Revit.DB.Plane ToPlane(this Autodesk.DesignScript.Geometry.Plane plane)
 {
     return(new Autodesk.Revit.DB.Plane(plane.Normal.ToXyz(), plane.Origin.ToXyz()));
 }
Ejemplo n.º 36
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="planes"></param>
        /// <param name="selectPoint"></param>
        /// <param name="autoExtend"></param>
        /// <returns></returns>
        public Surface Trim(Plane[] planes, Point selectPoint, bool autoExtend)
        {
            if(null == planes)
                throw new System.ArgumentNullException("planes");

            return Trim(null, planes, null, null, selectPoint, autoExtend);
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Performs hit test on Gizmo to find out hit object. The returned 
        /// hitObject could be either axis vector or a plane.
        /// </summary>
        /// <param name="source">Mouse click source for hit test</param>
        /// <param name="direction">View projection direction</param>
        /// <param name="hitObject">object hit</param>
        /// <returns>True if Gizmo was hit successfully</returns>
        public bool HitTest(Point source, Vector direction, out object hitObject)
        {
            hitAxis = null;
            hitPlane = null; //reset hit objects
            hitObject = HitTest(source, direction);
            hitAxis = hitObject as Vector;
            if (hitAxis == null)
            {
                hitPlane = hitObject as Plane;
            }

            return hitObject != null;
        }
Ejemplo n.º 38
0
 //**CREATE
 /// <summary>
 /// Construct an instance of slicer via a static method.
 /// This makes vertical stacks of given solid
 /// with each stack being of specified thickness
 /// and with given plane as the initial cutplane
 /// </summary>
 /// <param name="solid">Solid: geometry that is to be parsed</param>
 /// <param name="plane">Plane: primary cutplane</param>
 /// <param name="line1">Line1: (optional) defines secondary cutplane</param>
 /// <param name="line2">Line2: (optional) defines tertiary cutplane</param>
 /// <param name="thickness">Thickness: the thickness of the slices, or the thickness of the material to be used for the assembly</param>
 /// <param name="spacing">Spacing: the distance between each slice</param>
 /// <returns>A newly-constructed Slicer object</returns>
 public static Slicer ByPlaneAndLines(Solid solid, Plane plane, Line line1 = null, Line line2 = null, double thickness = 1, double spacing = 0)
 {
     if (!solid.DoesIntersect(plane)) throw new ArgumentException("plane does not intersection solid");
     if (line1.Direction.IsParallel(plane.Normal)) throw new ArgumentException("line is perpendicular to plane");
     if (line2.Direction.IsParallel(plane.Normal)) throw new ArgumentException("line is perpendicular to plane");
     return new Slicer(solid, plane, line1, line2, thickness, spacing);
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Convert a DesignScript plane to a Nucleus one
 /// </summary>
 /// <param name="plane"></param>
 /// <returns></returns>
 public static Plane Convert(DS.Plane plane)
 {
     return(new Plane(Convert(plane.Origin), Convert(plane.XAxis), Convert(plane.YAxis)));
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Define tooldata from plane and load value.
 /// </summary>
 /// <param name="pl">Plane</param>
 /// <param name="load">Load in kg</param>
 /// <param name="name">Name of tooldata variable</param>
 /// <returns></returns>
 public static List<string> ToolAtPlane(Plane pl, object load, string name)
 {
     List<string> toolData = new List<string>();
     List<double> quats = RobotUtils.PlaneToQuaternian(pl);
     string tool = string.Format("\tPERS tooldata {0}:=[TRUE,[[{1},{2},{3}],[{4},{5},{6},{7}]],[{8},[0,0,0.001],[1,0,0,0],0,0,0]];\n", name, pl.Origin.X, pl.Origin.Y, pl.Origin.Z, quats[0], quats[1], quats[2], quats[3], load);
     toolData.Add(tool);
     return toolData;
 }
Ejemplo n.º 41
0
        /// <summary>
        /// Constructors a point by projecting a point on a plane. It is 
        /// equivalent to finding the nearest point on the plane.
        /// </summary>
        /// <param name="contextPlane">Plane of projection</param>
        /// <returns>Point</returns>
        public Point Project(Plane contextPlane)
        {
            if (contextPlane == null)
            {
                throw new ArgumentNullException("contextPlane");
            }

            var pt = contextPlane.Project(this);
            pt.Context = contextPlane;
            pt.ReferencePoint = this;
            pt.Persist();
            return pt;
        }
Ejemplo n.º 42
0
 /// <summary>
 /// Define wobjdata from plane.
 /// </summary>
 /// <param name="pl">Plane</param>
 /// <param name="name">Name of wobjdata variable</param>
 /// <returns></returns>
 public static List<string> WobjAtPlane(Plane pl, string name)
 {
     List<string> wobjData = new List<string>();
     List<double> quats = RobotUtils.PlaneToQuaternian(pl);
     string wobj = string.Format("\tTASK PERS wobjdata {0}:=[FALSE,TRUE," + @"""""" + ",[[{1},{2},{3}],[{4},{5},{6},{7}]],[[0,0,0],[1,0,0,0]]];\n", name, pl.Origin.X, pl.Origin.Y, pl.Origin.Z, quats[0], quats[1], quats[2], quats[3]);
     wobjData.Add(wobj);
     return wobjData;
 }
Ejemplo n.º 43
0
        /// <summary>
        /// Returns the projection of this curve on a given plane with plane 
        /// normal as direction
        /// </summary>
        /// <param name="contextPlane">Projection plane</param>
        /// <returns>Projected curve on the context plane</returns>
        public Curve Project(Plane contextPlane)
        {
            string kMethodName = "Curve.Project";
            if (null == contextPlane)
                throw new System.ArgumentNullException("contextPlane");

            ICurveEntity entity = CurveEntity.ProjectOn(contextPlane.PlaneEntity, contextPlane.Normal.IVector);
            if (entity == null)
                throw new System.InvalidOperationException(string.Format(Properties.Resources.OperationFailed, kMethodName));

            return entity.ToCurve(true, this);
        }
Ejemplo n.º 44
0
        internal static IEnumerable<Curve> FromStringOriginAndScale(string text, Plane originPlane, double scale = 1.0)
        {
            //http://msdn.microsoft.com/en-us/library/ms745816(v=vs.110).aspx

            var crvs = new List<Curve>();

            var font = new System.Windows.Media.FontFamily("Arial");
            var fontStyle = FontStyles.Normal;
            var fontWeight = FontWeights.Medium;

            // Create the formatted text based on the properties set.
            var formattedText = new FormattedText(
                text,
                CultureInfo.GetCultureInfo("en-us"),
                FlowDirection.LeftToRight,
                new Typeface(
                    font,
                    fontStyle,
                    fontWeight,
                    FontStretches.Normal),
                1,
                System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text.
                );

            // Build the geometry object that represents the text.
            var textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
            foreach (var figure in textGeometry.GetFlattenedPathGeometry().Figures)
            {
                var init = figure.StartPoint;
                var a = figure.StartPoint;
                System.Windows.Point b;
                foreach (var segment in figure.GetFlattenedPathFigure().Segments)
                {
                    var lineSeg = segment as LineSegment;
                    if (lineSeg != null)
                    {
                        b = lineSeg.Point;
                        var crv = LineBetweenPoints(originPlane.Origin, 0.5*scale, a, b);
                        a = b;
                        CoordinateSystem localWorldcs = CoordinateSystem.ByOrigin(originPlane.Origin);
                        Curve rotC = (Curve)crv.Transform(localWorldcs, originPlane.ToCoordinateSystem());
                        crvs.Add(rotC);
                    }

                    var plineSeg = segment as PolyLineSegment;
                    if (plineSeg != null)
                    {
                        foreach (var segPt in plineSeg.Points)
                        {
                            var crv = LineBetweenPoints(originPlane.Origin, 0.5 * scale, a, segPt);
                            a = segPt;
                            CoordinateSystem localWorldcs = CoordinateSystem.ByOrigin(originPlane.Origin);
                            Curve rotC = (Curve)crv.Transform(localWorldcs, originPlane.ToCoordinateSystem());
                            crvs.Add(rotC);
                        }
                    }

                }
            }

            return crvs;
        }
Ejemplo n.º 45
0
        internal override IGeometryEntity[] IntersectWithPlane(Plane plane)
        {
            ILineEntity line = PlaneEntity.IntersectWith(plane.PlaneEntity);
            if (null != line)
                return new IGeometryEntity[] { line };

            return null;
        }
Ejemplo n.º 46
0
    internal static DSPlane CoordinateSystemToPlane(CoordinateSystem cs)
    {
        DSPlane pl = DSPlane.ByOriginXAxisYAxis(cs.Origin, cs.XAxis, cs.YAxis);

        return(pl);
    }
Ejemplo n.º 47
0
 /// <summary>
 /// Create robot target from plane.
 /// </summary>
 /// <param name="plane">Plane</param>
 /// <returns></returns>
 public static RobTarget RobTargetAtPlane(Plane plane)
 {
     var target = new RobTarget();
     if (plane != null)
     {
         List<double> quatDoubles = RobotUtils.PlaneToQuaternian(plane);
         target.FillFromString2(
             string.Format(
                 "[[{0},{1},{2}],[{3},{4},{5},{6}],[0,0,0,0],[9.999999999E09,9.999999999E09,9.999999999E09,9.999999999E09,9.999999999E09,9.999999999E09]];",
                 plane.Origin.X, plane.Origin.Y, plane.Origin.Z, quatDoubles[0], quatDoubles[1], quatDoubles[2], quatDoubles[3]));
     }
     return target;
 }
Ejemplo n.º 48
0
 private Plane[][] ShiftCutPlanes(List<Plane> planes, double thickness)
 {
     Plane[] shiftUp = new Plane[planes.Count];
     Plane[] shiftDown = new Plane[planes.Count];
     for (int i = 0; i < planes.Count; i++)
     {
         shiftUp[i] = planes[i].Offset(thickness / 2.0);
         shiftDown[i] = planes[i].Offset(- thickness / 2.0);
     }
     Plane[][] shifted = {shiftUp, shiftDown};
     return shifted;
 }
Ejemplo n.º 49
0
        /// <summary>
        /// Draws plane at half the scale.
        /// </summary>
        /// <param name="package"></param>
        /// <param name="plane"></param>
        /// <param name="name"></param>
        private void DrawPlane(ref IRenderPackage package, Plane plane, Planes name)
        {
            package.Description = string.Format("{0}_{1}_{2}", RenderDescriptions.ManipulatorPlane, Name, name.ToString()); 
            var p1 = Origin.Add(plane.XAxis.Scale(scale/2));
            var p2 = p1.Add(plane.YAxis.Scale(scale/2));
            var p3 = Origin.Add(plane.YAxis.Scale(scale/2));
            
            package.AddLineStripVertexCount(3);
            package.AddLineStripVertexColor(0, 0, 255, 255);
            package.AddLineStripVertex(p1.X, p1.Y, p1.Z);

            package.AddLineStripVertexColor(0, 0, 255, 255);
            package.AddLineStripVertex(p2.X, p2.Y, p2.Z);

            package.AddLineStripVertexColor(0, 0, 255, 255);
            package.AddLineStripVertex(p3.X, p3.Y, p3.Z);
        }
Ejemplo n.º 50
0
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outline">The outline.</param>
        /// <param name="floorType">Type of the floor.</param>
        /// <param name="level">The level.</param>
        /// <param name="structural">if set to <c>true</c> [structural].</param>
        /// <returns>
        /// The floor
        /// </returns>
        public static SlopedFloor ByOutlineTypeAndLevel(Autodesk.DesignScript.Geometry.PolyCurve outline, Revit.Elements.FloorType floorType, Revit.Elements.Level level, bool structural)
        {
            Utils.Log(string.Format("SlopedFloor.ByOutlineTypeAndLevel started...", ""));

            try
            {
                var profile = new CurveArray();

                Autodesk.DesignScript.Geometry.Plane plane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(
                    outline.Curves().Cast <Autodesk.DesignScript.Geometry.Curve>().Select(x => x.StartPoint));

                Vector normal = plane.Normal;
                if (normal.Dot(Vector.ZAxis()) <= 0)
                {
                    normal = normal.Reverse();
                }

                Autodesk.DesignScript.Geometry.Point origin     = plane.Origin;
                Autodesk.DesignScript.Geometry.Point end        = origin.Add(normal);
                Autodesk.DesignScript.Geometry.Point projection = Autodesk.DesignScript.Geometry.Point.ByCoordinates(end.X, end.Y, -1000);
                end = Autodesk.DesignScript.Geometry.Point.ByCoordinates(end.X, end.Y, end.Z + 1000);
                Autodesk.DesignScript.Geometry.Point intersection = null;
                var result = plane.Intersect(Autodesk.DesignScript.Geometry
                                             .Line.ByStartPointEndPoint(end, projection));

                if (result.Length > 0)
                {
                    intersection = result[0] as Autodesk.DesignScript.Geometry.Point;
                }
                else
                {
                    var message = "Couldn't find intersection";

                    Utils.Log(string.Format("ERROR: SlopedFloor.ByOutlineTypeAndLevel {0}", message));

                    throw new Exception(message);
                }

                Autodesk.DesignScript.Geometry.Curve temp = Autodesk.DesignScript.Geometry.Line.ByBestFitThroughPoints(new Autodesk.DesignScript.Geometry.Point[] { origin, intersection });

                PolyCurve flat = PolyCurve.ByJoinedCurves(outline.PullOntoPlane(Autodesk.DesignScript.Geometry.Plane.XY()
                                                                                .Offset(temp.StartPoint.Z)).Explode().Cast <Autodesk.DesignScript.Geometry.Curve>().ToList());

                Autodesk.DesignScript.Geometry.Curve flatLine = temp.PullOntoPlane(Autodesk.DesignScript.Geometry.Plane.XY().Offset(temp.StartPoint.Z));

                if (Math.Abs(Math.Abs(plane.Normal.Dot(Vector.ZAxis())) - 1) < 0.00001)
                {
                    var f = Revit.Elements.Floor.ByOutlineTypeAndLevel(flat, floorType, level);
                    f.InternalElement.Parameters.Cast <Autodesk.Revit.DB.Parameter>()
                    .First(x => x.Id.IntegerValue.Equals(Autodesk.Revit.DB.BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL))
                    .Set(structural ? 1 : 0);

                    plane.Dispose();
                    flatLine.Dispose();
                    flat.Dispose();
                    origin.Dispose();
                    end.Dispose();
                    projection.Dispose();
                    intersection.Dispose();
                    temp.Dispose();

                    return(new SlopedFloor(f.InternalElement as Autodesk.Revit.DB.Floor));
                }

                double slope = (temp.EndPoint.Z - temp.StartPoint.Z) / flatLine.Length;

                foreach (Autodesk.DesignScript.Geometry.Curve c in flat.Curves())
                {
                    profile.Append(c.ToRevitType());
                }

                Autodesk.Revit.DB.Line slopeArrow = flatLine.ToRevitType() as Autodesk.Revit.DB.Line;

                var ft  = floorType.InternalElement as Autodesk.Revit.DB.FloorType;
                var lvl = level.InternalElement as Autodesk.Revit.DB.Level;

                var floor = new SlopedFloor(profile, slopeArrow, slope, ft, lvl, structural);

                floor.Level      = level;
                floor.Floortype  = floorType;
                floor.Structural = structural;

                //DocumentManager.Regenerate();

                plane.Dispose();
                flatLine.Dispose();
                flat.Dispose();
                origin.Dispose();
                end.Dispose();
                projection.Dispose();
                intersection.Dispose();
                temp.Dispose();

                Utils.Log(string.Format("SlopedFloor.ByOutlineTypeAndLevel completed.", ""));

                return(floor);
            }
            catch (Exception ex)
            {
                Utils.Log(string.Format("ERROR: SlopedFloor.ByOutlineTypeAndLevel {0}", ex.Message));

                throw ex;
            }
        }
Ejemplo n.º 51
0
        /// <summary>
        /// Gets the rectangular openings.
        /// </summary>
        /// <returns></returns>
        /// <remarks>This method uses walls, doors, windows and generic models bounding boxes to determine the rectangles.
        /// These objects can be in the host file or in linked Revit files.</remarks>
        public static IList <Autodesk.DesignScript.Geometry.Rectangle> GetRectangularOpenings()
        {
            Utils.Log(string.Format("OpeningUtils.GetRectangularOpenings started...", ""));

            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;

            //look for Walls, Doors, Windows, Generic Models in the current document and in the linked documents
            ElementCategoryFilter wallFilter    = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
            ElementCategoryFilter doorFilter    = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
            ElementCategoryFilter windowFilter  = new ElementCategoryFilter(BuiltInCategory.OST_Windows);
            ElementCategoryFilter genericFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel);

            IList <ElementFilter> filterList = new List <ElementFilter>()
            {
                wallFilter, doorFilter, windowFilter, genericFilter
            };

            LogicalOrFilter orFilter = new LogicalOrFilter(filterList);

            IList <Autodesk.DesignScript.Geometry.Solid> solids = new List <Autodesk.DesignScript.Geometry.Solid>();

            IList <Autodesk.DesignScript.Geometry.Rectangle> output = new List <Autodesk.DesignScript.Geometry.Rectangle>();

            foreach (Autodesk.Revit.DB.Element e in new FilteredElementCollector(doc)
                     .WherePasses(orFilter)
                     .WhereElementIsNotElementType()
                     .Where(x =>
                            x.Parameters.Cast <Autodesk.Revit.DB.Parameter>()
                            .First(p => p.Id.IntegerValue == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).HasValue))
            {
                string comments = e.Parameters.Cast <Autodesk.Revit.DB.Parameter>().First(p => p.Id.IntegerValue == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).AsString();

                if (comments.ToLower() != "opening")
                {
                    continue;
                }

                Transform tr = Transform.Identity;

                if (e is Instance)
                {
                    Instance instance = e as Instance;
                    tr = instance.GetTotalTransform();
                }

                IList <Autodesk.Revit.DB.Solid> temp = new List <Autodesk.Revit.DB.Solid>();

                foreach (GeometryObject go in e.get_Geometry(new Options()))
                {
                    if (go is GeometryInstance)
                    {
                        GeometryInstance geoInstance = go as GeometryInstance;

                        foreach (var gi in geoInstance.SymbolGeometry)
                        {
                            if (gi is Autodesk.Revit.DB.Solid)
                            {
                                Autodesk.Revit.DB.Solid s = gi as Autodesk.Revit.DB.Solid;
                                s = SolidUtils.CreateTransformed(s, tr);
                                temp.Add(s);
                            }
                        }
                    }
                    else
                    {
                        if (go is Autodesk.Revit.DB.Solid)
                        {
                            Autodesk.Revit.DB.Solid s = go as Autodesk.Revit.DB.Solid;
                            s = SolidUtils.CreateTransformed(s, tr);
                            temp.Add(s);
                        }
                    }
                }

                if (temp.Count > 0)
                {
                    Autodesk.Revit.DB.Solid s0 = temp[0];
                    for (int i = 1; i < temp.Count; ++i)
                    {
                        s0 = BooleanOperationsUtils.ExecuteBooleanOperation(s0, temp[i], BooleanOperationsType.Union);
                    }

                    solids.Add(s0.ToProtoType());
                }
            }

            foreach (RevitLinkInstance rli in new FilteredElementCollector(doc).OfClass(typeof(RevitLinkInstance)).WhereElementIsNotElementType())
            {
                Autodesk.Revit.DB.Document link = rli.GetLinkDocument();

                foreach (Autodesk.Revit.DB.Element e in new FilteredElementCollector(link)
                         .WherePasses(orFilter)
                         .WhereElementIsNotElementType()
                         .Where(x =>
                                x.Parameters.Cast <Autodesk.Revit.DB.Parameter>()
                                .First(p => p.Id.IntegerValue == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).HasValue))
                {
                    Transform tr = rli.GetTotalTransform();

                    string comments = e.Parameters.Cast <Autodesk.Revit.DB.Parameter>().First(p => p.Id.IntegerValue == (int)BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).AsString();

                    if (comments.ToLower() != "opening")
                    {
                        continue;
                    }

                    if (e is Instance)
                    {
                        Instance instance = e as Instance;
                        tr = tr.Multiply(instance.GetTotalTransform());
                    }

                    IList <Autodesk.Revit.DB.Solid> temp = new List <Autodesk.Revit.DB.Solid>();

                    foreach (var go in e.get_Geometry(new Options()))
                    {
                        if (go is GeometryInstance)
                        {
                            GeometryInstance geoInstance = go as GeometryInstance;

                            foreach (var gi in geoInstance.SymbolGeometry)
                            {
                                if (gi is Autodesk.Revit.DB.Solid)
                                {
                                    Autodesk.Revit.DB.Solid s = gi as Autodesk.Revit.DB.Solid;
                                    s = SolidUtils.CreateTransformed(s, tr);
                                    temp.Add(s);
                                }
                            }
                        }
                        else
                        {
                            if (go is Autodesk.Revit.DB.Solid)
                            {
                                Autodesk.Revit.DB.Solid s = go as Autodesk.Revit.DB.Solid;
                                s = SolidUtils.CreateTransformed(s, tr);
                                temp.Add(s);
                            }
                        }
                    }

                    if (temp.Count > 0)
                    {
                        Autodesk.Revit.DB.Solid s0 = temp[0];
                        for (int i = 1; i < temp.Count; ++i)
                        {
                            s0 = BooleanOperationsUtils.ExecuteBooleanOperation(s0, temp[i], BooleanOperationsType.Union);
                        }

                        solids.Add(s0.ToProtoType());
                    }
                }
            }

            foreach (var s in solids)
            {
                IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>();

                foreach (var v in s.Vertices)
                {
                    points.Add(v.PointGeometry);
                }

                points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points);

                Autodesk.DesignScript.Geometry.Plane plane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(points);

                plane = Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(points.Last(), plane.Normal);

                IList <Autodesk.DesignScript.Geometry.Point> temp = new List <Autodesk.DesignScript.Geometry.Point>();

                foreach (var p in points)
                {
                    foreach (var q in p.Project(plane, plane.Normal))
                    {
                        temp.Add(q as Autodesk.DesignScript.Geometry.Point);
                    }

                    foreach (var q in p.Project(plane, plane.Normal.Reverse()))
                    {
                        temp.Add(q as Autodesk.DesignScript.Geometry.Point);
                    }
                }

                temp = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(temp);

                CoordinateSystem cs = CoordinateSystem.ByPlane(plane);

                IList <Autodesk.DesignScript.Geometry.Point> relative = new List <Autodesk.DesignScript.Geometry.Point>();

                foreach (var p in temp)
                {
                    relative.Add(p.Transform(cs.Inverse()) as Autodesk.DesignScript.Geometry.Point);
                }

                var min = Autodesk.DesignScript.Geometry.Point.ByCoordinates(relative.Min(p => p.X),
                                                                             relative.Min(p => p.Y),
                                                                             relative.Min(p => p.Z));

                var max = Autodesk.DesignScript.Geometry.Point.ByCoordinates(relative.Max(p => p.X),
                                                                             relative.Max(p => p.Y),
                                                                             relative.Max(p => p.Z));

                double width  = max.X - min.X;
                double height = max.Y - min.Y;

                min = min.Transform(cs) as Autodesk.DesignScript.Geometry.Point;
                max = max.Transform(cs) as Autodesk.DesignScript.Geometry.Point;

                plane = Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(min, max).PointAtParameter(0.5), plane.Normal);

                Autodesk.DesignScript.Geometry.Rectangle rectangle = Autodesk.DesignScript.Geometry.Rectangle.ByWidthLength(plane,
                                                                                                                            width,
                                                                                                                            height);

                output.Add(rectangle);

                plane.Dispose();
                cs.Dispose();
                min.Dispose();
                max.Dispose();
            }

            Utils.Log(string.Format("OpeningUtils.GetRectangularOpenings completed.", ""));

            return(output);
        }
Ejemplo n.º 52
0
        public static Dictionary<string, double> QuatAtPlane(Plane plane)
        {
            List<double> quats = new List<double>();

            if (plane != null)
            {
                List<double> quatDoubles = RobotUtils.PlaneToQuaternian(plane);
                quats.Add(quatDoubles[0]);
                quats.Add(quatDoubles[1]);
                quats.Add(quatDoubles[2]);
                quats.Add(quatDoubles[3]);
            }
            return new Dictionary<string, double>
            {
            {"q1", quats[0]},
            {"q2", quats[1]},
            {"q3", quats[2]},
            {"q4", quats[3]}
            };
        }
 public static Autodesk.Revit.DB.Plane ToPlane(this Autodesk.DesignScript.Geometry.Plane plane, bool convertUnits = true)
 {
     return(Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(plane.Normal.ToXyz(), plane.Origin.ToXyz(convertUnits)));
 }
Ejemplo n.º 54
0
 /// <summary>
 /// Returns a plane at a point on the curve by given paramater and use 
 /// the tangent at the point as Normal of the plane. This method can 
 /// specify the size of the plane.
 /// Argument Requirement:
 ///     planeSize >= 1
 /// </summary>
 /// <param name="param"></param>
 /// <param name="planeSize"></param>
 /// <returns></returns>
 public Plane PlaneAtParameter(double param, double planeSize)
 {
     var origin = CurveEntity.PointAtParameter(param).ToPoint(false, null);
     var tangent = TangentAtParameter(param);
     Plane result = new Plane(origin, tangent, planeSize, true, this);
     result.T = param;
     result.Distance = CurveEntity.DistanceAtParameter(param);
     return result;
 }