Hello All,
I have been trying to figure out how to set and retrieve parameter values of elements. For testing I built a macro that creates a diffuser, and as a test I would like to display the Mark, and set the Offset to 10 ft. From the help file I would have thought that the code to retrieve the Mark would be:
Code:
Parameter param = fi.Parameter("Mark");
And, I would have thought that the code to set the Offset to 10 would be
Code:
Parameter param = fi.Parameter("Offset");
param.Set(10);
I have looked through the Developers Guide and some sample macros from the SDK, but still haven't been able to figure it out. If someone would point out where I'm going wrong, it would be greatly appreciated. The full code for my example macro is below.
Code:
public void AddDiffuser()
{
UIDocument uiDoc = this.ActiveUIDocument;
Document doc = this.ActiveUIDocument.Document;
//Get the level of the active view
Level l = doc.ActiveView.GenLevel;
//Get the family of the diffuser (family name)
Family f = new FilteredElementCollector(doc)
.OfClass(typeof(Family))
.FirstOrDefault(q => q.Name == "Supply Diffuser") as Family;
//Get the Type
FamilySymbol fs = f.Symbols.Cast<FamilySymbol>()
.First(q => q.Name == "24 x 24 Face 12 x 12 Connection");
using (Transaction t = new Transaction(doc,"Create Diffusers"))
{
t.Start();
XYZ diffuserPnt = new XYZ(-65,55,99);
//Create new diffuser
FamilyInstance fi = doc.Create
.NewFamilyInstance(diffuserPnt, fs, l, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
//How to a retrieve a parameter value from a family instance that was just created?????
Parameter param = fi.Parameter("Mark");
TaskDialog.Show("The Name of the Element", param.ToString());
//How to a set a parameter value from a family instance that was just created?????
Parameter param = fi.Parameter("Offset");
param.Set(10);
TaskDialog.Show("The Name of the Element", param.ToString());
t.Commit();
}
}