Message 1 of 5
InvalidOperationExcpetion when trying to get Space information from Family Instance using Revit API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Not all family instance has Space linked. There few family instance that has Space linked and others not.
Whenever code get family instance with space linked it works fine but when i get family instance which has no space linked that throws "Autodesk.Revit.Exceptions.InvalidOperationException: The target instance does not exist in the given phase". How to handle this?
Here is the code sample
List<BuiltInCategory> filteredCat = new List<BuiltInCategory> {
BuiltInCategory.OST_SpecialityEquipment
,BuiltInCategory.OST_FurnitureSystems
};
ElementMulticategoryFilter multiFilter = new ElementMulticategoryFilter(filteredCat);
FilteredElementCollector filterCollector = new FilteredElementCollector(doc)
.OfClass(typeof(FamilyInstance));
filterCollector.WherePasses(multiFilter);
foreach (Element ele in filterCollector.ToElements())
{
ElementId id = ele.GetTypeId();
FamilySymbol symbol = doc.GetElement(id) as FamilySymbol;
ParameterMap familyParamMap = symbol.ParametersMap;
if (familyParamMap != null)
{
var familyInstance = ele as FamilyInstance;
if (familyInstance != null)
{
Autodesk.Revit.DB.Mechanical.Space space = familyInstance.Space;
if (space != null)
{
spaceMap = space.ParametersMap;
}
}
}
}
I am trying to get a value from Space parameter map. If Space is not linked to family instance will that not return null? Are we expected to see this error.