Example #1
0
        Stream(ArrayList data, ElectricalSetting elecSetting)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(ElectricalSetting)));

            data.Add(new Snoop.Data.Enumerable("Conduit types", elecSetting.WireConduitTypes));
            data.Add(new Snoop.Data.Enumerable("Distribution system types", elecSetting.DistributionSysTypes));
            data.Add(new Snoop.Data.Enumerable("Voltage types", elecSetting.VoltageTypes));
            data.Add(new Snoop.Data.Enumerable("Wire material types", elecSetting.WireMaterialTypes));
            data.Add(new Snoop.Data.Enumerable("Wire types", elecSetting.WireTypes));

            data.Add(new Snoop.Data.CategorySeparator("Demand Factors"));
        }
        Stream(ArrayList data, ElectricalSetting elecSetting)
      {
         data.Add(new Snoop.Data.ClassSeparator(typeof(ElectricalSetting)));

         data.Add(new Snoop.Data.Enumerable("Conduit types", elecSetting.WireConduitTypes));
         data.Add(new Snoop.Data.Enumerable("Distribution system types", elecSetting.DistributionSysTypes));
         data.Add(new Snoop.Data.Enumerable("Voltage types", elecSetting.VoltageTypes));
         data.Add(new Snoop.Data.Enumerable("Wire material types", elecSetting.WireMaterialTypes));
         data.Add(new Snoop.Data.Enumerable("Wire types", elecSetting.WireTypes));

         data.Add(new Snoop.Data.CategorySeparator("Demand Factors"));
      }
Example #3
0
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false); // why did someone else send us the message?
                return;
            }


            // see if it is a type we are responsible for
            Connector connector = e.ObjToSnoop as Connector;

            if (connector != null)
            {
                Utils.StreamWithReflection(snoopCollector.Data(), typeof(Connector), connector);
                return;
            }

            ConnectorManager connectorMgr = e.ObjToSnoop as ConnectorManager;

            if (connectorMgr != null)
            {
                Stream(snoopCollector.Data(), connectorMgr);
                return;
            }

            CorrectionFactor correctionFactor = e.ObjToSnoop as CorrectionFactor;

            if (correctionFactor != null)
            {
                Stream(snoopCollector.Data(), correctionFactor);
                return;
            }

            ElectricalSetting elecSetting = e.ObjToSnoop as ElectricalSetting;

            if (elecSetting != null)
            {
                Stream(snoopCollector.Data(), elecSetting);
                return;
            }

            GroundConductorSize groundConductorSize = e.ObjToSnoop as GroundConductorSize;

            if (groundConductorSize != null)
            {
                Stream(snoopCollector.Data(), groundConductorSize);
                return;
            }

            MEPModel mepModel = e.ObjToSnoop as MEPModel;

            if (mepModel != null)
            {
                Stream(snoopCollector.Data(), mepModel);
                return;
            }

            WireSize wireSize = e.ObjToSnoop as WireSize;

            if (wireSize != null)
            {
                Stream(snoopCollector.Data(), wireSize);
                return;
            }
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            #region Clear the existing system.
            TaskDialogResult r = TaskDialog.Show("Note",
                                                 "This will clear the existing " +
                                                 "electrical system.Continue?",
                                                 TaskDialogCommonButtons.Yes |
                                                 TaskDialogCommonButtons.No);
            if (r == TaskDialogResult.No)
            {
                return(Result.Failed);
            }
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Clear existing system.");
                FilteredElementCollector col =
                    new FilteredElementCollector(doc)
                    .WhereElementIsNotElementType()
                    .OfCategory(BuiltInCategory.OST_ElectricalCircuit);
                Stack <ElementId> sysId = new Stack <ElementId>();
                foreach (Element e in col)
                {
                    sysId.Push(e.Id);
                }
                while (sysId.Count > 0)
                {
                    doc.Delete(sysId.Pop());
                }
                tx.Commit();
            }
            #endregion

            #region Check the default settings.
            const string elecSettingName =
                "DefaultElectricalSettingExcuted";
            GlobalParameter SettingP = doc.GetElement(
                GlobalParametersManager.FindByName
                    (doc, elecSettingName)) as GlobalParameter;
            if (SettingP == null)
            {
                //Set the voltage and distribution to default
                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Autoset electrical setting");
                    ElectricalSetting ElecSet = ElectricalSetting
                                                .GetElectricalSettings(doc);
                    VoltageType VtypeHome = ElecSet
                                            .AddVoltageType("Home", 220, 200, 250);
                    ElecSet.AddDistributionSysType
                        ("Lighting", ElectricalPhase.SinglePhase,
                        ElectricalPhaseConfiguration.Undefined,
                        2, null, VtypeHome);
                    ElecSet.AddDistributionSysType
                        ("Outlet", ElectricalPhase.SinglePhase,
                        ElectricalPhaseConfiguration.Undefined,
                        2, null, VtypeHome);
                    GlobalParameter.Create
                        (doc, elecSettingName, ParameterType.Number);
                    tx.Commit();
                }
            }
            #endregion

            #region Retrieve elements from database
            List <ElementId> LightIds  = new List <ElementId>();
            List <ElementId> OutletIds = new List <ElementId>();
            List <ElementId> HVACIds   = new List <ElementId>();

            FilteredElementCollector colLight
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_LightingFixtures)
                  .WhereElementIsNotElementType();
            FilteredElementCollector colOutlet
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_ElectricalFixtures)
                  .WhereElementIsNotElementType();
            FilteredElementCollector colHVAC
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_MechanicalEquipment)
                  .WhereElementIsNotElementType();

            foreach (Element e in colLight)
            {
                LightIds.Add(e.Id);
            }
            foreach (Element e in colOutlet)
            {
                OutletIds.Add(e.Id);
            }
            foreach (Element e in colHVAC)
            {
                if (HasElectricalConnector(e))
                {
                    HVACIds.Add(e.Id);
                }
            }

            #endregion Retrieve elements from databa

            //Locate the electrical main box.
            FamilyInstance ElecBox = null;
            do
            {
                try
                {
                    Selection sel = uidoc.Selection;
                    TaskDialog.Show("Choose", "Please " +
                                    "select one electrical box after " +
                                    "closing the dialog.\n" +
                                    "请在关闭窗口后选择一个配电箱。");
                    ElementId ElecBoxId = sel.PickObject
                                              (ObjectType.Element, new SelFilterElecEquip()
                                              , "Select the main box").ElementId;
                    ElecBox = doc.GetElement(ElecBoxId)
                              as FamilyInstance;
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("Error", "Something went wrong.\n"
                                    + ex.Message);
                    return(Result.Failed);
                }
            } while ((ElecBox.MEPModel as ElectricalEquipment)
                     .DistributionSystem == null);



            // Create the electrical system
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create ElectricalSystem");
                ElectricalSystem LightingCircuit =
                    ElectricalSystem.Create(doc, LightIds,
                                            ElectricalSystemType.PowerCircuit);
                LightingCircuit.Name = "LightingCircuit";
                LightingCircuit.SelectPanel(ElecBox);
                ElectricalSystem OutlietCircuit =
                    ElectricalSystem.Create(doc, OutletIds,
                                            ElectricalSystemType.PowerCircuit);
                OutlietCircuit.Name = "OutletCircuit";
                OutlietCircuit.SelectPanel(ElecBox);
                ElectricalSystem HVACCircuit =
                    ElectricalSystem.Create(doc, HVACIds,
                                            ElectricalSystemType.PowerCircuit);
                HVACCircuit.Name = "HVACCircuit";
                HVACCircuit.SelectPanel(ElecBox);
                tx.Commit();
            }
            TaskDialog.Show("Result",
                            "Default systems have been created.\n" +
                            "Please do not change system name.\n" +
                            "已创建默认系统,请勿修改系统名,将影响后续计算\n" +
                            "可手动调整系统内末端.");

            return(Result.Succeeded);
        }