1. 程式人生 > >Revit二次開發--設定族型別引數

Revit二次開發--設定族型別引數

已知載入到專案中的族Family,如何設定該族型別的引數,程式碼如下:

	 private Family EditFamilyToSetParam(Document doc, Family family, double diameter)
    {
        try
        {
            Document familyDoc = doc.EditFamily(family);
            FamilyParameter familyParamWidth = null;
            FamilyManager familyMgr = familyDoc.FamilyManager;
            FamilyParameterSet parameters = familyMgr.Parameters;
            FamilyType familyType = familyMgr.CurrentType;

            foreach (FamilyParameter param in parameters)
            {
                if (param.Definition.Name == "淨寬")
                {
                    familyParamWidth = param;
                }
            }
            //修改族型別引數
            using (Transaction trans = new Transaction(familyDoc))
            {
                trans.Start("Edit Family Parameter");
                double width = diameter + double.Parse(PublicValue.paramDic["leftDist"]) * 2;
                familyMgr.Set(familyParamWidth, width / 304.8);
                trans.Commit();
            }
            Family familyEnd = familyDoc.LoadFamily(doc, new FamilyLoadOptionsImp());
            return familyEnd;
        }
        catch (Exception e)
        {
            throw new Exception(e.Message);
        }