revit-二次开发在项目中 修改族类型参数和族实例参数

using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;

namespace ReadParasFamily
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class Test : IExternalCommand
    {

    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        #region//获得当前文件
        UIDocument uidoc = commandData.Application.ActiveUIDocument;
        Document doc = uidoc.Document;
        #endregion

        #region//过滤出需要的族类型
        FilteredElementCollector FilterElemens = new FilteredElementCollector(doc);
        IList list1 = FilterElemens.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_GenericModel).ToElements();
        ElementId familysymbolid = null;
        if (list1!=null)
        {
            foreach (var item in list1)
            {
                if (item.Name == "测试1")
                {
                    //修改族类型参数
                    #region
                    ParameterSet parameters = item.Parameters;
                    foreach (Parameter item1 in parameters)
                    {
                        if (item1.Definition.Name == "高度")
                        {
                            //string ss = item1.AsValueString();
                            //TaskDialog.Show("1", ss);
                            Transaction transaction = new Transaction(doc);
                            transaction.Start("李博");
                            double bb = 0.200;
                            item1.Set(bb);
                            transaction.Commit();
                        }
                    }
                    #endregion
                    familysymbolid = item.Id;
                    //修改族实例参数
                    #region

                    FamilyInstanceFilter familyInstanceFilter = new FamilyInstanceFilter(doc, familysymbolid);
                    FilteredElementCollector elementss = new FilteredElementCollector(doc);
                  IList  familuinstancElements= elementss.WherePasses(familyInstanceFilter).ToElements();
                    foreach (var item3 in familuinstancElements )
                    {
                        ParameterSet parameterss = item3.Parameters;
                        foreach (Parameter  item4 in parameterss)
                        {
                            if (item4.Definition.Name=="上部分高度")
                            {
                                Transaction transaction1 = new Transaction(doc);
                                transaction1.Start("李博 ");
                                double bb = 0.200;
                                item4.Set(bb);
                                transaction1.Commit();
                            }
                        }

                    }
                    #endregion

                }
            }

        }
        #endregion
        


        return Result.Succeeded;


    }
   


}


}

你可能感兴趣的:(revit二次开发)