Esempio n. 1
0
        // Show a message to decide whether to save the document.
        void a_DocumentSaving(
            object obj,
            DocumentSavingEventArgs args)
        {
            // Ask whether to prevent from saving:

            bool cancel = args.Cancellable &&
                          LabUtils.QuestionMsg(
                "Saving event handler was triggered.\r\n"
                + "Using the pre-event mechanism, we can cancel the save.\r\n"
                + "Continue saving the document?");

            //args.Cancel = cancel; // 2011
            if (cancel)
            {
                args.Cancel();
            }                         // 2012
        }
Esempio n. 2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document      doc = app.ActiveUIDocument.Document;

            List <string>            a = new List <string>();
            FilteredElementCollector families;

            #region 3.1.a Retrieve and iterate over all Family objects in document:
            //
            // retrieve all family elements in current document:
            //
            families = new FilteredElementCollector(doc);

            families.OfClass(typeof(Family));

            foreach (Family f in families)
            {
                // Get its category name; notice that the Category property is not
                // implemented for the Family class; use FamilyCategory instead;
                // notice that that is also not always implemented; in that case,
                // use the workaround demonstrated below, looking at the contained
                // family symbols' category:

                a.Add(string.Format("Name={0}; Category={1}; FamilyCategory={2}",
                                    f.Name,
                                    ((null == f.Category) ? "?" : f.Category.Name),
                                    ((null == f.FamilyCategory) ? "?" : f.FamilyCategory.Name)));
            }
            #endregion // 3.1.a

            string msg = "{0} standard familie{1} are loaded in this model{2}";
            LabUtils.InfoMsg(msg, a);

            // Loop through the collection of families, and now look at
            // the child symbols (types) as well. These symbols can be
            // used to determine the family category.

            foreach (Family f in families)
            {
                string catName;
                bool   first = true;

                // Loop all contained symbols (types):

                //foreach( FamilySymbol s in f.Symbols ) // 2014
                foreach (ElementId id in f.GetFamilySymbolIds()) // 2015
                {
                    FamilySymbol s = doc.GetElement(id) as FamilySymbol;

                    // you can determine the family category from its first symbol.

                    if (first)
                    {
                        first = false;

                        #region 3.1.b Retrieve category name of first family symbol:
                        catName = s.Category.Name;
                        #endregion // 3.1.b

                        msg = "Family: Name=" + f.Name
                              + "; Id=" + f.Id.IntegerValue.ToString()
                              + "; Category=" + catName
                              + "\r\nContains Types:";
                    }
                    msg += "\r\n    " + s.Name + "; Id=" + s.Id.IntegerValue.ToString();
                }

                // Show the symbols for this family and allow user to proceed
                // to the next family (OK) or cancel (Cancel)

                msg += "\r\nContinue?";
                if (!LabUtils.QuestionMsg(msg))
                {
                    break;
                }
            }
            //
            // return all families whose name contains the substring "Round Duct":
            //
            IEnumerable <Family> round_duct_families
                = LabUtils.GetFamilies(doc, "Round Duct", true);

            int n = round_duct_families.Count();

            return(Result.Failed);
        }
Esempio n. 3
0
        /// <summary>
        /// Revit external command to list all valid built-in parameters for a given selected element.
        /// </summary>
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            Element e
                = LabUtils.GetSingleSelectedElementOrPrompt(
                      uidoc);

            if (null == e)
            {
                return(Result.Cancelled);
            }

            bool isSymbol = false;

            #region Check for FamilyInstance
#if CHECK_FOR_FAMILY_INSTANCE
            //
            // for a family instance, ask user whether to
            // display instance or type parameters;
            // in a similar manner, we could add dedicated
            // switches for Wall --> WallType,
            // Floor --> FloorType etc. ...
            //
            if (e is FamilyInstance)
            {
                FamilyInstance inst = e as FamilyInstance;
                if (null != inst.Symbol)
                {
                    string symbol_name
                        = LabUtils.ElementDescription(
                              inst.Symbol, true);

                    string family_name
                        = LabUtils.ElementDescription(
                              inst.Symbol.Family, true);

                    string msg =
                        "This element is a family instance, so it "
                        + "has both type and instance parameters. "
                        + "By default, the instance parameters are "
                        + "displayed. If you select 'No', the type "
                        + "parameters will be displayed instead. "
                        + "Would you like to see the instance "
                        + "parameters?";

                    if (!LabUtils.QuestionMsg(msg))
                    {
                        e        = inst.Symbol;
                        isSymbol = true;
                    }
                }
            }
#endif // CHECK_FOR_FAMILY_INSTANCE
            #endregion // Check for FamilyInstance

            #region Check for element type
#if CHECK_GET_TYPE_ID
            ElementId idType = e.GetTypeId();

            if (ElementId.InvalidElementId != idType)
            {
                // The selected element has a type; ask user
                // whether to display instance or type
                // parameters.

                ElementType typ = doc.GetElement(idType)
                                  as ElementType;

                Debug.Assert(null != typ,
                             "expected to retrieve a valid element type");

                string type_name = LabUtils.ElementDescription(
                    typ, true);

                string msg =
                    "This element has an ElementType, so it has "
                    + "both type and instance parameters. By "
                    + "default, the instance parameters are "
                    + "displayed. If you select 'No', the type "
                    + "parameters will be displayed instead. "
                    + "Would you like to see the instance "
                    + "parameters?";

                if (!LabUtils.QuestionMsg(msg))
                {
                    e        = typ;
                    isSymbol = true;
                }
            }
#endif // CHECK_GET_TYPE_ID
            #endregion // Check for element type

            SortableBindingList <ParameterData> data = new SortableBindingList <ParameterData>();
            {
                WaitCursor waitCursor = new WaitCursor();
                Array      bips       = Enum.GetValues(typeof(BuiltInParameter));
                int        n          = bips.Length;
                Parameter  p;
                foreach (BuiltInParameter a in bips)
                {
                    try
                    {
                        p = e.get_Parameter(a);

                        #region Check for external definition
#if CHECK_FOR_EXTERNAL_DEFINITION
                        Definition         d    = p.Definition;
                        ExternalDefinition e    = d as ExternalDefinition; // this is never possible
                        string             guid = (null == e) ? null : e.GUID.ToString();
#endif // CHECK_FOR_EXTERNAL_DEFINITION
                        #endregion // Check for external definition

                        if (null != p)
                        {
                            //string value = LabUtils.GetParameterValue2( p, doc );
                            string valueString = (StorageType.ElementId == p.StorageType)
                ? LabUtils.GetParameterValue2(p, doc)
                : p.AsValueString();

                            data.Add(new ParameterData(a, p, valueString));
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Print("Exception retrieving built-in parameter {0}: {1}",
                                    a, ex);
                    }
                }
            }
            string description = LabUtils.ElementDescription(e, true)
                                 + (isSymbol
          ? " Type"
          : " Instance");

            using (BuiltInParamsCheckerForm form = new BuiltInParamsCheckerForm(description, data))
            {
                form.ShowDialog();
            }
            return(Result.Succeeded);
        }