Example #1
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);
 }
        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);
                }
            }
        }
        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);
        }
Example #4
0
        private void CreateSpotElevation(FamilyInstance familyInstance)
        {
            //get the location curve of the family instance
            LocationCurve location = familyInstance.Location as LocationCurve;

            //instantiate a curve
            Curve curve = null;

            //check for location null
            if (location != null)
            {
                //get the curve from the location
                curve = location.Curve;
            }

            else if (familyInstance.Category.Name.Equals("Structural Columns"))
            //structural columns do not have location curve, but analytical model does
            {
                curve = familyInstance.GetAnalyticalModel().GetCurve();
            }

            if (curve != null)
            {
                //get the end points and mid point from the curve
                XYZ startPoint = curve.GetEndPoint(0);
                XYZ endPoint   = curve.GetEndPoint(1);
                XYZ midPoint   = curve.Evaluate(0.5, true);

                //set the default point on the element to tag
                XYZ pointOnElementToTag = startPoint;

                TaskDialog td = new TaskDialog("Select Point to Tag");
                td.MainInstruction = "Select the point on the curve to tag";
                td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Start Point");
                td.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "End Point");
                td.AddCommandLink(TaskDialogCommandLinkId.CommandLink3, "Mid Point");
                td.CommonButtons = TaskDialogCommonButtons.Cancel;
                td.DefaultButton = TaskDialogResult.Cancel;
                TaskDialogResult result = td.Show();

                if (result == TaskDialogResult.CommandLink1)
                {
                    pointOnElementToTag = startPoint;
                }
                else if (result == TaskDialogResult.CommandLink2)
                {
                    pointOnElementToTag = endPoint;
                }
                else if (result == TaskDialogResult.CommandLink3)
                {
                    pointOnElementToTag = midPoint;
                }
                else
                {
                    TaskDialog.Show("Canceled", "The action was canceled by the user");
                    return;
                }

                //instantiate a transaction to add the individual tag
                using (Transaction trans = new Transaction(_doc, "Add Spot Elevation"))
                {
                    trans.Start();

                    try
                    {
                        //get the top reference for the spot elevation
                        Reference spotReference = FindTopMostReference(familyInstance);

                        //set the bend and endpoints for the new spot elevation
                        XYZ seBendPoint = pointOnElementToTag.Add(new XYZ(0, 1, 4));
                        XYZ seEndPoint  = pointOnElementToTag.Add(new XYZ(0, 2, 4));

                        //add the spot elevation
                        SpotDimension sd = _docCreator.NewSpotElevation(_uiDoc.ActiveView, spotReference, pointOnElementToTag, seBendPoint, seEndPoint, pointOnElementToTag, true);

                        trans.Commit();

                        //TaskDialog.Show("Success", "The Spot elevation was added successfully");
                    }
                    catch (Exception ex)
                    {
                        TaskDialog.Show("Error", "The following error occurred: " + ex.Message);
                        trans.RollBack();
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="element">the host object, must be family instance</param>
        /// <param name="geoOptions">the geometry option</param>
        public GeometrySupport(FamilyInstance element, Options geoOptions)
        {
            // get the geometry element of the selected element
            Autodesk.Revit.DB.GeometryElement geoElement = element.get_Geometry(new Options());
            if (null == geoElement || 0 == geoElement.Objects.Size)
            {
                throw new Exception("Can't get the geometry of selected element.");
            }

            AnalyticalModel aModel = element.GetAnalyticalModel();
            if (aModel == null)
            {
                throw new Exception("The selected FamilyInstance don't have AnalyticalModel.");
            }

            AnalyticalModelSweptProfile swProfile = aModel.GetSweptProfile();
            if (swProfile == null || !(swProfile.GetDrivingCurve() is Line))
            {
                throw new Exception("The selected element driving curve is not a line.");
            }

            // get the driving path and vector of the beam or column
            Line line = swProfile.GetDrivingCurve() as Line;
            if (null != line)
            {
                m_drivingLine = line;   // driving path
                m_drivingVector = GeomUtil.SubXYZ(line.get_EndPoint(1), line.get_EndPoint(0));
            }

            //get the geometry object
            foreach (GeometryObject geoObject in geoElement.Objects)
            {
                //get the geometry instance which contain the geometry information
                GeoInstance instance = geoObject as GeoInstance;
                if (null != instance)
                {
                    foreach (GeometryObject o in instance.SymbolGeometry.Objects)
                    {
                        // get the solid of beam of column
                        Solid solid = o as Solid;

                        // do some checks.
                        if (null == solid)
                        {
                            continue;
                        }
                        if (0 == solid.Faces.Size || 0 == solid.Edges.Size)
                        {
                            continue;
                        }

                        m_solid = solid;
                        //get the transform value of instance
                        m_transform = instance.Transform;

                        // Get the swept profile curves information
                        if (!GetSweptProfile(solid))
                        {
                            throw new Exception("Can't get the swept profile curves.");
                        }
                        break;
                    }
                }

            }

            // do some checks about profile curves information
            if (null == m_edges)
            {
                throw new Exception("Can't get the geometry edge information.");
            }
            if (4 != m_points.Count)
            {
                throw new Exception("The sample only work for rectangular beams or columns.");
            }
        }
Example #6
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="element">The host object, must be family instance</param>
        public GeometrySupport(FamilyInstance element)
        {
            // get the geometry element of the selected element
            Autodesk.Revit.DB.GeometryElement geoElement = element.get_Geometry(new Options());
            if (null == geoElement || 0 == geoElement.Objects.Size)
            {
                throw new Exception("Can't get the geometry of selected element.");
            }

            AnalyticalModel aModel = element.GetAnalyticalModel();

            if (aModel == null)
            {
                throw new Exception("The selected FamilyInstance don't have AnalyticalModel.");
            }

            AnalyticalModelSweptProfile swProfile = aModel.GetSweptProfile();

            if (swProfile == null || !(swProfile.GetDrivingCurve() is Line))
            {
                throw new Exception("The selected element driving curve is not a line.");
            }

            // get the driving path and vector of the beam or column
            Line line = swProfile.GetDrivingCurve() as Line;

            if (null != line)
            {
                m_drivingLine   = line; // driving path
                m_drivingVector = GeomUtil.SubXYZ(line.get_EndPoint(1), line.get_EndPoint(0));
                m_drivingLength = m_drivingVector.GetLength();
            }

            //get the geometry object
            foreach (GeometryObject geoObject in geoElement.Objects)
            {
                //get the geometry instance which contains the geometry information
                GeoInstance instance = geoObject as GeoInstance;
                if (null != instance)
                {
                    foreach (GeometryObject o in instance.SymbolGeometry.Objects)
                    {
                        // get the solid of beam of column
                        Solid solid = o as Solid;

                        // do some checks.
                        if (null == solid)
                        {
                            continue;
                        }
                        if (0 == solid.Faces.Size || 0 == solid.Edges.Size)
                        {
                            continue;
                        }

                        m_solid = solid;
                        //get the transform value of instance
                        m_transform = instance.Transform;

                        // Get the swept profile curves information
                        if (!GetSweptProfile(solid))
                        {
                            throw new Exception("Can't get the swept profile curves.");
                        }
                        break;
                    }
                }
            }

            // do some checks about profile curves information
            if (null == m_edges)
            {
                throw new Exception("Can't get the geometry edge information.");
            }
            if (4 != m_points.Count)
            {
                throw new Exception("The sample only works for rectangle beam or column.");
            }
        }
Example #7
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static List <Bar> BarsFromRevit(this FamilyInstance familyInstance, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            List <Bar> bars = refObjects.GetValues <Bar>(familyInstance.Id);

            if (bars != null)
            {
                return(bars);
            }

            // Get bar curve
            oM.Geometry.ICurve   locationCurve   = null;
            AnalyticalModelStick analyticalModel = familyInstance.GetAnalyticalModel() as AnalyticalModelStick;

            if (analyticalModel != null)
            {
                Curve curve = analyticalModel.GetCurve();
                if (curve != null)
                {
                    locationCurve = curve.IFromRevit();
                }
            }

            if (locationCurve != null)
            {
                familyInstance.AnalyticalPullWarning();
            }
            else
            {
                locationCurve = familyInstance.LocationCurve(settings);
            }

            // Get bar material
            ElementId structuralMaterialId = familyInstance.StructuralMaterialId;

            if (structuralMaterialId.IntegerValue < 0)
            {
                structuralMaterialId = familyInstance.Symbol.LookupParameterElementId(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
            }

            Material revitMaterial = familyInstance.Document.GetElement(structuralMaterialId) as Material;

            if (revitMaterial == null)
            {
                revitMaterial = familyInstance.Category.Material;
            }

            // Get material grade
            string materialGrade = familyInstance.MaterialGrade(settings);

            // Find material fragment: convert the material assigned to the element, if that returns null try finding a material in the library, based on the material type assigned to the family.
            IMaterialFragment materialFragment = revitMaterial.MaterialFragmentFromRevit(materialGrade, settings, refObjects);

            if (materialFragment == null)
            {
                materialFragment = familyInstance.StructuralMaterialType.LibraryMaterial(materialGrade);
            }

            // If material fragment could not be found create an empty one and raise a warning further down the line.
            bool materialFound = materialFragment != null;

            if (materialFragment == null)
            {
                materialFragment = familyInstance.StructuralMaterialType.EmptyMaterialFragment(materialGrade);
            }

            // Get bar profile and create property
            string           profileName = familyInstance.Symbol.Name;
            ISectionProperty property    = BH.Engine.Library.Query.Match("SectionProperties", profileName) as ISectionProperty;

            if (property == null)
            {
                IProfile profile = familyInstance.Symbol.ProfileFromRevit(settings, refObjects);

                //TODO: this should be removed and null passed finally?
                if (profile == null)
                {
                    profile = new FreeFormProfile(new List <oM.Geometry.ICurve>());
                }

                if (profile.Edges.Count == 0)
                {
                    familyInstance.Symbol.ConvertProfileFailedWarning();
                }

                if (!materialFound)
                {
                    Compute.InvalidDataMaterialWarning(familyInstance);
                }

                property = BH.Engine.Structure.Create.SectionPropertyFromProfile(profile, materialFragment, profileName);
            }
            else
            {
                property = property.ShallowClone();

                if (!materialFound)
                {
                    BH.Engine.Reflection.Compute.RecordNote($"A matching section was found in the library. No valid material was defined in Revit, so the default material for this section was used. Revit ElementId: {familyInstance.Id.IntegerValue}");
                }
                else
                {
                    property.Material = materialFragment;
                }

                property.Name = profileName;
            }

            // Create linear bars
            bars = new List <Bar>();
            if (locationCurve != null)
            {
                //TODO: check category of familyInstance to recognize which rotation query to use
                double rotation = familyInstance.OrientationAngle(settings);
                foreach (BH.oM.Geometry.Line line in locationCurve.ICollapseToPolyline(Math.PI / 12).SubParts())
                {
                    bars.Add(BH.Engine.Structure.Create.Bar(line, property, rotation));
                }
            }
            else
            {
                bars.Add(BH.Engine.Structure.Create.Bar(null, null, property, 0));
            }

            for (int i = 0; i < bars.Count; i++)
            {
                bars[i].Name = familyInstance.Name;

                //Set identifiers, parameters & custom data
                bars[i].SetIdentifiers(familyInstance);
                bars[i].CopyParameters(familyInstance, settings.ParameterSettings);
                bars[i].SetProperties(familyInstance, settings.ParameterSettings);
            }

            refObjects.AddOrReplace(familyInstance.Id, bars);
            return(bars);
        }
Example #8
0
        /// <summary>
        /// Search for the In-Place family instance's properties data to be listed
        /// and graphics data to be drawn.
        /// </summary>
        /// <param name="inPlaceMember">properties data to be listed</param>
        /// <param name="model">graphics data to be draw</param>
        /// <returns>Returns true if retrieved this data</returns>
        private bool PrepareData(ref FamilyInstance inPlaceMember, ref AnalyticalModel model)
        {
            ElementSet selected = m_commandData.Application.ActiveUIDocument.Selection.Elements;

            if (selected.Size != 1)
            {
                return false;
            }

            foreach (object o in selected)
            {
                inPlaceMember = o as FamilyInstance;
                if (null == inPlaceMember)
                {
                    return false;
                }
            }

            model = inPlaceMember.GetAnalyticalModel();

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

            return true;
        }