❔ different variable type depending on condition of IF statement
Hi there, how would I go about having a different type on a variable with the same name, for later use? This is required for use in my code later on within the Autodesk RevitAPI
var elmFilter = null;
if (FilterSelected == 0)
{
Helpers.ElementFilterTerminals elmFilter = new Helpers.ElementFilterTerminals();
}
if (FilterSelected == 1)
{
Helpers.ElementFilterDuctwork elmFilter = new Helpers.ElementFilterDuctwork();
}
//later on...
pickedRef = sel.PickObject(ObjectType.PointOnElement, elmFilter, "Pick the elements to be updated.");var elmFilter = null;
if (FilterSelected == 0)
{
Helpers.ElementFilterTerminals elmFilter = new Helpers.ElementFilterTerminals();
}
if (FilterSelected == 1)
{
Helpers.ElementFilterDuctwork elmFilter = new Helpers.ElementFilterDuctwork();
}
//later on...
pickedRef = sel.PickObject(ObjectType.PointOnElement, elmFilter, "Pick the elements to be updated.");in my helpers class:in my helpers class: public class ElementFilterTerminals : ISelectionFilter
{
public bool AllowElement(Element e)
{
//TO-DO: Add Magicad Family for end caps to this.
return (e.Category.Id.IntegerValue.Equals(
(int)BuiltInCategory.OST_DuctTerminal)) ||
(e.Category.Id.IntegerValue.Equals(
(int)BuiltInCategory.OST_MechanicalEquipment));
}
public bool AllowReference(Autodesk.Revit.DB.Reference r, XYZ p)
{
return (r.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_SURFACE);
}
}
public class ElementFilterDuctwork : ISelectionFilter
{
public bool AllowElement(Element e)
{
return (e.Category.Id.IntegerValue.Equals(
(int)BuiltInCategory.OST_DuctSystem)) ||
(e.Category.Id.IntegerValue.Equals(
(int)BuiltInCategory.OST_DuctFitting));
}
public bool AllowReference(Autodesk.Revit.DB.Reference r, XYZ p)
{
return (r.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_SURFACE);
}
} public class ElementFilterTerminals : ISelectionFilter
{
public bool AllowElement(Element e)
{
//TO-DO: Add Magicad Family for end caps to this.
return (e.Category.Id.IntegerValue.Equals(
(int)BuiltInCategory.OST_DuctTerminal)) ||
(e.Category.Id.IntegerValue.Equals(
(int)BuiltInCategory.OST_MechanicalEquipment));
}
public bool AllowReference(Autodesk.Revit.DB.Reference r, XYZ p)
{
return (r.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_SURFACE);
}
}
public class ElementFilterDuctwork : ISelectionFilter
{
public bool AllowElement(Element e)
{
return (e.Category.Id.IntegerValue.Equals(
(int)BuiltInCategory.OST_DuctSystem)) ||
(e.Category.Id.IntegerValue.Equals(
(int)BuiltInCategory.OST_DuctFitting));
}
public bool AllowReference(Autodesk.Revit.DB.Reference r, XYZ p)
{
return (r.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_SURFACE);
}
}