I'm trying to generate some elements in Revit using one Macro. When I try to define any parameter to any generated element, I use the Set()
method from Parameter
class.
When I try to define any double
, int
or string
parameter it works fine. However, when I try to define a bool
parameter, it doesn't work.
I know that in Revit you have to define all boolean parameters as an int so I convert all boolean parameters to 0 when false and 1 when true.
public void Define_Parameter()
{
// I get the family.
Family family_test = Get_Family("STR_Top&BottomReinforcement_Fixed_pruebas");
// I get the symbols of the family.
FamilySymbol symbols_test = ActiveUIDocument.Document.GetElement(family_test.GetFamilySymbolIds().First()) as FamilySymbol;
// I initiate one transaction.
Transaction transaction_test = new Transaction(ActiveUIDocument.Document, "Test");
transaction_test.Start();
// I generate all elements requiered to generate a new family instance
Line line_test = Line.CreateBound(new XYZ(0, 10, ActiveUIDocument.ActiveView.Origin.Z), new XYZ(10, 10, ActiveUIDocument.ActiveView.Origin.Z));
FamilyInstance instance_test = ActiveUIDocument.Document.Create.NewFamilyInstance(line_test, symbols_test, ActiveUIDocument.ActiveView);
// I modify the boolean parameter.
Parameter parameter = Get_Parameter(instance_test, "Top_Hook90_Right");
parameter.Set(1);
transaction_test.Commit();
}
public static Family Get_Family(string Family_Name)
{
// I get all families of the model.
FilteredElementCollector filter = new FilteredElementCollector(Phantom.BIM.Revit.Recursos.Datos.Documento_Revit.Document);
List<Element> families = filter.OfClass(typeof(Family)).ToList();
// I go through the list of families and I try to get the one requested
foreach (Element family in families) if ((family as Family).Name == Family_Name) return family as Family;
// The family requested doesn't exists.
return null;
}
public static Parameter Get_Parameter(Element Host_Element, string Param_Name)
{
// I go through the list of parameters and I try to return the one requested.
foreach (Parameter param in Host_Element.Parameters) if (param.Definition.Name == Param_Name) return param;
// The parameter doesn't exists.
return null;
}
These are all methods requiered for the macro. I don't know why is not working with boolean parameters.. any idea?
Thanks
Well.... this is really embarrassing but I have to post the answer in order to help the community.
The correct way to do it is forcing the type introduced to be sure that the value is an integer. If you don't force it, it's introduced as a double
. So, the correct way will be:
Parameter parameter = Get_Parameter(instance_test, "Top_Hook90_Right");
parameter.Set((int)1);