Exemplo n.º 1
0
        private void CheckThisFamilyPairing(Autodesk.Revit.DB.Document doc, Type targetType, string familyTagName, string familyTagSymbName, BuiltInCategory bic)
        {
            Element ConfirmTag = FamilyUtils.FindFamilyType(doc, targetType, familyTagName, familyTagSymbName, bic);

            if (ConfirmTag == null)
            {
                FamilyUtils.SayMsg("Road Closed", "Unable to resolve loading family " + familyTagName +
                                   " that has a type " + familyTagSymbName +
                                   "Maybe the tool settings are not correct.");
            }
        }
Exemplo n.º 2
0
        public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document;

            PlunkOClass plunkThis        = new PlunkOClass(commandData.Application);
            string      wsName           = "ELEC LIGHTING DIAGNOSTIC";
            string      FamilyName       = "OCC-SENSOR-DETECTION-CMR09";
            string      FamilySymbolName = "DET BLADES ALL";
            string      pNameOccHeight   = "HEIGHT_ABOVE_FLOOR";

            bool            oneShot   = true;
            BuiltInCategory bicFamily = BuiltInCategory.OST_LightingDevices;

            if (plunkThis.NotInThisView())
            {
                return(Result.Succeeded);
            }

            CheckThisFamilyPairing(doc, typeof(FamilySymbol), FamilyName, FamilySymbolName, bicFamily);

            Element elemPlunked = null;
            double  optOffset   = plunkThis.GetCeilingHeight("OCC Sensor Tool Plunk");
            Double  pOffSetX    = 0.0;
            Double  pOffSetY    = 0.0;
            Double  pOffSetZ    = 0.0 + optOffset;
            Units   unit        = commandData.Application.ActiveUIDocument.Document.GetUnits();
            string  optMSG      = " : will be at " + UnitFormatUtils.Format(unit, UnitType.UT_Length, optOffset, false, false);

            if (optOffset != 0.0)
            {
                plunkThis.PlunkThisFamilyType(FamilyName, FamilySymbolName, wsName, bicFamily, out elemPlunked, oneShot, pOffSetX, pOffSetY, pOffSetZ, optMSG);
            }

            /// At this point there may or may not have been an element placed.
            #region SetParametersSection
            if (elemPlunked != null)
            {
                using (Transaction tp = new Transaction(doc, "PlunkOMatic:SetParam")) {
                    tp.Start();
                    //TaskDialog.Show(_pName, _pName);
                    Parameter parToSet = null;
                    parToSet = elemPlunked.LookupParameter(pNameOccHeight);
                    string strVal = UnitFormatUtils.Format(unit, UnitType.UT_Length, optOffset, false, false);
                    if (null != parToSet)
                    {
                        parToSet.SetValueString(strVal); // this parameter is distance, therefore valuestring
                    }
                    else
                    {
                        FamilyUtils.SayMsg("Cannot Set Parameter Value: " + strVal, "... because parameter:\n" + pNameOccHeight
                                           + "\ndoes not exist in the family:\n" + FamilyName
                                           + "\nof Category:\n" + bicFamily.ToString().Replace("OST_", ""));
                    }
                    tp.Commit();
                }
            }
            #endregion
            return(Result.Succeeded);
        }
Exemplo n.º 3
0
        public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            UIDocument       uiDoc      = commandData.Application.ActiveUIDocument;
            Document         doc        = uiDoc.Document;
            Selection        sel        = uiDoc.Selection;
            List <ElementId> selIds     = new List <ElementId>();
            Room             thisPickRm = null;
            string           pNamePWR   = "INPUT POWER";

            PlunkOClass plunkThis = new PlunkOClass(commandData.Application);

            if (plunkThis.NotInThisView())
            {
                return(Result.Succeeded);
            }

            // phase basis is the phase on which element status is determined for inclusion
            Phase phsBasis = FamilyUtils.GetDesiredPhaseBasis(doc);

            FormMsgWPF thisReport = new FormMsgWPF();
            string     bot        = "( ESC key cancels )";
            string     purpose    = "Room Lighting - Phase Basis: " + phsBasis.Name;
            bool       stay       = true;
            bool       doWeSelect = false;

            try {
                while (stay)
                {
                    RoomSelectionFilter cf = new RoomSelectionFilter();
                    Reference           pickedRoomReference = sel.PickObject(ObjectType.LinkedElement, cf, "Selecting Rooms Only");
                    if (pickedRoomReference == null)
                    {
                        return(Result.Failed);
                    }
                    // we need to get the linked document and then get the element that was picked from the LinkedElementId
                    RevitLinkInstance linkInstance     = doc.GetElement(pickedRoomReference) as RevitLinkInstance;
                    Document          linkedDoc        = linkInstance.GetLinkDocument();
                    Element           firstRoomElement = linkedDoc.GetElement(pickedRoomReference.LinkedElementId);

                    string selRmName    = "";
                    string selLV        = "";
                    string sePhsCreated = "";
                    // string daPhsDemo = "";
                    string selRmNumber = "";
                    double selRmArea   = 0.0;

                    switch (firstRoomElement.GetType().ToString())
                    {
                    case "Autodesk.Revit.DB.Architecture.Room":
                        thisPickRm = firstRoomElement as Room;
                        if (thisPickRm != null)
                        {
                            selRmName   = thisPickRm.Name.ToString();
                            selRmNumber = thisPickRm.Number.ToString();
                            Phase phCR = linkedDoc.GetElement(thisPickRm.CreatedPhaseId) as Phase;
                            if (phCR != null)
                            {
                                sePhsCreated = phCR.ToString();
                            }
                            Level itsLevelRm = thisPickRm.Level;
                            if (itsLevelRm != null)
                            {
                                selLV     = itsLevelRm.Name.ToString();
                                selRmArea = thisPickRm.Area;
                                //selIds.Add(thisPickRm.Id);  // does not work. A known Revit fact, cannot highlight linked elements
                            }
                        }
                        break;

                    default:
                        break;
                    }

                    string msgMain = firstRoomElement.Name;
                    msgMain = msgMain
                              + "\n" + "Rm Numb.: " + selRmNumber
                              + "\n" + "At level: " + selLV
                    ;

                    // Get all LightingFixtures in the current room
                    BuiltInCategory             bic               = BuiltInCategory.OST_LightingFixtures;
                    List <FamilyInstance>       famInstances      = FamilyUtils.FamilyInstanceCategoryInThisRoom(thisPickRm, bic, doc, phsBasis);
                    Dictionary <string, int>    dicFamInstances   = new Dictionary <string, int>();
                    Dictionary <string, double> dicLightFixTypeIP = new Dictionary <string, double>();
                    if (famInstances != null)
                    {
                        if (doWeSelect)
                        {
                            selIds.Clear();
                        }
                        foreach (FamilyInstance fi in famInstances)
                        {
                            string fiNamePair = fi.Symbol.FamilyName + " | " + fi.Symbol.Name;
                            //msg = msg + "\n" + fiNamePair;
                            int qty;
                            if (dicFamInstances.TryGetValue(fiNamePair, out qty))
                            {
                                dicFamInstances[fiNamePair] = qty + 1;
                            }
                            else
                            {
                                dicFamInstances.Add(fiNamePair, 1);
                                Parameter pPwr = fi.Symbol.LookupParameter(pNamePWR);
                                if (pPwr != null)
                                {
                                    double convVal = FamilyUtils.ConvertParmValueFromRaw(pPwr.AsDouble());
                                    dicLightFixTypeIP.Add(fiNamePair, convVal);
                                    //System.Windows.Forms.MessageBox.Show(fi.Symbol.Name + "  " + convVal.ToString());
                                }
                            }
                            if (doWeSelect)
                            {
                                selIds.Add(fi.Id);
                            }
                        }
                    }

                    string msgDetail     = "";
                    double totRoomLWatts = 0.0;
                    foreach (var item in dicFamInstances)
                    {
                        string itemName  = item.Key;
                        int    itemCount = item.Value;
                        double itemWatts;
                        if (dicLightFixTypeIP.TryGetValue(item.Key, out itemWatts))
                        {
                            double totalWattsForItem = itemWatts * Convert.ToDouble(itemCount);
                            totRoomLWatts = totRoomLWatts + totalWattsForItem;
                            msgDetail     = msgDetail + "\n" + itemName + "  cnt " +
                                            itemCount.ToString() + " @ " +
                                            itemWatts.ToString("0.00") + " for " +
                                            totalWattsForItem.ToString("0.0 w");
                        }
                        else
                        {
                            /// item key not in dictionary!
                        }
                    }
                    double lightFixPWRDensity = totRoomLWatts / selRmArea;
                    msgMain = msgMain
                              + "\n" + "Rm Area: " + selRmArea.ToString("0.00 sf") + "  L Pwr. Density: " + lightFixPWRDensity.ToString("0.00 w/sf") + "  Tot: " + totRoomLWatts.ToString("0.00 w")
                              + "\n"
                              + msgDetail;

                    thisReport.SetMsg(msgMain, purpose, bot, true);
                    thisReport.Show();
                }
            } catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                //TaskDialog.Show("Cancelled", "User cancelled");
                stay = false;
                thisReport.Close();
                uiDoc.Selection.SetElementIds(selIds);
                return(Result.Cancelled);
            }
            //Catch other errors
            catch (Exception ex) {
                thisReport.Close();
                FamilyUtils.SayMsg("Error At RoomLightingReporter", ex.Message);
                return(Result.Failed);
            }

            if (doWeSelect)
            {
                uiDoc.Selection.SetElementIds(selIds);
            }
            return(Result.Succeeded);
        }