Conversion of type parameters and instance parameters of revit redevelopment family

1 background

In the second development of revit, small partners may need to transform the family type parameters and instance parameters in the family environment.

2 way of thinking

1. Use the family manager FamilyManager, see Note 1
2. First obtain the parameters to be converted (single and batch), see Note 2, 3
3. For instance parameter to type parameter or type parameter to instance to instance parameter, see note 4, 5

3 code

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;

namespace heiyedeqishi
    class Revit_API_Executable1 : IExternalCommand
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;       
                Transaction trans = new Transaction(doc, "Parameter transformation");
                //1 get FamilyManager
                FamilyManager familyManager = doc.FamilyManager;
                //2 get family parameters by name
                FamilyParameter singleParameter = familyManager.get_Parameter("Material Science");
                //3. Get family parameters through traversal
                foreach (FamilyParameter familyParameter in familyManager.Parameters)
                    //4 type to instance
                    //5 instance conversion type
                return Result.Succeeded;
            catch (Exception ex)
                message = ex.Message;
                return Result.Failed;

4 precautions

If the parameter itself is an instance parameter, even if it is changed to an instance parameter, no error will be reported
Type parameter, as above

Posted on Fri, 08 Nov 2019 11:40:09 -0800 by xtiano77