unable to add Material Parameter to Family

unable to add Material Parameter to Family

dirk.neethling
Advocate Advocate
1,117 Views
1 Reply
Message 1 of 2

unable to add Material Parameter to Family

dirk.neethling
Advocate
Advocate

I have been struggling for a while trying to add material to a Family. It seems strange that such a basic requirement is so difficult to implement.

I've tried most examples which I could find. The BuildingCoder samples were not helpful either.

 

Could anybody help me with this?

 

I generate a Family and am able to generate FamilyInstances of that Family. However, when I add the "Material" Parameter using AddParameter, I can no longer Access the Family using either Util.FindFamilySymbol or doc.LoadFamily(fileName, out Family). It seems as if adding a Parameter somehow invalidates that Family.

 

 

            FamilyManager fm = doc.FamilyManager;
            FamilyParameter fparam = fm.get_Parameter("Material");
            bool canAssign = fm.IsUserAssignableParameterGroup(BuiltInParameterGroup.PG_MATERIALS);

            if (fparam == null)
                oFamParam = fm.AddParameter("Material", BuiltInParameterGroup.PG_MATERIALS, ParameterType.Material, true);
            if (material != null)
            {
                if (doc.FamilyManager.Types.Size == 0)
                    ft = doc.FamilyManager.NewType("Type 1");
                fm.CurrentType = ft;
                fm.Set(oFamParam, material.Id);
            }

dirk

 

0 Likes
Accepted solutions (1)
1,118 Views
1 Reply
Reply (1)
Message 2 of 2

dirk.neethling
Advocate
Advocate
Accepted solution

OK, this turns out to be trivial, once you get it.

helped me sort this out, thanks:

 

 

prm = solid.get_Parameter(BuiltInParameter.MATERIAL_ID_PARAM);

prm.Set(material.Id);

 

https://forums.autodesk.com/t5/revit-api-forum/associate-a-family-parameter/m-p/7165307/highlight/fa...

 

dirk

0 Likes