Ejemplo n.º 1
0
        /// <summary>
        ///     Creates a new CurtainSystem with transaction.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="curtainParm"></param>
        /// <param name="instParm"></param>
        /// <param name="normal"></param>
        /// <returns></returns>
        public static CurtainSystem CreateCurtainSystem(this Document doc, CurtainParm curtainParm, InstParm instParm, XYZ normal)
        {
            if (doc is null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (curtainParm is null)
            {
                throw new NullReferenceException(nameof(curtainParm));
            }

            if (instParm is null)
            {
                throw new NullReferenceException(nameof(instParm));
            }

            if (normal is null)
            {
                throw new NullReferenceException(nameof(normal));
            }

            return(doc.AutoTransaction(() =>
            {
                var inst = doc.CreateFamilyInstance(instParm);

                doc.Regenerate();

                // The instance has thickness.
                var faces = inst.GetFaceList(-normal).ToFaceArray();

                var result = doc.CreateCurtainSystem(curtainParm.TypeName, faces);

                doc.Delete(inst.Id);

                doc.Delete(instParm.Symbol.Family.Id);

                var pnlTypeId = result.CurtainSystemType.get_Parameter(AUTO_PANEL).AsElementId();

                if (!(doc.GetElement(pnlTypeId) is PanelType pnlType))
                {
                    return result;
                }

                var thickness = pnlType.get_Parameter(CURTAIN_WALL_SYSPANEL_THICKNESS).AsDouble();

                ElementTransformUtils.MoveElement(doc, result.Id, normal * thickness / 2);

                return result;
            }));
        }