Originally Posted by
Ning Zhou
OK, then what is the "area" in your code? at first i assume it's ViewSchedule like below:
ViewSchedule vs = new FilteredElementCollector(doc).OfClass(typeof(ViewSchedule)).ElementAt(1) as ViewSchedule; // assume casework keyschedule
parmId = vs.get_Parameter("Casework Style").AsElementId();
elem = doc.GetElement(new ElementId(parmId.IntegerValue));
if (elem != null)
value = elem.get_Parameter(BuiltInParameter.REF_TABLE_ELEM_NAME).AsString();
else
value = "(none)";
well, at first i thought you can get mapped field value like "1" -> "x", "2" -> "xx", "3" -> "xxx", etc.
area was the element I was getting the key value of. I would image you can use any element that has a key parameter for it. After you get the key element, then you can get its parameters which I think are the values you are looking for. I don't think you can do what you seem to be trying to do which is grab the keys and all their values from a schedule. Unless you already have all the ElementIds of the keys, which there doesn't seem to be enough properties in order to get them or you have a set of elements that each have a key assigned to it that you can grab from. Alternatively, but prone to error, you can use the code below (in macro form). It searches for a key based on its name instead of the Key Parameter name. The problem is that keys could have the same name, so it only works if all the key names are unique:
Code:
public void GetKeyParameterValues()
{
Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = this.ActiveUIDocument;
string data = "";
string keyName = "4"; // name of key you want to get - hopefully no duplicates in project!
foreach (Element key in new FilteredElementCollector(doc).WhereElementIsNotElementType())
{
try
{
if (key.get_Parameter(BuiltInParameter.REF_TABLE_ELEM_NAME).AsString() == keyName)
{
foreach (Parameter p in key.Parameters)
{
data += p.Definition.Name + ": " + getParameterString(p) + Environment.NewLine;
}
break;
}
}
catch { continue; }
}
TaskDialog.Show("Info", data);
}
public static string getParameterString(Parameter p)
{
if (p.StorageType == StorageType.Integer)
return p.AsInteger().ToString();
else if (p.StorageType == StorageType.Double)
{
return p.AsDouble().ToString();
}
else if (p.StorageType == StorageType.ElementId)
{
return p.AsElementId().ToString();
}
else if (p.StorageType == StorageType.String)
{
return p.AsString();
}
else
return "?";
}