Exemple #1
0
        /// <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.Structure.BoundaryConditions CreatePointBC(Autodesk.Revit.DB.Element hostElement)
        {
            if (!(hostElement is FamilyInstance))
            {
                return(null);
            }
            FamilyInstance    familyInstance  = hostElement as FamilyInstance;
            AnalyticalElement analyticalModel = GetAnalyticalElement(hostElement);
            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.Structure.BoundaryConditions createdBC =
                createDoc.NewPointBoundaryConditions(endReference, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            return(createdBC);
        }
Exemple #2
0
        /// <summary>
        /// Create a new Line BoundaryConditions Element.
        /// All the parameter default as Fixed.
        /// </summary>
        /// <param name="hostElement">structural element which provide the hostElementId</param>
        /// <returns>the created Point BoundaryConditions Element</returns>
        private Autodesk.Revit.DB.Structure.BoundaryConditions CreateLineBC(Autodesk.Revit.DB.Element hostElement)
        {
            Autodesk.Revit.Creation.Document createDoc = hostElement.Document.Create;
            // invoke Document.NewLineBoundaryConditions Method
            AnalyticalElement analyticalModel = GetAnalyticalElement(hostElement);

            Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
                createDoc.NewLineBoundaryConditions(analyticalModel, 0, 0, 0, 0, 0, 0, 0, 0);
            return(createdBC);
        }
Exemple #3
0
        /// <summary>
        /// get element's support information
        /// </summary>
        /// <param name="analyticalModel"> element's analytical model</param>
        /// <returns></returns>
        private string[] GetSupportInformation(AnalyticalElement analyticalModel)
        {
            // supportInformation[0] store supportType
            // supportInformation[1] store other informations
            string[] supportInformations = new string[2] {
                "", ""
            };
            // "Supported" flag indicates if the Element is completely supported.
            // AnalyticalModel Support list keeps track of all supports.
            supportInformations[0] = "not supported";

            return(supportInformations);
        }
Exemple #4
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 AnalyticalElement model)
        {
            ElementSet selected = new ElementSet();

            foreach (ElementId elementId in m_commandData.Application.ActiveUIDocument.Selection.GetElementIds())
            {
                selected.Insert(m_commandData.Application.ActiveUIDocument.Document.GetElement(elementId));
            }

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

            foreach (object o in selected)
            {
                inPlaceMember = o as FamilyInstance;
                if (null == inPlaceMember)
                {
                    return(false);
                }
            }
            Document document = inPlaceMember.Document;
            AnalyticalToPhysicalAssociationManager relManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document);

            if (relManager != null)
            {
                ElementId associatedElementId = relManager.GetAssociatedElementId(inPlaceMember.Id);
                if (associatedElementId != ElementId.InvalidElementId)
                {
                    Element associatedElement = document.GetElement(associatedElementId);
                    if (associatedElement != null && associatedElement is AnalyticalElement)
                    {
                        model = associatedElement as AnalyticalElement;
                    }
                }
            }

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

            return(true);
        }
        /// <summary>
        /// Generate appropriate graphics data object from exact analytical model type.
        /// </summary>
        /// <param name="element">The selected element maybe has analytical model lines</param>
        /// <returns>A graphics data object appropriate for GDI.</returns>
        public ModelData(Element element)
        {
            try
            {
                AnalyticalElement analyticalMode = GetAnalyticalElement(element);
                View currentView = Command.CommandData.Application.ActiveUIDocument.Document.ActiveView;
                m_bbox = element.get_BoundingBox(currentView);

                if (null == analyticalMode)
                {
                    return;
                }

                GetModelData(analyticalMode);
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// create GraphicsData of given AnalyticalModel3D
        /// </summary>
        /// <param name="model">AnalyticalModel3D contains geometry data</param>
        /// <returns></returns>
        public static GraphicsData CreateGraphicsData(AnalyticalElement model)
        {
            IList <Curve> curveList = new List <Curve>();

            if (model is AnalyticalMember)
            {
                curveList.Add(model.GetCurve());
            }
            else if (model is AnalyticalPanel)
            {
                curveList = (model as AnalyticalPanel).GetOuterContour().ToList();
            }

            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.");
            }
        }
        /// <summary>
        /// Get the analytical model object from an element.
        /// </summary>
        /// <param name="element">The selected element maybe has analytical model lines</param>
        /// <returns>Return analytical model object, or else return null.</returns>
        private AnalyticalElement GetAnalyticalElement(Element element)
        {
            Document          document          = element.Document;
            AnalyticalElement analyticalElement = null;
            AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document);

            if (assocManager != null)
            {
                ElementId associatedElementId = assocManager.GetAssociatedElementId(element.Id);
                if (associatedElementId != ElementId.InvalidElementId)
                {
                    Element associatedElement = document.GetElement(associatedElementId);
                    if (associatedElement != null && associatedElement is AnalyticalElement)
                    {
                        analyticalElement = associatedElement as AnalyticalElement;
                    }
                }
            }
            return(analyticalElement);
        }
Exemple #8
0
        AnalyticalElement GetAnalyticalElement(Autodesk.Revit.DB.Element element)
        {
            AnalyticalElement analyticalModel = null;
            Document          document        = element.Document;
            AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document);

            if (assocManager != null)
            {
                ElementId associatedElementId = assocManager.GetAssociatedElementId(element.Id);
                if (associatedElementId != ElementId.InvalidElementId)
                {
                    Element associatedElement = document.GetElement(associatedElementId);
                    if (associatedElement != null && associatedElement is AnalyticalElement)
                    {
                        analyticalModel = associatedElement as AnalyticalElement;
                    }
                }
            }
            return(analyticalModel);
        }
Exemple #9
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            m_commandData = commandData;
            Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");

            FamilyInstance inPlace = null;

            AnalyticalElement model = null;

            try
            {
                transaction.Start();
                if (!PrepareData(ref inPlace, ref model))
                {
                    message = "You should select only one in place member which have analytical model.";
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                GraphicsData       graphicsData       = GraphicsDataFactory.CreateGraphicsData(model);
                Properties         instanceProperties = new Properties(inPlace);
                InPlaceMembersForm form = new InPlaceMembersForm(instanceProperties, graphicsData);
                if (form.ShowDialog() == System.Windows.Forms.DialogResult.Abort)
                {
                    return(Autodesk.Revit.UI.Result.Failed);
                }

                return(Autodesk.Revit.UI.Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
            finally
            {
                transaction.Commit();
            }
        }
Exemple #10
0
        /// <summary>
        /// the selected element must be a structural Column/brace/Beam/Wall/Wall Foundation/Slab/Foundation Slab.
        /// </summary>
        /// <returns></returns>
        private bool IsExpectedElement(Element element)
        {
            // judge the element's type. If it is any type of FamilyInstance, Wall, Floor or
            // WallFoundation, then get judge if it has a AnalyticalModel.
            AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(element.Document);
            AnalyticalElement elemAnalytical = null;

            if (assocManager != null)
            {
                ElementId associatedElementId = assocManager.GetAssociatedElementId(element.Id);
                if (associatedElementId != ElementId.InvalidElementId)
                {
                    Element associatedElement = element.Document.GetElement(associatedElementId);
                    if (associatedElement != null && associatedElement is AnalyticalElement)
                    {
                        elemAnalytical = associatedElement as AnalyticalElement;
                    }
                }
            }
            if (null == elemAnalytical)
            {
                return(false);
            }
            FamilyInstance familyInstance = element as FamilyInstance;

            if ((null != familyInstance) && (StructuralType.Footing == familyInstance.StructuralType))
            {
                return(false); // if selected a isolated foundation not create BC
            }

            if (element is FamilyInstance || element is Wall || element is Floor || element is WallFoundation)
            {
                return(true);
            }

            return(false);
        }
 /// <summary>
 /// create GraphicsData of give AnalyticalElement
 /// </summary>
 /// <param name="model">AnalyticalElement contains geometry data</param>
 /// <returns>A graphics data object appropriate for GDI.</returns>
 private void GetModelData(AnalyticalElement model)
 {
     if (model == null)
     {
         return;
     }
     if (model is AnalyticalMember)
     {
         m_curve3Ds.Add(model.GetCurve().Tessellate() as List <XYZ>);
     }
     else if (model is AnalyticalPanel)
     {
         foreach (Curve curve in (model as AnalyticalPanel).GetOuterContour())
         {
             try
             {
                 m_curve3Ds.Add(curve.Tessellate() as List <XYZ>);
             }
             catch
             {
             }
         }
     }
 }
Exemple #12
0
        /// <summary>
        /// get all the required information of selected elements and store them in a data table
        /// </summary>
        /// <param name="selectedElements">
        /// all selected elements in Revit main program
        /// </param>
        /// <returns>
        /// a data table which store all the required information
        /// </returns>
        private DataTable StoreInformationInDataTable(ElementSet selectedElements)
        {
            DataTable informationTable = CreatDataTable();

            foreach (Element element in selectedElements)
            {
                // Get
                AnalyticalElement analyticalModel = null;
                Document          document        = element.Document;
                AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document);
                if (assocManager != null)
                {
                    ElementId associatedElementId = assocManager.GetAssociatedElementId(element.Id);
                    if (associatedElementId != ElementId.InvalidElementId)
                    {
                        Element associatedElement = document.GetElement(associatedElementId);
                        if (associatedElement != null && associatedElement is AnalyticalElement)
                        {
                            analyticalModel = associatedElement as AnalyticalElement;
                        }
                    }
                }
                if (null == analyticalModel) // skip no AnalyticalModel element
                {
                    continue;
                }

                DataRow  newRow             = informationTable.NewRow();
                string   idValue            = element.Id.ToString();                  // store element Id value
                string   typeName           = "";                                     // store element type name
                string[] supportInformation = GetSupportInformation(analyticalModel); // store support information

                // get element type information
                switch (element.GetType().Name)
                {
                case "WallFoundation":
                    WallFoundation wallFound      = element as WallFoundation;
                    ElementType    wallFootSymbol = m_revit.Application.ActiveUIDocument.Document.GetElement(wallFound.GetTypeId()) as ElementType;// get element Type
                    typeName = wallFootSymbol.Category.Name + ": " + wallFootSymbol.Name;
                    break;

                case "FamilyInstance":
                    FamilyInstance familyInstance = element as FamilyInstance;
                    FamilySymbol   symbol         = m_revit.Application.ActiveUIDocument.Document.GetElement(familyInstance.GetTypeId()) as FamilySymbol;
                    typeName = symbol.Family.Name + ": " + symbol.Name;
                    break;

                case "Floor":
                    Floor     slab     = element as Floor;
                    FloorType slabType = m_revit.Application.ActiveUIDocument.Document.GetElement(slab.GetTypeId()) as FloorType; // get element type
                    typeName = slabType.Category.Name + ": " + slabType.Name;
                    break;

                case "Wall":
                    Wall     wall     = element as Wall;
                    WallType wallType = m_revit.Application.ActiveUIDocument.Document.GetElement(wall.GetTypeId()) as WallType; // get element type
                    typeName = wallType.Kind.ToString() + ": " + wallType.Name;
                    break;

                default:
                    break;
                }

                // set the relative information of current element into the table.
                newRow["Id"]           = idValue;
                newRow["Element Type"] = typeName;
                newRow["Support Type"] = supportInformation[0];
                newRow["Remark"]       = supportInformation[1];
                informationTable.Rows.Add(newRow);
            }

            return(informationTable);
        }