Пример #1
0
        /// <summary>
        /// Get all the parameters and store them into a list
        /// </summary>
        /// <param name="familyInstance">The instance of a curtain panel</param>
        /// <returns>A list containing all the required parameters</returns>
        private InstParameters GetParams(FamilyInstance familyInstance)
        {
            InstParameters iParams = new InstParameters();
            Parameter      L1      = familyInstance.LookupParameter("Length1");
            Parameter      L2      = familyInstance.LookupParameter("Length2");
            Parameter      L3      = familyInstance.LookupParameter("Length3");
            Parameter      L4      = familyInstance.LookupParameter("Length4");
            Parameter      A1      = familyInstance.LookupParameter("Angle1");
            Parameter      A2      = familyInstance.LookupParameter("Angle2");
            Parameter      A3      = familyInstance.LookupParameter("Angle3");
            Parameter      A4      = familyInstance.LookupParameter("Angle4");

            if (L1 == null || L2 == null || L3 == null || L4 == null || A1 == null || A2 == null || A3 == null || A4 == null)
            {
                string errorstring = "Panel family: " + familyInstance.Id.IntegerValue + " '" + familyInstance.Symbol.Family.Name + "' must have instance parameters Length1, Length2, Length3, Length4, Angle1, Angle2, Angle3, and Angle4";
                TaskDialog.Show("Revit", errorstring);
                //   throw new ArgumentException(errorstring);
            }

            iParams["Length1"] = L1;
            iParams["Length2"] = L2;
            iParams["Length3"] = L3;
            iParams["Length4"] = L4;
            iParams["Angle1"]  = A1;
            iParams["Angle2"]  = A2;
            iParams["Angle3"]  = A3;
            iParams["Angle4"]  = A4;

            return(iParams);
        }
Пример #2
0
        /// <summary>
        /// Compute the length and angle data of the edges, then update the parameters with these values
        /// </summary>
        /// <param name="edge_ar">The edges of the curtain panel</param>
        /// <param name="instParams">The parameters which records the length and angle data</param>
        private void SetParams(EdgeArray edge_ar, InstParameters instParams)
        {
            double length4 = 0d;
            double angle3  = 0d;
            double angle4  = 0d;
            Edge   edge1   = edge_ar.get_Item(0);
            Edge   edge2   = edge_ar.get_Item(1);
            Edge   edge3   = edge_ar.get_Item(2);
            double length1 = edge1.ApproximateLength;
            double length2 = edge2.ApproximateLength;
            double length3 = edge3.ApproximateLength;
            double angle1  = AngleBetweenEdges(edge1, edge2);
            double angle2  = AngleBetweenEdges(edge2, edge3);

            if (edge_ar.Size == 3)
            {
                angle3 = AngleBetweenEdges(edge3, edge1);
            }
            else if (edge_ar.Size > 3)
            {
                Edge edge4 = edge_ar.get_Item(3);
                length4 = edge4.ApproximateLength;
                angle3  = AngleBetweenEdges(edge3, edge4);
                angle4  = AngleBetweenEdges(edge4, edge1);
            }

            instParams["Length1"].Set(length1);
            instParams["Length2"].Set(length2);
            instParams["Length3"].Set(length3);
            instParams["Length4"].Set(length4);
            instParams["Angle1"].Set(angle1);
            instParams["Angle2"].Set(angle2);
            instParams["Angle3"].Set(angle3);
            instParams["Angle4"].Set(angle4);
        }
Пример #3
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_app = commandData.Application.Application;
            m_doc = commandData.Application.ActiveUIDocument.Document;

            // step 1: get all the divided surfaces in the Revit document
            List <DividedSurface> dsList = GetElements <DividedSurface>();

            foreach (DividedSurface ds in dsList)
            {
                // step 2: get the panel instances from the divided surface
                List <FamilyInstance> fiList = GetFamilyInstances(ds);
                foreach (FamilyInstance inst in fiList)
                {
                    // step 3: compute the length and angle and set them to the parameters
                    InstParameters instParams = GetParams(inst);
                    EdgeArray      edges      = GetEdges(inst);
                    SetParams(edges, instParams);
                }
            }
            return(Autodesk.Revit.UI.Result.Succeeded);
        }