Example #1
0
        /// <summary>
        /// Create the walls which along and under the path of the selected beams
        /// </summary>
        /// <param name="project"> A reference of current document</param>
        /// <returns>true if there is no error in process; otherwise, false.</returns>
        Boolean BeginCreate(Autodesk.Revit.DB.Document project)
        {
            // Begin to create walls along and under each beam
            for (int i = 0; i < m_beamCollection.Count; i++)
            {
                // Get each selected beam.
                FamilyInstance m = m_beamCollection[i] as FamilyInstance;
                if (null == m)
                {
                    m_errorInformation = "The program should not go here.";
                    return(false);
                }

                // Get the analytical model of the beam,
                // the wall will be created using this model line as path.
                AnalyticalModel model = m.GetAnalyticalModel();
                if (null == model)
                {
                    m_errorInformation = "The beam should have analytical model.";
                    return(false);
                }

                // Get the level using the beam's reference level
                Autodesk.Revit.DB.ElementId levelId = m.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).AsElementId();
                m_level = project.GetElement(levelId) as Level;
                if (null == m_level)
                {
                    m_errorInformation = "The program should not go here.";
                    return(false);
                }

                Transaction t = new Transaction(project, Guid.NewGuid().GetHashCode().ToString());
                t.Start();
                Wall createdWall = Wall.Create(project, model.GetCurve(), m_selectedWallType.Id,
                                               m_level.Id, 10, 0, true, m_isStructural);
                if (null == createdWall)
                {
                    m_errorInformation = "Can not create the walls";
                    return(false);
                }

                // Modify some parameters of the created wall to make it look better.
                Double offset = model.GetCurve().GetEndPoint(0).Z - m_level.Elevation;
                createdWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).Set(levelId);
                createdWall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).Set(offset - 3000 / 304.8);
                createdWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(levelId);
                t.Commit();
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// Get points of the truss
        /// </summary>
        /// <returns>points array stores all the points on truss</returns>
        public List <XYZ> GetTrussPoints()
        {
            List <XYZ> xyzArray = new List <XYZ>();

            try
            {
                IEnumerator iter = m_truss.Members.GetEnumerator();
                iter.Reset();
                while (iter.MoveNext())
                {
                    Autodesk.Revit.DB.ElementId id   = (Autodesk.Revit.DB.ElementId)(iter.Current);
                    Autodesk.Revit.DB.Element   elem =
                        m_commandData.Application.ActiveUIDocument.Document.GetElement(id);
                    FamilyInstance  familyInstace = (FamilyInstance)(elem);
                    AnalyticalModel frame         = familyInstace.GetAnalyticalModel();
                    Line            line          = (Line)(frame.GetCurve());
                    xyzArray.Add(line.GetEndPoint(0));
                    xyzArray.Add(line.GetEndPoint(1));
                }
            }
            catch (System.ArgumentException)
            {
                TaskDialog.Show("Revit", "The start point and the end point of the line are too close, please re-draw it.");
            }
            return(xyzArray);
        }
        /// <summary>
        /// Create a new Point BoundaryConditions Element.
        /// All the parameter default as Fixed.
        /// </summary>
        /// <param name="hostElement">
        /// structural element which provide the analytical line end reference
        /// </param>
        /// <returns> the created Point BoundaryConditions Element</returns>
        private Autodesk.Revit.DB.BoundaryConditions CreatePointBC(Autodesk.Revit.DB.Element hostElement)
        {
            if (!(hostElement is FamilyInstance))
            {
                return(null);
            }

            FamilyInstance  familyInstance  = hostElement as FamilyInstance;
            AnalyticalModel analyticalModel = familyInstance.GetAnalyticalModel();
            Reference       endReference    = null;

            Curve refCurve = analyticalModel.GetCurve();

            if (null != refCurve)
            {
                endReference = analyticalModel.GetReference(new AnalyticalModelSelector(refCurve, AnalyticalCurveSelector.EndPoint));
            }
            else
            {
                return(null);
            }

            Autodesk.Revit.Creation.Document createDoc = hostElement.Document.Create;

            // invoke Document.NewPointBoundaryConditions Method
            Autodesk.Revit.DB.BoundaryConditions createdBC =
                createDoc.NewPointBoundaryConditions(endReference, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            return(createdBC);
        }
Example #4
0
        /// <summary>
        /// create truss in Revit
        /// </summary>
        /// <returns>new created truss</returns>
        public Autodesk.Revit.DB.Structure.Truss CreateTruss()
        {
            Autodesk.Revit.DB.Document          document  = m_commandData.Application.ActiveUIDocument.Document;
            Autodesk.Revit.Creation.Document    createDoc = document.Create;
            Autodesk.Revit.Creation.Application createApp = m_commandData.Application.Application.Create;
            //sketchPlane
            Autodesk.Revit.DB.XYZ origin     = new Autodesk.Revit.DB.XYZ(0, 0, 0);
            Autodesk.Revit.DB.XYZ xDirection = new Autodesk.Revit.DB.XYZ(1, 0, 0);
            Autodesk.Revit.DB.XYZ yDirection = new Autodesk.Revit.DB.XYZ(0, 1, 0);
            Plane       plane       = Plane.CreateByOriginAndBasis(xDirection, yDirection, origin);
            SketchPlane sketchPlane = SketchPlane.Create(document, plane);
            //new base Line
            AnalyticalModel frame1 = column1.GetAnalyticalModel();

            Autodesk.Revit.DB.XYZ centerPoint1 = (frame1.GetCurve() as Line).GetEndPoint(0);
            AnalyticalModel       frame2       = column2.GetAnalyticalModel();

            Autodesk.Revit.DB.XYZ  centerPoint2 = (frame2.GetCurve() as Line).GetEndPoint(0);
            Autodesk.Revit.DB.XYZ  startPoint   = new Autodesk.Revit.DB.XYZ(centerPoint1.X, centerPoint1.Y, 0);
            Autodesk.Revit.DB.XYZ  endPoint     = new Autodesk.Revit.DB.XYZ(centerPoint2.X, centerPoint2.Y, 0);
            Autodesk.Revit.DB.Line baseLine     = null;

            try
            { baseLine = Line.CreateBound(startPoint, endPoint); }
            catch (System.ArgumentException)
            {
                TaskDialog.Show("Argument Exception", "Two column you selected are too close to create truss.");
            }

            return(Autodesk.Revit.DB.Structure.Truss.Create(document, m_selectedTrussType.Id, sketchPlane.Id, baseLine));
        }
Example #5
0
        /// <summary>
        /// create truss in Revit
        /// </summary>
        /// <returns>new created truss</returns>
        public Autodesk.Revit.DB.Structure.Truss CreateTruss()
        {
            Autodesk.Revit.Creation.Document    createDoc = m_commandData.Application.ActiveUIDocument.Document.Create;
            Autodesk.Revit.Creation.Application createApp = m_commandData.Application.Application.Create;
            //sketchPlane
            Autodesk.Revit.DB.XYZ origin     = new Autodesk.Revit.DB.XYZ(0, 0, 0);
            Autodesk.Revit.DB.XYZ xDirection = new Autodesk.Revit.DB.XYZ(1, 0, 0);
            Autodesk.Revit.DB.XYZ yDirection = new Autodesk.Revit.DB.XYZ(0, 1, 0);
            Plane       plane       = createApp.NewPlane(xDirection, yDirection, origin);
            SketchPlane sketchPlane = createDoc.NewSketchPlane(plane);
            //new base Line
            AnalyticalModel frame1 = column1.GetAnalyticalModel();

            Autodesk.Revit.DB.XYZ centerPoint1 = (frame1.GetCurve() as Line).get_EndPoint(0);
            AnalyticalModel       frame2       = column2.GetAnalyticalModel();

            Autodesk.Revit.DB.XYZ  centerPoint2 = (frame2.GetCurve() as Line).get_EndPoint(0);
            Autodesk.Revit.DB.XYZ  startPoint   = new Autodesk.Revit.DB.XYZ(centerPoint1.X, centerPoint1.Y, 0);
            Autodesk.Revit.DB.XYZ  endPoint     = new Autodesk.Revit.DB.XYZ(centerPoint2.X, centerPoint2.Y, 0);
            Autodesk.Revit.DB.Line baseLine     = null;

            try
            { baseLine = createApp.NewLineBound(startPoint, endPoint); }
            catch (System.ArgumentException)
            { MessageBox.Show("Two column you selected are too close to create truss."); }

            return(createDoc.NewTruss(m_selectedTrussType, sketchPlane, baseLine));
        }
Example #6
0
 /// <summary>
 /// Check whether all the beams have horizontal analytical line
 /// </summary>
 /// <returns>true if each beam has horizontal analytical line; otherwise, false.</returns>
 Boolean CheckBeamHorizontal()
 {
     for (int i = 0; i < m_beamCollection.Count; i++)
     {
         // Get the analytical curve of each selected beam.
         // And check if Z coordinate of start point and end point of the curve are same.
         FamilyInstance  m     = m_beamCollection[i] as FamilyInstance;
         AnalyticalModel model = m.GetAnalyticalModel();
         if (null == model)
         {
             m_errorInformation = "The beam should have analytical model.";
             return(false);
         }
         else if ((PRECISION <= model.GetCurve().GetEndPoint(0).Z - model.GetCurve().GetEndPoint(1).Z) ||
                  (-PRECISION >= model.GetCurve().GetEndPoint(0).Z - model.GetCurve().GetEndPoint(1).Z))
         {
             m_errorInformation = "Please only select horizontal beams.";
             return(false);
         }
     }
     return(true);
 }
Example #7
0
        /// <summary>
        /// Generate a Transform instance which as Transform property of BoundingBoxXYZ,
        /// when the user select a beam, this method will be called
        /// </summary>
        /// <returns>the reference of Transform, return null if it can't be generated</returns>
        Transform GenerateBeamTransform()
        {
            Transform      transform = null;
            FamilyInstance instance  = m_currentComponent as FamilyInstance;

            // First check whether the beam is horizontal.
            // In order to predigest the calculation, only allow it to be horizontal
            double startOffset = instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).AsDouble();
            double endOffset   = instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).AsDouble();

            if (-PRECISION > startOffset - endOffset || PRECISION < startOffset - endOffset)
            {
                m_errorInformation = "Please select a horizontal beam.";
                return(transform);
            }

            // Second get the Analytical Model line.
            AnalyticalModel model = instance.GetAnalyticalModel();

            if (null == model)
            {
                m_errorInformation = "The selected beam doesn't have Analytical Model line.";
                return(transform);
            }
            Curve curve = model.GetCurve();

            if (null == curve)
            {
                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 line and set it as Origin property.
            Autodesk.Revit.DB.XYZ startPoint = curve.GetEndPoint(0);
            Autodesk.Revit.DB.XYZ endPoint   = curve.GetEndPoint(1);
            Autodesk.Revit.DB.XYZ midPoint   = XYZMath.FindMidPoint(startPoint, endPoint);
            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.FindDirection(startPoint, endPoint);
            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);
        }
        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()));
        }
        public void Get_BeamSymbols(Document doc)
        {
            ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
            // Category filter
            ElementCategoryFilter FramingCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
            // Instance filter
            LogicalAndFilter FramingInstancesFilter = new LogicalAndFilter(familyInstanceFilter, FramingCategoryfilter);

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            // Colletion Array of Elements
            ICollection <Element> FramingElements = collector.WherePasses(FramingInstancesFilter).ToElements();

            foreach (Element e in FramingElements)
            {
                FamilyInstance familyInstance = e as FamilyInstance;

                if (null != familyInstance && familyInstance.StructuralType == StructuralType.Beam)
                {
                    Element         element         = e;
                    AnalyticalModel analyticalModel = familyInstance.GetAnalyticalModel();
                    Curve           analyticalCurve = analyticalModel.GetCurve();
                    XYZ             pointStart      = analyticalCurve.GetEndPoint(0);
                    XYZ             pointEnd        = analyticalCurve.GetEndPoint(1);
                    Family          family          = familyInstance.Symbol.Family;

                    //Create Revit Object and Set Methods
                    RevitObject revitObject = new RevitObject();
                    revitObject.Set_Element(element);
                    revitObject.Set_AnalyticalModel(analyticalModel);
                    revitObject.Set_PointStart(pointStart);
                    revitObject.Set_PointEnd(pointEnd);
                    revitObject.Set_RevitFamily(family);
                    revitObject.Set_FamilyInstance(familyInstance);
                    _RevitFramingList.Add(revitObject);
                }
            }
        }
        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);
        }
Example #11
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);
            }
        }
      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()));
      }