public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            UIApplication uiapp  = commandData.Application;
            UIDocument    _uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application _app = uiapp.Application;
            Autodesk.Revit.DB.Document _doc = _uidoc.Document;

            BuiltInCategory bicFamilyA = BuiltInCategory.OST_DuctTerminal;
            BuiltInCategory bicFamilyB = BuiltInCategory.OST_DataDevices;
            BuiltInCategory bicFamilyC = BuiltInCategory.OST_MechanicalEquipment;
            //BuiltInCategory bicFamilyC = BuiltInCategory.OST_Sprinklers;

            ICollection <BuiltInCategory> categories = new[] { bicFamilyA, bicFamilyB, bicFamilyC };
            ElementFilter    myPCatFilter            = new ElementMulticategoryFilter(categories);
            ISelectionFilter myPickFilter            = SelFilter.GetElementFilter(myPCatFilter);

            bool       keepOnTruckn = true;
            FormMsgWPF formMsg      = new FormMsgWPF();

            formMsg.Show();

            using (TransactionGroup pickGrp = new TransactionGroup(_doc)) {
                pickGrp.Start("CmdCycleType");
                bool firstTime = true;

                //string strCats= "";
                //foreach (BuiltInCategory iCat in categories) {
                //    strCats = strCats + iCat.ToString().Replace("OST_", "") + ", ";
                //}
                string strCats = FamilyUtils.BICListMsg(categories);

                formMsg.SetMsg("Pick the " + strCats + " to check its type.", "Type Cycle:");
                while (keepOnTruckn)
                {
                    try {
                        Reference pickedElemRef = _uidoc.Selection.PickObject(ObjectType.Element, myPickFilter, "Pick the " + bicFamilyA.ToString() + " to cycle its types. (Press ESC to cancel)");
                        Element   pickedElem    = _doc.GetElement(pickedElemRef.ElementId);

                        FamilyInstance fi = pickedElem as FamilyInstance;
                        FamilySymbol   fs = fi.Symbol;

                        var famTypesIds = fs.Family.GetFamilySymbolIds().OrderBy(e => _doc.GetElement(e).Name).ToList();
                        int thisIndx    = famTypesIds.FindIndex(e => e == fs.Id);
                        int nextIndx    = thisIndx;
                        if (!firstTime)
                        {
                            nextIndx = nextIndx + 1;
                            if (nextIndx >= famTypesIds.Count)
                            {
                                nextIndx = 0;
                            }
                        }
                        else
                        {
                            firstTime = false;
                        }

                        if (pickedElem != null)
                        {
                            using (Transaction tp = new Transaction(_doc, "PlunkOMatic:SetParam")) {
                                tp.Start();
                                if (pickedElem != null)
                                {
                                    fi.Symbol = _doc.GetElement(famTypesIds[nextIndx]) as FamilySymbol;
                                    formMsg.SetMsg("Currently:\n" + fi.Symbol.Name + "\n\nPick again to cycle its types.", "Type Cycling");
                                }
                                tp.Commit();
                            }
                        }
                        else
                        {
                            keepOnTruckn = false;
                        }
                    } catch (Exception) {
                        keepOnTruckn = false;
                        //throw;
                    }
                }
                pickGrp.Assimilate();
            }

            formMsg.Close();
            return(Result.Succeeded);
        }
        public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            UIApplication uiapp  = commandData.Application;
            UIDocument    _uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application _app = uiapp.Application;
            Autodesk.Revit.DB.Document _doc = _uidoc.Document;

            PlunkOClass     plunkThis         = new PlunkOClass(commandData.Application);
            string          wsName            = "MECH HVAC";
            string          FamilyName        = "M_BAS SENSOR";
            string          FamilySymbolName  = "THERMOSTAT";
            string          pName             = "STAT ZONE NUMBER";
            string          FamilyTagName     = "M_EQIP_BAS_SENSOR_TAG";
            string          FamilyTagNameSymb = "SENSOR";
            bool            oneShot           = true;
            bool            hasLeader         = false;
            BuiltInCategory bicTagBeing       = BuiltInCategory.OST_MechanicalEquipmentTags;
            BuiltInCategory bicFamily         = BuiltInCategory.OST_DataDevices;
            BuiltInCategory _bicMechItem      = BuiltInCategory.OST_MechanicalEquipment;
            Element         elemPlunked;
            bool            keepOnTruckn = true;

            while (keepOnTruckn)
            {
                try {
                    Result     result  = plunkThis.PlunkThisFamilyType(FamilyName, FamilySymbolName, wsName, bicFamily, out elemPlunked, oneShot);
                    FormMsgWPF formMsg = new FormMsgWPF();
                    if ((result == Result.Succeeded) & (elemPlunked != null))
                    {
                        formMsg.Show();
                        formMsg.SetMsg("Now Select the Mech Unit for this sensor.", "Sensor For MEQ");
                        Transaction tp = new Transaction(_doc, "PlunkOMatic:OrientGuts ");
                        tp.Start();
                        plunkThis.OrientTheInsides(elemPlunked);
                        tp.Commit();
                        ICollection <BuiltInCategory> categories = new[] { _bicMechItem };
                        ElementFilter    myPCatFilter            = new ElementMulticategoryFilter(categories);
                        ISelectionFilter myPickFilter            = SelFilter.GetElementFilter(myPCatFilter);
                        try {
                            Reference pickedElemRef = _uidoc.Selection.PickObject(ObjectType.Element, myPickFilter, "Select the Mech Unit for this sensor.");
                            Element   pickedElem    = _doc.GetElement(pickedElemRef.ElementId);
                            formMsg.SetMsg("Now place the unit text at the sensor.", "Sensor For MEQ");
                            plunkThis.AddThisTag(pickedElem, FamilyTagName, FamilyTagNameSymb, pName, bicTagBeing, hasLeader);
                            formMsg.Close();
                        } catch (Exception) {
                            formMsg.Close();
                            keepOnTruckn = false;
                            //throw;
                        }
                    }
                    else
                    {
                        formMsg.Close();
                        keepOnTruckn = false;
                    }
                } catch (Autodesk.Revit.Exceptions.OperationCanceledException) {
                    keepOnTruckn = false;
                    //    TaskDialog.Show("Where", "here  " );
                }
            }
            return(Result.Succeeded);
        }
        public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            UIApplication uiapp  = commandData.Application;
            UIDocument    _uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application _app = uiapp.Application;
            Autodesk.Revit.DB.Document _doc = _uidoc.Document;

            PlunkOClass     plunkThis          = new PlunkOClass(commandData.Application);
            string          wsName             = "MECH HVAC";
            string          FamilyName         = "M_BAS SENSOR";
            string          FamilySymbolName   = "THERMOSTAT";
            string          FamilyTagName      = "M_EQIP_BAS_SENSOR_TAG";
            string          FamilyTagNameSymb  = "TAG NUMBER ONLY";
            string          FamilyTagName2     = "M_DEVICE_BAS_TAG_SYM";
            string          FamilyTagNameSymb2 = "M-DATA-SENSOR";
            bool            hasLeader          = false;
            bool            oneShot            = true;
            BuiltInCategory bicTagBeing        = BuiltInCategory.OST_MechanicalEquipmentTags;
            BuiltInCategory bicTagBeing2       = BuiltInCategory.OST_DataDeviceTags;
            BuiltInCategory bicFamily          = BuiltInCategory.OST_DataDevices;
            BuiltInCategory bicMechItem        = BuiltInCategory.OST_MechanicalEquipment;
            Element         elemPlunked;
            bool            keepOnTruckn = true;

            while (keepOnTruckn)
            {
                try {
                    Result     result  = plunkThis.PlunkThisFamilyType(FamilyName, FamilySymbolName, wsName, bicFamily, out elemPlunked, oneShot);
                    FormMsgWPF formMsg = new FormMsgWPF();
                    if ((result == Result.Succeeded) & (elemPlunked != null))
                    {
                        plunkThis.AddThisTag(elemPlunked, FamilyTagName2, FamilyTagNameSymb2, "Offset Stat", bicTagBeing2, true);
                        formMsg.Show();
                        formMsg.SetMsg("Now Select the Mech Unit for this sensor.", "Offset Sensor For MEQ");
                        Transaction tp = new Transaction(_doc, "PlunkOMatic:SymVis");
                        tp.Start();
                        Parameter parForVis = elemPlunked.LookupParameter("SHOW SYM");
                        if (null != parForVis)
                        {
                            parForVis.Set(0);
                        }
                        plunkThis.OrientTheInsides(elemPlunked);  // left in in case type is changed later
                        tp.Commit();

                        ICollection <BuiltInCategory> categories = new[] { bicMechItem };
                        ElementFilter    myPCatFilter            = new ElementMulticategoryFilter(categories);
                        ISelectionFilter myPickFilter            = SelFilter.GetElementFilter(myPCatFilter);
                        try {
                            Reference pickedElemRef = _uidoc.Selection.PickObject(ObjectType.Element, myPickFilter, "Select the Mech Unit for this sensor.");
                            Element   pickedElem    = _doc.GetElement(pickedElemRef.ElementId);
                            formMsg.SetMsg("Now place the unit text at the sensor.", "Offset Sensor For MEQ");
                            plunkThis.AddThisTag(pickedElem, FamilyTagName, FamilyTagNameSymb, "Offset Stat", bicTagBeing, hasLeader);
                            formMsg.Close();
                        } catch (Exception) {
                            formMsg.Close();
                            keepOnTruckn = false;
                            //throw;
                        }
                    }
                    else
                    {
                        formMsg.Close();
                        keepOnTruckn = false;
                    }
                } catch (Exception) {
                    keepOnTruckn = false;
                    //throw;
                }
            }
            return(Result.Succeeded);
        }
        public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            UIApplication uiapp  = commandData.Application;
            UIDocument    _uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application _app = uiapp.Application;
            Autodesk.Revit.DB.Document _doc = _uidoc.Document;

            string          parmTogN                 = "SHOW SYM";
            BuiltInCategory bicFamily                = BuiltInCategory.OST_DataDevices;
            BuiltInCategory bicFamilyTag             = BuiltInCategory.OST_DataDeviceTags;
            ICollection <BuiltInCategory> categories = new[] { bicFamily, bicFamilyTag };
            ElementFilter    myPCatFilter            = new ElementMulticategoryFilter(categories);
            ISelectionFilter myPickFilter            = SelFilter.GetElementFilter(myPCatFilter);

            bool       keepOnTruckn = true;
            FormMsgWPF formMsgWPF   = new FormMsgWPF();

            formMsgWPF.Show();

            while (keepOnTruckn)
            {
                try {
                    formMsgWPF.SetMsg("Pick the Sensor to toggle symbol visibility.", "Sensor Symbol Toggle");
                    Reference pickedElemRef = _uidoc.Selection.PickObject(ObjectType.Element, myPickFilter, "Pick the Sensor to toggle symbol visibility. (Press ESC to cancel)");
                    Element   pickedElem    = _doc.GetElement(pickedElemRef.ElementId);
                    // get tagged element instead if user picked the tag
                    if (pickedElem.GetType() == typeof(IndependentTag))
                    {
                        IndependentTag _tag = (IndependentTag)pickedElem;
                        pickedElem = _doc.GetElement(_tag.TaggedLocalElementId);
                    }
                    if (pickedElem != null)
                    {
                        Transaction tp = new Transaction(_doc, "PlunkOMatic:SetParam");
                        tp.Start();
                        //TaskDialog.Show("Debug", pickedElem.ToString());
                        if (pickedElem != null)
                        {
                            Parameter parForTog = pickedElem.LookupParameter(parmTogN);
                            if (null != parForTog)
                            {
                                if (parForTog.AsInteger() == 1)
                                {
                                    parForTog.Set(0);
                                }
                                else
                                {
                                    parForTog.Set(1);
                                }
                            }
                        }
                        tp.Commit();
                    }
                    else
                    {
                        keepOnTruckn = false;
                    }
                } catch (Exception) {
                    keepOnTruckn = false;
                    //throw;
                }
            }
            formMsgWPF.Close();
            return(Result.Succeeded);
        }