I keep getting this exception when iterating trough a FilteredElementCollector.
Exception thrown at 0x00007FFA03A27788 in Revit.exe:
Microsoft C++ exception: InvalidOperationException at memory location 0x00000099B64FADA8.
If there is a handler for this exception, the program may be safely continued.
Solved! Go to Solution.
I keep getting this exception when iterating trough a FilteredElementCollector.
Exception thrown at 0x00007FFA03A27788 in Revit.exe:
Microsoft C++ exception: InvalidOperationException at memory location 0x00000099B64FADA8.
If there is a handler for this exception, the program may be safely continued.
Solved! Go to Solution.
Solved by matthew_taylor. Go to Solution.
The code itself does not delete elements. The families are updated and that does change the element.
private bool ConvertParameters(Document doc) { // Load the Elements which will be updated. IEnumerable<Element> elements = this.GetAllWoononElements(doc); foreach (Element e in elements) { // what ever, exception iss thrown in the foreach. } }
// GetElementsWithGroepParameter returns all the Elements that have the shared parameter // KO_Groep. This is a legecy parameter which we know Elements uploaded to WOONON require. private IEnumerable<Element> GetAllWoononElements(Document doc) { var result = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .Where(q => this.ElementIsWoononElement(q)) ; return result; }
// We use the element name parameter. Don't use the Version parameter, because the // project information uses the project parameter as well. private bool ElementIsWoononElement(Element e) { Parameter name = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol(WoononParameters.WO_FAMILY_ELEMENT_NAME, e); if (name != null && name.HasValue) return true; Parameter g = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol("KO_Groep", e); Parameter o = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol("KO_Optienummer", e); if ((g == null || o == null) || (!g.HasValue || !o.HasValue)) return false; string gs = HParameters.GetParameterValue(g).ToString(); string os = HParameters.GetParameterValue(o).ToString(); return !string.IsNullOrWhiteSpace(gs) && !string.IsNullOrWhiteSpace(os) && !gs.All(c => c == '0') && !os.All(c => c == '0') ; }
The code itself does not delete elements. The families are updated and that does change the element.
private bool ConvertParameters(Document doc) { // Load the Elements which will be updated. IEnumerable<Element> elements = this.GetAllWoononElements(doc); foreach (Element e in elements) { // what ever, exception iss thrown in the foreach. } }
// GetElementsWithGroepParameter returns all the Elements that have the shared parameter // KO_Groep. This is a legecy parameter which we know Elements uploaded to WOONON require. private IEnumerable<Element> GetAllWoononElements(Document doc) { var result = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .Where(q => this.ElementIsWoononElement(q)) ; return result; }
// We use the element name parameter. Don't use the Version parameter, because the // project information uses the project parameter as well. private bool ElementIsWoononElement(Element e) { Parameter name = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol(WoononParameters.WO_FAMILY_ELEMENT_NAME, e); if (name != null && name.HasValue) return true; Parameter g = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol("KO_Groep", e); Parameter o = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol("KO_Optienummer", e); if ((g == null || o == null) || (!g.HasValue || !o.HasValue)) return false; string gs = HParameters.GetParameterValue(g).ToString(); string os = HParameters.GetParameterValue(o).ToString(); return !string.IsNullOrWhiteSpace(gs) && !string.IsNullOrWhiteSpace(os) && !gs.All(c => c == '0') && !os.All(c => c == '0') ; }
Ok, i wrapped the foreach in a try catch block and see the exception being what you described:
"- $exception {"The iterator cannot proceed due to changes made to the Element table in Revit's database (typically, This can be the result of an Element deletion)."} Autodesk.Revit.Exceptions.InvalidOperationException"
I guess i'll have to check if the element is valid in ElementIsWoononElement
Ok, i wrapped the foreach in a try catch block and see the exception being what you described:
"- $exception {"The iterator cannot proceed due to changes made to the Element table in Revit's database (typically, This can be the result of an Element deletion)."} Autodesk.Revit.Exceptions.InvalidOperationException"
I guess i'll have to check if the element is valid in ElementIsWoononElement
I added isValidObject but the exception is still thrown... Any suggestions?
private bool ElementIsWoononElement(Element e) { if (!e.IsValidObject) return false; Parameter name = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol(WoononParameters.WO_FAMILY_ELEMENT_NAME, e); if (name != null && name.HasValue) return true; Parameter g = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol("KO_Groep", e); Parameter o = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol("KO_Optienummer", e); if ((g == null || o == null) || (!g.HasValue || !o.HasValue)) return false; string gs = HParameters.GetParameterValue(g).ToString(); string os = HParameters.GetParameterValue(o).ToString(); return !string.IsNullOrWhiteSpace(gs) && !string.IsNullOrWhiteSpace(os) && !gs.All(c => c == '0') && !os.All(c => c == '0') ; } }
I added isValidObject but the exception is still thrown... Any suggestions?
private bool ElementIsWoononElement(Element e) { if (!e.IsValidObject) return false; Parameter name = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol(WoononParameters.WO_FAMILY_ELEMENT_NAME, e); if (name != null && name.HasValue) return true; Parameter g = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol("KO_Groep", e); Parameter o = new RevitUtils.ParameterUtil().GetParameterFromFamilyInstanceOrSymbol("KO_Optienummer", e); if ((g == null || o == null) || (!g.HasValue || !o.HasValue)) return false; string gs = HParameters.GetParameterValue(g).ToString(); string os = HParameters.GetParameterValue(o).ToString(); return !string.IsNullOrWhiteSpace(gs) && !string.IsNullOrWhiteSpace(os) && !gs.All(c => c == '0') && !os.All(c => c == '0') ; } }
This seems to be exactly what im facing. Iter throug elements, and reload family.
This seems to be exactly what im facing. Iter throug elements, and reload family.
Hi Michal,
Without trying to analyse the issue too much, if you want to proceed in this manner and not have this issue, you could convert the ienumerable to a list and iterate through them in this manner:
for I as integer = 0 to (lst.count - 1) Dim elem as element=lst.item(i) 'check your element. next
It does look like you could simplify your code by using a parametervalueprovider..
-Matt
Hi Michal,
Without trying to analyse the issue too much, if you want to proceed in this manner and not have this issue, you could convert the ienumerable to a list and iterate through them in this manner:
for I as integer = 0 to (lst.count - 1) Dim elem as element=lst.item(i) 'check your element. next
It does look like you could simplify your code by using a parametervalueprovider..
-Matt
Can't find what you're looking for? Ask the community or share your knowledge.