Ejemplo n.º 1
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static List <ICurve> AnalyticalOutlines(this HostObject hostObject, RevitSettings settings = null)
        {
            AnalyticalModel analyticalModel = hostObject.GetAnalyticalModel();

            if (analyticalModel == null)
            {
                //TODO: appropriate warning or not - physical preferred?
                return(null);
            }

            settings = settings.DefaultIfNull();

            List <ICurve> wallCurves = analyticalModel.GetCurves(AnalyticalCurveType.ActiveCurves).ToList().FromRevit();

            if (wallCurves.Any(x => x == null))
            {
                hostObject.UnsupportedOutlineCurveWarning();
                return(null);
            }

            List <ICurve> result = BH.Engine.Geometry.Compute.IJoin(wallCurves).ConvertAll(c => c as ICurve);

            if (result.Any(x => !x.IIsClosed()))
            {
                hostObject.NonClosedOutlineWarning();
                return(null);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// get necessary data when create AreaReinforcement on a horizontal floor
        /// </summary>
        /// <param name="floor">floor on which to create AreaReinforcemen</param>
        /// <param name="refer">reference of the horizontal face on the floor</param>
        /// <param name="curves">curves compose the horizontal face of the floor</param>
        /// <returns>is successful</returns>
        public bool GetFloorGeom(Floor floor, ref Reference refer, ref IList <Curve> curves)
        {
            //get horizontal face reference
            FaceArray faces = GeomUtil.GetFaces(floor);

            foreach (Face face in faces)
            {
                if (GeomUtil.IsHorizontalFace(face))
                {
                    refer = face.Reference;
                    break;
                }
            }
            //no proper reference
            if (null == refer)
            {
                return(false);
            }

            //check the analytical model profile is rectangular
            AnalyticalModel model = floor.GetAnalyticalModel();

            if (null == model)
            {
                return(false);
            }
            curves = model.GetCurves(AnalyticalCurveType.ActiveCurves);
            if (!GeomUtil.IsRectangular(curves))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// create GraphicsData of given AnalyticalModel3D
        /// </summary>
        /// <param name="model">AnalyticalModel3D contains geometry data</param>
        /// <returns></returns>
        public static GraphicsData CreateGraphicsData(AnalyticalModel model)
        {
            IList <Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves);

            if (curveList.Count > 0)
            {
                GraphicsData data = new GraphicsData();

                IEnumerator <Curve> curves = curveList.GetEnumerator();
                curves.Reset();
                while (curves.MoveNext())
                {
                    Curve curve = curves.Current as Curve;

                    try
                    {
                        List <XYZ> points = curve.Tessellate() as List <XYZ>;
                        data.InsertCurve(points);
                    }
                    catch
                    {
                    }
                }

                data.UpdataData();

                return(data);
            }
            else
            {
                throw new Exception("Can't get curves.");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// create GraphicsData of given AnalyticalModel3D
        /// </summary>
        /// <param name="model">AnalyticalModel3D contains geometry data</param>
        /// <returns></returns>
        public static GraphicsData CreateGraphicsData(AnalyticalModel model)
        {
            IList<Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves);

            if (curveList.Count > 0)
            {
                GraphicsData data = new GraphicsData();

                IEnumerator<Curve> curves = curveList.GetEnumerator();
                curves.Reset();
                while (curves.MoveNext())
                {
                    Curve curve = curves.Current as Curve;

                    try
                    {
                        List<XYZ> points = curve.Tessellate() as List<XYZ>;
                        data.InsertCurve(points);
                    }
                    catch
                    {
                    }
                }

                data.UpdataData();

                return data;
            }
            else
            {
                throw new Exception("Can't get curves.");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// get necessary data when create AreaReinforcement on a straight wall
        /// </summary>
        /// <param name="wall">wall on which to create AreaReinforcemen</param>
        /// <param name="refer">reference of the vertical straight face on the wall</param>
        /// <param name="curves">curves compose the vertical face of the wall</param>
        /// <returns>is successful</returns>
        public bool GetWallGeom(Wall wall, ref Reference refer, ref CurveArray curves)
        {
            FaceArray     faces    = GeomUtil.GetFaces(wall);
            LocationCurve locCurve = wall.Location as LocationCurve;

            //unless API has bug, locCurve can't be null
            if (null == locCurve)
            {
                return(false);
            }
            //check the location is line
            Line locLine = locCurve.Curve as Line;

            if (null == locLine)
            {
                return(false);
            }

            //get the face reference
            foreach (Face face in faces)
            {
                if (GeomUtil.IsParallel(face, locLine))
                {
                    refer = face.Reference;
                    break;
                }
            }
            //can't find proper reference
            if (null == refer)
            {
                return(false);
            }

            //check the analytical model profile is rectangular
            AnalyticalModel model = wall.GetAnalyticalModel();

            if (null == model)
            {
                return(false);
            }

            IList <Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves);

            curves = m_currentDoc.Application.Create.NewCurveArray();
            foreach (Curve curve in curveList)
            {
                curves.Append(curve);
            }
            if (!GeomUtil.IsRectangular(curves))
            {
                return(false);
            }

            return(true);
        }
        static Transform _t = Transform.CreateTranslation(_offset); // 2014

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            List <Element> walls = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    walls, uidoc, typeof(Wall)))
            {
                Selection sel = uidoc.Selection;
                //message = ( 0 < sel.Elements.Size ) // 2014
                message = (0 < sel.GetElementIds().Count) // 2015
          ? "Please select some wall elements."
          : "No wall elements found.";
                return(Result.Failed);
            }

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create model curve copies of analytical model curves");

                Creator creator = new Creator(doc);

                foreach (Wall wall in walls)
                {
                    AnalyticalModel am = wall.GetAnalyticalModel();

                    foreach (AnalyticalCurveType ct in _curveTypes)
                    {
                        IList <Curve> curves = am.GetCurves(ct);

                        int n = curves.Count;

                        Debug.Print("{0} {1} curve{2}.",
                                    n, ct, Util.PluralSuffix(n));

                        foreach (Curve curve in curves)
                        {
                            //creator.CreateModelCurve( curve.get_Transformed( _t ) ); // 2013

                            creator.CreateModelCurve(curve.CreateTransformed(_t)); // 2014
                        }
                    }
                }
                tx.Commit();
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get a floor's profile.
        /// </summary>
        /// <param name="floor">The floor whose profile you want to get.</param>
        /// <returns>The profile of the floor.</returns>
        private CurveArray GetFloorProfile(Floor floor)
        {
            CurveArray floorProfile = new CurveArray();

            // Structural slab's profile can be found in it's AnalyticalModel.
            if (null != floor.GetAnalyticalModel())
            {
                AnalyticalModel analyticalModel = floor.GetAnalyticalModel();
                IList <Curve>   curveList       = analyticalModel.GetCurves(AnalyticalCurveType.ActiveCurves);
                for (int i = 0; i < curveList.Count; i++)
                {
                    floorProfile.Append(curveList[i]);
                }

                return(floorProfile);
            }

            // Nonstructural floor's profile can be formed through it's Geometry.
            Options aOptions = m_revit.Application.Create.NewGeometryOptions();

            Autodesk.Revit.DB.GeometryElement aElementOfGeometry = floor.get_Geometry(aOptions);
            //GeometryObjectArray geometryObjects = aElementOfGeometry.Objects;
            IEnumerator <GeometryObject> Objects = aElementOfGeometry.GetEnumerator();

            //foreach (GeometryObject o in geometryObjects)
            while (Objects.MoveNext())
            {
                GeometryObject o = Objects.Current;

                Solid solid = o as Solid;
                if (null == solid)
                {
                    continue;
                }

                // Form the floor's profile through solid's edges.
                EdgeArray edges = solid.Edges;
                for (int i = 0; i < (edges.Size) / 3; i++)
                {
                    Edge       edge     = edges.get_Item(i);
                    List <XYZ> xyzArray = edge.Tessellate() as List <XYZ>; // A set of points.
                    for (int j = 0; j < (xyzArray.Count - 1); j++)
                    {
                        Autodesk.Revit.DB.XYZ startPoint = xyzArray[j];
                        Autodesk.Revit.DB.XYZ endPoint   = xyzArray[j + 1];
                        Line line = Line.CreateBound(startPoint, endPoint);

                        floorProfile.Append(line);
                    }
                }
            }
            return(floorProfile);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// create GraphicsData of give AnalyticalModel
 /// </summary>
 /// <param name="model">AnalyticalModel contains geometry data</param>
 /// <returns>A graphics data object appropriate for GDI.</returns>
 private void GetModelData(AnalyticalModel model)
 {
     foreach (Curve curve in model.GetCurves(AnalyticalCurveType.RawCurves))
     {
         try
         {
             m_curve3Ds.Add(curve.Tessellate() as List <XYZ>);
         }
         catch
         {
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Generate a Transform instance which as Transform property of BoundingBoxXYZ,
        /// when the user select a floor, this method will be called
        /// </summary>
        /// <returns>the reference of Transform, return null if it can't be generated</returns>
        Transform GenerateFloorTransform()
        {
            Transform transform = null;
            Floor     floor     = m_currentComponent as Floor;

            // First get the Analytical Model lines
            AnalyticalModel model = floor.GetAnalyticalModel();

            if (null == model)
            {
                m_errorInformation = "Please select a structural floor.";
                return(transform);
            }

            CurveArray    curves    = m_project.Document.Application.Create.NewCurveArray();
            IList <Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves);

            foreach (Curve curve in curveList)
            {
                curves.Append(curve);
            }

            if (null == curves || true == curves.IsEmpty)
            {
                m_errorInformation = "The program should never go here.";
                return(transform);
            }

            // Now I am sure I can create a transform instance.
            transform = Transform.Identity;

            // Third find the middle point of the floor and set it as Origin property.
            Autodesk.Revit.DB.XYZ midPoint = XYZMath.FindMiddlePoint(curves);
            transform.Origin = midPoint;

            // At last find out the directions of the created view, and set it as Basis property.
            Autodesk.Revit.DB.XYZ basisZ = XYZMath.FindFloorViewDirection(curves);
            Autodesk.Revit.DB.XYZ basisX = XYZMath.FindRightDirection(basisZ);
            Autodesk.Revit.DB.XYZ basisY = XYZMath.FindUpDirection(basisZ);

            transform.set_Basis(0, basisX);
            transform.set_Basis(1, basisY);
            transform.set_Basis(2, basisZ);
            return(transform);
        }
Ejemplo n.º 10
0
        Stream(ArrayList data, AnalyticalModel aModel)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModel)));

            try {
                data.Add(new Snoop.Data.Object("GetCurve", aModel.GetCurve()));
            }
            catch (System.Exception ex) {
                data.Add(new Snoop.Data.Exception("GetCurve", ex));
            }
            data.Add(new Snoop.Data.Enumerable("GetCurves", aModel.GetCurves(AnalyticalCurveType.ActiveCurves)));
            try {
                data.Add(new Snoop.Data.Xyz("GetPoint", aModel.GetPoint()));
            }
            catch (System.Exception ex) {
                data.Add(new Snoop.Data.Exception("GetPoint", ex));
            }
            data.Add(new Snoop.Data.Enumerable("GetAnalyticalModelSupports", aModel.GetAnalyticalModelSupports()));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// get necessary data when create AreaReinforcement on a horizontal floor
        /// </summary>
        /// <param name="floor">floor on which to create AreaReinforcemen</param>
        /// <param name="refer">reference of the horizontal face on the floor</param>
        /// <param name="curves">curves compose the horizontal face of the floor</param>
        /// <returns>is successful</returns>
        public bool GetFloorGeom(Floor floor, ref Reference refer, ref CurveArray curves)
        {
            //get horizontal face's reference
            FaceArray faces = GeomUtil.GetFaces(floor);

            foreach (Face face in faces)
            {
                if (GeomUtil.IsHorizontalFace(face))
                {
                    refer = face.Reference;
                    break;
                }
            }
            if (null == refer)
            {
                return(false);
            }
            //get analytical model profile
            AnalyticalModel model = floor.GetAnalyticalModel();

            if (null == model)
            {
                return(false);
            }

            IList <Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves);

            curves = m_currentDoc.Application.Create.NewCurveArray();
            foreach (Curve curve in curveList)
            {
                curves.Append(curve);
            }

            if (!GeomUtil.IsRectangular(curves))
            {
                return(false);
            }
            curves = AddInlaidCurves(curves, 0.5);

            return(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Auxiliary method. Gets sample points from surface element contour( three points for each contour curve: start, mid and end )
        /// </summary>
        /// <param name="doc">Revit document</param>
        /// <param name="elementId">Surface element Id</param>
        /// <returns>List of XYZ points on the contour</returns>
        private List <XYZ> GetSurfaceContourPoints(Document doc, ElementId elementId)
        {
            // Create point list, get list of curves from analitical model
            List <XYZ>      contour         = new List <XYZ>();
            AnalyticalModel analyticalModel = (doc.GetElement(elementId) as AnalyticalModel);
            IList <Curve>   curves          = analyticalModel.GetCurves(AnalyticalCurveType.RawCurves);

            // Iterate over curves and add mid, and end point of every curve to the point list
            foreach (Curve curve in curves)
            {
                double startParam   = curve.GetEndParameter(0),
                           endParam = curve.GetEndParameter(1);

                XYZ start = curve.Evaluate(startParam, false),
                    mid   = curve.Evaluate(0.5 * (startParam + endParam), false),
                    end   = curve.Evaluate(endParam, false);
                contour.Add(mid);
                contour.Add(end);
            }
            return(contour);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// dump each curve of this FamilyInstance's AnalyticalModel
        /// </summary>
        /// <param name="analyticalModel3D"></param>
        private void DumpAnalyticalModel3D(AnalyticalModel analyticalModel3D)
        {
            int counter = 1;

            // the 3D analytical model has a curves property that reports all the
            // analytical model curves within the in place family instance
            foreach (Curve curve in analyticalModel3D.GetCurves(AnalyticalCurveType.RawCurves))
            {
                m_message += "Curve" + counter;

                // use the tesselate method to fragment all types of curves including lines and arcs etc.
                IList <XYZ> points = curve.Tessellate();

                foreach (XYZ point in points)
                {
                    m_message += ("\n" + point.X.ToString() + "," + point.Y.ToString() + "," + point.Z.ToString());
                }

                counter += 1;
            }
        }
Ejemplo n.º 14
0
        // Получение главного направления армирования
        public static XYZ GetMajorDirection(Element e)
        {
            AnalyticalModel analyticalModel = e.GetAnalyticalModel() as AnalyticalModel;

            if (null == analyticalModel)
            {
                throw new Exception("Невозможно получить аналитическую модель перекрытия");
            }

            IList <Curve> curves = analyticalModel.GetCurves(AnalyticalCurveType
                                                             .ActiveCurves);

            XYZ direction = XYZ.BasisY;

            List <Line> lines = new List <Line>();

            foreach (Line line in curves)
            {
                if ((line.Direction.X > 0 || line.Direction.X.EqualTo(0, epsilon))
                    &&
                    (line.Direction.Y > 0 || line.Direction.Y.EqualTo(0, epsilon)))
                {
                    lines.Add(line);
                }
            }

            foreach (Line line in lines)
            {
                if (line.Direction.X.EqualTo(direction.X, epsilon) &&
                    line.Direction.Y.EqualTo(direction.Y, epsilon))
                {
                    return(direction);
                }
            }
            return(lines.First().Direction);
        }
        private void Stream(ArrayList data, AnalyticalModel aModel)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModel)));

             try {
            data.Add(new Snoop.Data.Object("GetCurve", aModel.GetCurve()));
             }
             catch (System.Exception ex){
            data.Add(new Snoop.Data.Exception("GetCurve", ex));
             }
             data.Add(new Snoop.Data.Enumerable("GetCurves", aModel.GetCurves(AnalyticalCurveType.ActiveCurves)));
             try {
            data.Add(new Snoop.Data.Xyz("GetPoint", aModel.GetPoint()));
             }
             catch (System.Exception ex){
            data.Add(new Snoop.Data.Exception("GetPoint", ex));
             }
             data.Add(new Snoop.Data.Enumerable("GetAnalyticalModelSupports", aModel.GetAnalyticalModelSupports()));

             data.Add(new Snoop.Data.Bool("CanApproximate", aModel.CanApproximate()));
             //data.Add(new Snoop.Data.Bool("CanDisable", aModel.CanDisable()));
             //data.Add(new Snoop.Data.Bool("CanDisableAutoDetect", aModel.CanDisableAutoDetect()));
             data.Add(new Snoop.Data.Bool("CanHaveRigidLinks", aModel.CanHaveRigidLinks()));
             //TF        data.Add(new Snoop.Data.Bool("CanSetAnalyticalOffset", aModel.CanSetAnalyticalOffset()));
             data.Add(new Snoop.Data.Bool("CanUseHardPoints", aModel.CanUseHardPoints()));
             data.Add(new Snoop.Data.Enumerable("Analytical Model Supports", aModel.GetAnalyticalModelSupports()));
             data.Add(new Snoop.Data.Object("Analyze As", aModel.GetAnalyzeAs()));

             try
             {
            data.Add(new Snoop.Data.Xyz("Offset EndOrTop", aModel.GetOffset(AnalyticalElementSelector.EndOrTop)));
             }
             catch (System.Exception ex)
             {
            data.Add(new Snoop.Data.Exception("Offset EndOrTop", ex));
             }

             try
             {
            data.Add(new Snoop.Data.Xyz("Offset StartOrBase", aModel.GetOffset(AnalyticalElementSelector.StartOrBase)));

             }
             catch (System.Exception ex)
             {
            data.Add(new Snoop.Data.Exception("Offset StartOrBase", ex));
             }

             try
             {
            data.Add(new Snoop.Data.Xyz("Offset Whole", aModel.GetOffset(AnalyticalElementSelector.Whole)));
             }
             catch (System.Exception ex)
             {
            data.Add(new Snoop.Data.Exception("Offset Whole", ex));
             }
            /* TF
             if (aModel.HasSweptProfile())
            data.Add(new Snoop.Data.Object("Swept profile", aModel.GetSweptProfile()));
             else
            data.Add(new Snoop.Data.String("Swept profile", "No swept profile."));
            */
             if (aModel is AnalyticalModelSurface)
            Stream(data, (AnalyticalModelSurface)aModel);
             if (aModel is AnalyticalModelStick)
            Stream(data, (AnalyticalModelStick)aModel);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// create GraphicsData of give AnalyticalModel
 /// </summary>
 /// <param name="model">AnalyticalModel contains geometry data</param>
 /// <returns>A graphics data object appropriate for GDI.</returns>
 private void GetModelData(AnalyticalModel model)
 {
     foreach (Curve curve in model.GetCurves(AnalyticalCurveType.RawCurves))
     {
         try
         {
             m_curve3Ds.Add(curve.Tessellate() as List<XYZ>);
         }
         catch
         {
         }
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// find out every wall in the selection and add a dimension from the start of the wall to its end
        /// </summary>
        /// <returns>if add successfully, true will be returned, else false will be returned</returns>
        public bool AddDimension()
        {
            if (!initialize())
            {
                return(false);
            }

            Transaction transaction = new Transaction(m_revit.Application.ActiveUIDocument.Document, "Add Dimensions");

            transaction.Start();
            //get out all the walls in this array, and create a dimension from its start to its end
            for (int i = 0; i < m_walls.Count; i++)
            {
                Wall wallTemp = m_walls[i] as Wall;
                if (null == wallTemp)
                {
                    continue;
                }

                //get location curve
                Location      location     = wallTemp.Location;
                LocationCurve locationline = location as LocationCurve;
                if (null == locationline)
                {
                    continue;
                }

                //New Line

                Line newLine = null;

                //get reference
                ReferenceArray referenceArray = new ReferenceArray();

                AnalyticalModel analyticalModel = wallTemp.GetAnalyticalModel();
                IList <Curve>   activeCurveList = analyticalModel.GetCurves(AnalyticalCurveType.ActiveCurves);
                foreach (Curve aCurve in activeCurveList)
                {
                    // find non-vertical curve from analytical model
                    if (aCurve.GetEndPoint(0).Z == aCurve.GetEndPoint(1).Z)
                    {
                        newLine = aCurve as Line;
                    }
                    if (aCurve.GetEndPoint(0).Z != aCurve.GetEndPoint(1).Z)
                    {
                        AnalyticalModelSelector amSelector = new AnalyticalModelSelector(aCurve);
                        amSelector.CurveSelector = AnalyticalCurveSelector.StartPoint;
                        referenceArray.Append(analyticalModel.GetReference(amSelector));
                    }
                    if (2 == referenceArray.Size)
                    {
                        break;
                    }
                }
                if (referenceArray.Size != 2)
                {
                    m_errorMessage += "Did not find two references";
                    return(false);
                }
                try
                {
                    //try to add new a dimension
                    Autodesk.Revit.UI.UIApplication app = m_revit.Application;
                    Document doc = app.ActiveUIDocument.Document;

                    Autodesk.Revit.DB.XYZ p1 = new XYZ(
                        newLine.GetEndPoint(0).X + 5,
                        newLine.GetEndPoint(0).Y + 5,
                        newLine.GetEndPoint(0).Z);
                    Autodesk.Revit.DB.XYZ p2 = new XYZ(
                        newLine.GetEndPoint(1).X + 5,
                        newLine.GetEndPoint(1).Y + 5,
                        newLine.GetEndPoint(1).Z);

                    Line      newLine2     = Line.CreateBound(p1, p2);
                    Dimension newDimension = doc.Create.NewDimension(
                        doc.ActiveView, newLine2, referenceArray);
                }
                // catch the exceptions
                catch (Exception ex)
                {
                    m_errorMessage += ex.ToString();
                    return(false);
                }
            }
            transaction.Commit();
            return(true);
        }
Ejemplo n.º 18
0
        Stream(ArrayList data, AnalyticalModel aModel)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModel)));

            try {
                data.Add(new Snoop.Data.Object("GetCurve", aModel.GetCurve()));
            }
            catch (System.Exception ex) {
                data.Add(new Snoop.Data.Exception("GetCurve", ex));
            }
            data.Add(new Snoop.Data.Enumerable("GetCurves", aModel.GetCurves(AnalyticalCurveType.ActiveCurves)));
            try {
                data.Add(new Snoop.Data.Xyz("GetPoint", aModel.GetPoint()));
            }
            catch (System.Exception ex) {
                data.Add(new Snoop.Data.Exception("GetPoint", ex));
            }
            data.Add(new Snoop.Data.Enumerable("GetAnalyticalModelSupports", aModel.GetAnalyticalModelSupports()));

            data.Add(new Snoop.Data.Bool("CanApproximate", aModel.CanApproximate()));
            //data.Add(new Snoop.Data.Bool("CanDisable", aModel.CanDisable()));
            //data.Add(new Snoop.Data.Bool("CanDisableAutoDetect", aModel.CanDisableAutoDetect()));
            data.Add(new Snoop.Data.Bool("CanHaveRigidLinks", aModel.CanHaveRigidLinks()));
            //TF        data.Add(new Snoop.Data.Bool("CanSetAnalyticalOffset", aModel.CanSetAnalyticalOffset()));
            data.Add(new Snoop.Data.Bool("CanUseHardPoints", aModel.CanUseHardPoints()));
            data.Add(new Snoop.Data.Enumerable("Analytical Model Supports", aModel.GetAnalyticalModelSupports()));
            data.Add(new Snoop.Data.Object("Analyze As", aModel.GetAnalyzeAs()));

            try
            {
                data.Add(new Snoop.Data.Xyz("Offset EndOrTop", aModel.GetOffset(AnalyticalElementSelector.EndOrTop)));
            }
            catch (System.Exception ex)
            {
                data.Add(new Snoop.Data.Exception("Offset EndOrTop", ex));
            }

            try
            {
                data.Add(new Snoop.Data.Xyz("Offset StartOrBase", aModel.GetOffset(AnalyticalElementSelector.StartOrBase)));
            }
            catch (System.Exception ex)
            {
                data.Add(new Snoop.Data.Exception("Offset StartOrBase", ex));
            }

            try
            {
                data.Add(new Snoop.Data.Xyz("Offset Whole", aModel.GetOffset(AnalyticalElementSelector.Whole)));
            }
            catch (System.Exception ex)
            {
                data.Add(new Snoop.Data.Exception("Offset Whole", ex));
            }

/* TF
 *       if (aModel.HasSweptProfile())
 *          data.Add(new Snoop.Data.Object("Swept profile", aModel.GetSweptProfile()));
 *       else
 *          data.Add(new Snoop.Data.String("Swept profile", "No swept profile."));
 */
            if (aModel is AnalyticalModelSurface)
            {
                Stream(data, (AnalyticalModelSurface)aModel);
            }
            if (aModel is AnalyticalModelStick)
            {
                Stream(data, (AnalyticalModelStick)aModel);
            }
        }
Ejemplo n.º 19
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            #region App Constants and instances
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;
            Selection     sel   = uidoc.Selection;
            #endregion

            IList <Reference> refs = sel.PickObjects(ObjectType.Element, "Please select an element to copy");

            foreach (Reference r in refs)
            {
                Element element = doc.GetElement(r.ElementId);

                Debug.Print(element.ToString());
                Debug.Print(element.Name);

                AnalyticalModel analytical = element.GetAnalyticalModel() as AnalyticalModel;
                if (null == analytical)
                {
                    throw new Exception("Can't get AnalyticalModel from the selected wall");
                }

                AreaReinforcement rein   = null;
                IList <Curve>     curves = analytical.GetCurves(AnalyticalCurveType.ActiveCurves);
                Line firstLine           = (Line)(curves[0]);
                XYZ  majorDirection      =
                    new XYZ(
                        firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X,
                        firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y,
                        firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z
                        );
                ElementId defaultRebarBarTypeId          = doc.GetDefaultElementTypeId(ElementTypeGroup.RebarBarType);
                ElementId defaultAreaReinforcementTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.AreaReinforcementType);
                ElementId defaultHookTypeId = ElementId.InvalidElementId;

                using (Transaction trans = new Transaction(doc))
                {
                    trans.Start("Arming..");
                    FailureHandlingOptions options       = trans.GetFailureHandlingOptions();
                    WarningSuppressor      preproccessor = new WarningSuppressor();
                    options.SetClearAfterRollback(true);
                    options.SetFailuresPreprocessor(preproccessor);
                    trans.SetFailureHandlingOptions(options);

                    rein = AreaReinforcement.Create(doc, element, curves, majorDirection, defaultAreaReinforcementTypeId, defaultRebarBarTypeId, defaultHookTypeId);
                    rein.AdditionalTopCoverOffset    = 0; // any number <--
                    rein.AdditionalBottomCoverOffset = 0; // any number -->

                    trans.SetFailureHandlingOptions(options);
                    trans.Commit();
                    var suppressor = new WarningSuppressor();
                }
            }


            return(Result.Succeeded);
        }
Ejemplo n.º 20
0
        // Получение контура армирования из аналитической модели плиты
        static IList <Curve> GetCurveArray(RebarArea rebarArea, XYZ majorDirection)
        {
            Floor floor = rebarArea.Host;

            AnalyticalModel analyticalModel = floor.GetAnalyticalModel() as AnalyticalModel;

            if (null == analyticalModel)
            {
                throw new Exception("Не удалось получить аналитическую модель");
            }

            IList <Curve> curves = analyticalModel.GetCurves(AnalyticalCurveType
                                                             .ActiveCurves);

            List <Line> lines = new List <Line>();

            foreach (Line line in curves)
            {
                if (rebarArea.Direction == Direction.TopMajor ||
                    rebarArea.Direction == Direction.BottomMajor)
                {
                    if ((line.Direction.X.EqualTo(majorDirection.X, epsilon)
                         &&
                         line.Direction.Y.EqualTo(majorDirection.Y, epsilon))
                        ||
                        (line.Direction.Negate().X.EqualTo(majorDirection.X, epsilon)
                         &&
                         line.Direction.Negate().Y.EqualTo(majorDirection.Y, epsilon)))
                    {
                        lines.Add(line);
                    }
                }

                if (rebarArea.Direction == Direction.TopMinor ||
                    rebarArea.Direction == Direction.BottomMinor)
                {
                    if ((line.Direction.X.EqualTo(majorDirection.Negate().Y, epsilon)
                         &&
                         line.Direction.Y.EqualTo(majorDirection.X, epsilon))
                        ||
                        (line.Direction.Negate().X.EqualTo(majorDirection.Negate().Y, epsilon)
                         &&
                         line.Direction.Negate().Y.EqualTo(majorDirection.X, epsilon)))
                    {
                        lines.Add(line);
                    }
                }
            }

            List <XYZ> points = new List <XYZ>();
            double     offset = (rebarArea.AlongRebarCover * mmToft) - (rebarArea.RebarBarType.BarDiameter / 2);

            foreach (Line line in lines)
            {
                points.Add(AddAlongRebarCover(line.GetEndPoint(0), line.Direction, offset));
                points.Add(AddAlongRebarCover(line.GetEndPoint(1), line.Direction, offset));
            }

            IList <Curve> newLines = new List <Curve>();
            XYZ           q        = points[points.Count - 1];

            foreach (XYZ p in points)
            {
                newLines.Add(Line.CreateBound(q, p));
                q = p;
            }
            return(newLines);
        }
Ejemplo n.º 21
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            #region App Constants and instances
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;
            Selection     sel   = uidoc.Selection;
            #endregion

            #region Core Functionality

            // Retrieve elements from database
            Reference pickedObj = sel.PickObject(ObjectType.Element, "Please select an element to copy.");
            if (pickedObj != null && pickedObj.ElementId != ElementId.InvalidElementId)
            {
                Element element = doc.GetElement(pickedObj.ElementId);
                Element wall    = element as Element;

                Debug.Print(wall.Name);

                AnalyticalModel analytical = wall.GetAnalyticalModel() as AnalyticalModel;
                if (null == analytical)
                {
                    throw new Exception("Can't get AnalyticalModel from the selected wall");
                }

                #region Path Reinforcement Implementation

                /*
                 * List<Curve> curves = new List<Curve>();
                 * LocationCurve location = wall.Location as LocationCurve;
                 * XYZ start = location.Curve.GetEndPoint(0);
                 * XYZ end = location.Curve.GetEndPoint(1);
                 * curves.Add(Line.CreateBound(start, end));
                 * ElementId defaultRebarBarTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.RebarBarType);
                 * ElementId defaultPathReinforcementTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.PathReinforcementType);
                 * ElementId defaultHookTypeId = ElementId.InvalidElementId;
                 *
                 * using (Transaction trans = new Transaction(doc))
                 * {
                 *  trans.Start("Arming..");
                 *
                 *
                 *  PathReinforcement rein = PathReinforcement.Create(doc, wall, curves, true, defaultPathReinforcementTypeId, defaultRebarBarTypeId, defaultHookTypeId, defaultHookTypeId);
                 *  rein.AdditionalOffset = 10;
                 *  Console.WriteLine(rein.Parameters);
                 *  Console.WriteLine();
                 *  Console.WriteLine(rein.ParametersMap);
                 *  Console.WriteLine();
                 *  Console.WriteLine(rein.PrimaryBarOrientation);
                 *  Console.WriteLine();
                 *  Console.WriteLine(rein.GetOrderedParameters());
                 *  Console.WriteLine();
                 *  Console.WriteLine(rein.GetSubelements());
                 *  Console.WriteLine();
                 *
                 *  trans.Commit();
                 * }
                 */
                #endregion

                #region Area Reinforcement Implementation
                /* Area Reinforce */
                AreaReinforcement rein   = null;
                IList <Curve>     curves = analytical.GetCurves(AnalyticalCurveType.ActiveCurves);
                Line firstLine           = (Line)(curves[0]);
                XYZ  majorDirection      =
                    new XYZ(
                        firstLine.GetEndPoint(1).X - firstLine.GetEndPoint(0).X,
                        firstLine.GetEndPoint(1).Y - firstLine.GetEndPoint(0).Y,
                        firstLine.GetEndPoint(1).Z - firstLine.GetEndPoint(0).Z
                        );
                ElementId defaultRebarBarTypeId          = doc.GetDefaultElementTypeId(ElementTypeGroup.RebarBarType);
                ElementId defaultAreaReinforcementTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.AreaReinforcementType);
                ElementId defaultHookTypeId = ElementId.InvalidElementId;

                using (Transaction trans = new Transaction(doc))
                {
                    trans.Start("Arming..");
                    rein = AreaReinforcement.Create(doc, wall, curves, majorDirection, defaultAreaReinforcementTypeId, defaultRebarBarTypeId, defaultHookTypeId);
                    rein.AdditionalTopCoverOffset    = 0; // any number <--
                    rein.AdditionalBottomCoverOffset = 0; // any number -->

                    trans.Commit();
                }

                /*
                 * TaskDialog td = new TaskDialog("spacing?");
                 * td.MainInstruction = "spacing!";
                 * td.CommonButtons = TaskDialogCommonButtons.Yes;
                 * td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "yes");
                 * td.Show();
                 */

                using (Transaction trans = new Transaction(doc))
                {
                    IList <Parameter> parameters = rein.GetOrderedParameters(); //14  20 26! 32!
                    var i = 0;
                    trans.Start("Spacing..");
                    foreach (Parameter p in parameters)
                    {
                        //Debug.Print(p.Definition.Name);
                        //Debug.Print(p.Definition.ParameterType.ToString());
                        // Debug.Print(i.ToString());
                        //Debug.Print("");

                        if (i == 14)
                        {
                            Debug.Print(p.Definition.Name + " will be 500.0");
                            p.SetValueString("500.0"); //»нтервал в основном направлении, наружна¤ грань
                        }


                        if (i == 20)
                        {
                            Debug.Print(p.Definition.Name + " will be 500.0");
                            p.SetValueString("500.0"); //»нтервал во второстепенном направлении, наружна¤ грань
                        }

                        if (i == 26)
                        {
                            Debug.Print(p.Definition.Name + " will be 500.0");
                            p.SetValueString("500.0"); // »нтервал в основном направлении, внутренн¤¤ грань
                        }

                        if (i == 32)
                        {
                            Debug.Print(p.Definition.Name + " will be 500.0");
                            p.SetValueString("500.0"); //»нтервал во второстепенном направлении, внутренн¤¤ грань
                        }

                        i += 1;
                    }
                    trans.Commit();
                }


                #endregion
            }
            #endregion

            #region StandartFiltering for Future

            /*
             * FilteredElementCollector col
             * = new FilteredElementCollector(doc)
             *  .WhereElementIsNotElementType()
             *  .OfCategory(BuiltInCategory.INVALID)
             *  .OfClass(typeof(Wall));
             *
             *
             * // Filtered element collector is iterable
             *
             * foreach (Element e in col)
             * {
             *  Debug.Print(e.Name);
             * }
             */
            #endregion

            return(Result.Succeeded);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            Debug.Assert(false, "This has not been tested since Revit 2010!");

            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            Autodesk.Revit.Creation.Application ca
                = app.Application.Create;

            Autodesk.Revit.Creation.Document cd
                = doc.Create;

            // determine line load symbol to use:

            FilteredElementCollector symbols
                = new FilteredElementCollector(doc);

            symbols.OfClass(typeof(LineLoadType));

            LineLoadType loadSymbol
                = symbols.FirstElement() as LineLoadType;

            // sketch plane and arrays of forces and moments:

            //Plane plane = ca.NewPlane( XYZ.BasisZ, XYZ.Zero ); // 2016
            Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero); // 2017

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Create New Line Load");

                //SketchPlane skplane = cd.NewSketchPlane( plane ); // 2013

                SketchPlane skplane = SketchPlane.Create(doc, plane); // 2014

                XYZ        forceA = new XYZ(0, 0, 5);
                XYZ        forceB = new XYZ(0, 0, 10);
                List <XYZ> forces = new List <XYZ>();
                forces.Add(forceA);
                forces.Add(forceB);

                XYZ        momentA = new XYZ(0, 0, 0);
                XYZ        momentB = new XYZ(0, 0, 0);
                List <XYZ> moments = new List <XYZ>();
                moments.Add(momentA);
                moments.Add(momentB);

                BuiltInCategory bic
                    = BuiltInCategory.OST_StructuralFraming;

                FilteredElementCollector beams = Util.GetElementsOfType(
                    doc, typeof(FamilyInstance), bic);

                XYZ p1 = new XYZ(0, 0, 0);
                XYZ p2 = new XYZ(3, 0, 0);
                //List<XYZ> points = new List<XYZ>();
                //points.Add( p1 );
                //points.Add( p2 );

                // create a new unhosted line load on points:

                //LineLoad lineLoadNoHost = cd.NewLineLoad(
                //  points, forces, moments,
                //  false, false, false,
                //  loadSymbol, skplane ); // 2015

                LineLoad lineLoadNoHost = LineLoad.Create(doc,
                                                          p1, p2, forces[0], moments[0],
                                                          loadSymbol, skplane); // 2016

                Debug.Print("Unhosted line load works.");

                // create new line loads on beam:

                foreach (Element e in beams)
                {
                    try
                    {
                        //LineLoad lineLoad = cd.NewLineLoad(
                        //  e, forces, moments,
                        //  false, false, false,
                        //  loadSymbol, skplane ); // 2015

                        AnalyticalModelSurface amsurf = e.GetAnalyticalModel()
                                                        as AnalyticalModelSurface;

                        LineLoad lineLoad = LineLoad.Create(doc,
                                                            amsurf, 0, forces[0], moments[0], loadSymbol); // 2016

                        Debug.Print("Hosted line load on beam works.");
                    }
                    catch (Exception ex)
                    {
                        Debug.Print("Hosted line load on beam fails: "
                                    + ex.Message);
                    }

                    FamilyInstance i = e as FamilyInstance;

                    AnalyticalModel am = i.GetAnalyticalModel();

                    foreach (Curve curve in
                             am.GetCurves(AnalyticalCurveType.ActiveCurves))
                    {
                        try
                        {
                            //LineLoad lineLoad = cd.NewLineLoad(
                            //  curve.Reference, forces, moments,
                            //  false, false, false,
                            //  loadSymbol, skplane ); // 2015

                            AnalyticalModelStick amstick = e.GetAnalyticalModel()
                                                           as AnalyticalModelStick;

                            LineLoad lineLoad = LineLoad.Create(doc,
                                                                amstick, forces[0], moments[0], loadSymbol); // 2016

                            Debug.Print("Hosted line load on "
                                        + "AnalyticalModelFrame curve works.");
                        }
                        catch (Exception ex)
                        {
                            Debug.Print("Hosted line load on "
                                        + "AnalyticalModelFrame curve fails: "
                                        + ex.Message);
                        }
                    }
                }
                t.Commit();
            }
            return(Result.Succeeded);
        }
      Stream(ArrayList data, AnalyticalModel aModel)
      {
         data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModel)));

         try {
            data.Add(new Snoop.Data.Object("GetCurve", aModel.GetCurve()));
         }
         catch (System.Exception ex){
            data.Add(new Snoop.Data.Exception("GetCurve", ex));
         }
         data.Add(new Snoop.Data.Enumerable("GetCurves", aModel.GetCurves(AnalyticalCurveType.ActiveCurves)));
         try {
            data.Add(new Snoop.Data.Xyz("GetPoint", aModel.GetPoint()));
         }
         catch (System.Exception ex){
            data.Add(new Snoop.Data.Exception("GetPoint", ex));
         }
         data.Add(new Snoop.Data.Enumerable("GetAnalyticalModelSupports", aModel.GetAnalyticalModelSupports()));
      }