/// <summary>
        /// DS Rectangle to SpecklePolyline
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public Polyline PolylineToSpeckle(DS.Rectangle rectangle, string units = null)
        {
            var rect = PolylineToSpeckle(rectangle as DS.Polygon, units ?? ModelUnits);

            CopyProperties(rect, rectangle);
            return(rect);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create an Advance Steel Rectangular Shear Stud Pattern By Rectangle
        /// </summary>
        /// <param name="rectangle"> Input Dynamo Rectangle </param>
        /// <param name="objectToConnect"> Object to attached ShearStud </param>
        /// <param name="studLength"> Input Shear Stud Length</param>
        /// <param name="studDiameter"> Input Shear Stud Diameter</param>
        /// <param name="noOfShearStudsX"> Input Number of Shear Stud X Direction</param>
        /// <param name="noOfShearStudsY"> Input Number of Shear Stud Y Direction</param>
        /// <param name="shearStudConnectionType"> Input Shear Bolt Connection type - Shop Bolt Default</param>
        /// <param name="additionalShearStudParameters"> Optional Input ShearStud Build Properties </param>
        /// <returns name="rectangularShearStudsPattern"> rectangularShearStudsPattern</returns>
        public static RectangularShearStudsPattern ByRectangle(Autodesk.DesignScript.Geometry.Rectangle rectangle,
                                                               SteelDbObject objectToConnect,
                                                               double studLength,
                                                               double studDiameter,
                                                               [DefaultArgument("2;")] int noOfShearStudsX,
                                                               [DefaultArgument("2;")] int noOfShearStudsY,
                                                               [DefaultArgument("2;")] int shearStudConnectionType,
                                                               [DefaultArgument("null")] List <Property> additionalShearStudParameters)
        {
            var dynCorners = rectangle.Corners();
            var astCorners = Utils.ToAstPoints(dynCorners, true);
            var vx         = astCorners[1] - astCorners[0];
            var vy         = astCorners[3] - astCorners[0];
            var vz         = Utils.ToAstVector3d(rectangle.Normal, true);

            vx = vx.Normalize();
            vy = vy.Normalize();
            vz = vz.Normalize();

            List <SteelDbObject> tempList = new List <SteelDbObject>()
            {
                objectToConnect
            };
            List <string> handlesList = Utils.GetSteelDbObjectsToConnect(tempList);

            var      rectangleCenter = astCorners[0] + (astCorners[2] - astCorners[0]) * 0.5;
            Matrix3d matrix3D        = new Matrix3d();

            matrix3D.SetCoordSystem(rectangleCenter, vx, vy, vz);

            additionalShearStudParameters = PreSetValuesInListProps(additionalShearStudParameters, noOfShearStudsX, noOfShearStudsY, Utils.ToInternalDistanceUnits(studLength, true), Utils.ToInternalDistanceUnits(studDiameter, true));

            return(new RectangularShearStudsPattern(astCorners[0], astCorners[2], handlesList[0], vx, vy, matrix3D,
                                                    additionalShearStudParameters, shearStudConnectionType));
        }
Exemplo n.º 3
0
        /// <summary>
        /// DS Rectangle to SpecklePolyline
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public Polyline PolylineToSpeckle(DS.Rectangle rectangle)
        {
            var rect = PolylineToSpeckle(rectangle as DS.Polygon);

            CopyProperties(rect, rectangle);
            return(rect);
        }
Exemplo n.º 4
0
        public static Dictionary <string, object> ViewportsCollector()
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;
            //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication;
            //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;

            List <Revit.Elements.Element> lstViewports = new List <Revit.Elements.Element>();
            List <ADG.Point>         centerViewports   = new List <ADG.Point>();
            List <List <ADG.Point> > pointsViewports   = new List <List <ADG.Point> >();
            List <ADG.Rectangle>     outlines          = new List <ADG.Rectangle>();

            FilteredElementCollector col = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Viewports).WhereElementIsNotElementType();

            foreach (Viewport c in col)
            {
                List <ADG.Point>       mmP = new List <ADG.Point>();
                Revit.Elements.Element v   = c.ToDSType(true);
                XYZ       center           = c.GetBoxCenter();
                ADG.Point cc = ADG.Point.ByCoordinates(center.X, center.Y);
                Outline   o  = c.GetBoxOutline();

                XYZ minPoint = o.MinimumPoint;
                XYZ maxPoint = o.MaximumPoint;

                List <ADG.Point> cP = new List <ADG.Point>();
                cP.Add(ADG.Point.ByCoordinates(minPoint.X, minPoint.Y));
                cP.Add(ADG.Point.ByCoordinates(minPoint.X, maxPoint.Y));
                cP.Add(ADG.Point.ByCoordinates(maxPoint.X, maxPoint.Y));
                cP.Add(ADG.Point.ByCoordinates(maxPoint.X, minPoint.Y));

                mmP.Add(ADG.Point.ByCoordinates(minPoint.X, minPoint.Y));
                mmP.Add(ADG.Point.ByCoordinates(maxPoint.X, maxPoint.Y));

                ADG.Rectangle rec = ADG.Rectangle.ByCornerPoints(cP);

                lstViewports.Add(v);
                centerViewports.Add(cc);
                pointsViewports.Add(mmP);
                outlines.Add(rec);
            }

            return(new Dictionary <string, object>
            {
                { "Viewports", lstViewports },
                { "CenterPoints", centerViewports },
                { "MinMaxPoints", pointsViewports },
                { "Outlines", outlines }
            });
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create an Advance Steel Rectangular Anchor Pattern bound By Rectangle
        /// </summary>
        /// <param name="rectangle"> Input rectangle </param>
        /// <param name="noOfBoltsX"> Input No of Anchor Bolts in the X direction</param>
        /// <param name="noOfBoltsY"> Input No of Anchor Bolts in the Y direction</param>
        /// <param name="objectsToConnect"> Input Objects to be bolted </param>
        /// <param name="boltConnectionType"> Input Bolt Connection type - Shop Bolt Default</param>
        /// <param name="additionalAnchorBoltParameters"> Optional Input Anchor Bolt Build Properties </param>
        /// <returns name="rectangularAnchorPattern"> rectangularAnchorPattern</returns>
        public static RectangularAnchorPattern ByRectangle(Autodesk.DesignScript.Geometry.Rectangle rectangle,
                                                           [DefaultArgument("2;")] int noOfBoltsX,
                                                           [DefaultArgument("2;")] int noOfBoltsY,
                                                           IEnumerable <SteelDbObject> objectsToConnect,
                                                           [DefaultArgument("2;")] int boltConnectionType,
                                                           [DefaultArgument("null")] List <Property> additionalAnchorBoltParameters)
        {
            List <string> handlesList = Utils.GetSteelDbObjectsToConnect(objectsToConnect);

            var dynCorners = rectangle.Corners();
            var astCorners = Utils.ToAstPoints(dynCorners, true);
            var vx         = astCorners[1] - astCorners[0];
            var vy         = astCorners[3] - astCorners[0];

            additionalAnchorBoltParameters = PreSetValuesInListProps(additionalAnchorBoltParameters, noOfBoltsX, noOfBoltsY);

            return(new RectangularAnchorPattern(astCorners[0], astCorners[2], handlesList, vx, vy, additionalAnchorBoltParameters, boltConnectionType));
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void ToPDF(iTextSharp.text.pdf.PdfWriter w)
        {
            PdfContentByte cb = w.DirectContent;

            cb.SetLineWidth((float)Settings.Thickness);
            if (Settings.Fill != null)
            {
                cb.SetColorFill(Settings.Fill.ToPDFColor());
            }

            if (Settings.Stroke != null)
            {
                cb.SetColorStroke(Settings.Stroke.ToPDFColor());
            }

            if (Geometry.GetType() == typeof(Dyn.Arc))
            {
                Dyn.Arc arc = Geometry as Dyn.Arc;
                cb.MoveTo(arc.StartPoint.X, arc.EndPoint.Y);
                cb.CurveTo(arc.PointAtParameter(0.5).X, arc.PointAtParameter(0.5).Y, arc.EndPoint.X, arc.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Line))
            {
                Dyn.Line line = Geometry as Dyn.Line;
                cb.MoveTo(line.StartPoint.X, line.StartPoint.Y);
                cb.LineTo(line.EndPoint.X, line.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Circle))
            {
                Dyn.Circle circle = Geometry as Dyn.Circle;
                cb.Circle(circle.CenterPoint.X, circle.CenterPoint.Y, circle.Radius);
            }
            else if (Geometry.GetType() == typeof(Dyn.Ellipse))
            {
                Dyn.Ellipse ellipse = Geometry as Dyn.Ellipse;
                cb.Ellipse(ellipse.StartPoint.X, ellipse.StartPoint.Y, ellipse.EndPoint.X, ellipse.EndPoint.Y);
            }
            else if (Geometry.GetType() == typeof(Dyn.Rectangle))
            {
                Dyn.Rectangle rect = Geometry as Dyn.Rectangle;
                cb.Rectangle(rect.Center().X, rect.Center().Y, rect.Width, rect.Height);
            }
            else if (Geometry.GetType() == typeof(Dyn.Polygon))
            {
                Dyn.Polygon p = Geometry as Dyn.Polygon;
                foreach (var curve in p.Curves())
                {
                    CurveToPDF(curve, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.PolyCurve))
            {
                Dyn.PolyCurve pc = Geometry as Dyn.PolyCurve;
                foreach (var curve in pc.Curves())
                {
                    CurveToPDF(curve, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.NurbsCurve))
            {
                Dyn.NurbsCurve nc = Geometry as Dyn.NurbsCurve;

                foreach (var linearc in nc.ApproximateWithArcAndLineSegments())
                {
                    CurveToPDF(linearc, cb);
                }
            }
            else if (Geometry.GetType() == typeof(Dyn.Curve))
            {
                Dyn.Curve curve = Geometry as Dyn.Curve;
                CurveToPDF(curve, cb);
            }
            else
            {
                throw new Exception(Properties.Resources.NotSupported);
            }

            if (Settings.Fill != null && Settings.Stroke != null)
            {
                cb.FillStroke();
            }
            else
            {
                if (Settings.Stroke != null)
                {
                    cb.Stroke();
                }
                if (Settings.Fill != null)
                {
                    cb.Fill();
                }
            }
        }