Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

InvalidOperationException at memory location

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
840 Views, 6 Replies

InvalidOperationException at memory location

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.

6 REPLIES 6
Message 2 of 7
matthew_taylor
in reply to: Anonymous

Hi Michal,
Do you delete elements in the iteration?
Post a code snippet. It's a piece of string (length issue) without it.

-Matt

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 3 of 7
Anonymous
in reply to: matthew_taylor

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')
            ;
        }
Message 4 of 7
Anonymous
in reply to: Anonymous

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

Message 5 of 7
Anonymous
in reply to: Anonymous

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')
            ;
        }
    }
Message 6 of 7
Anonymous
in reply to: Anonymous

This seems to be exactly what im facing. Iter throug elements, and reload family.

 

http://adndevblog.typepad.com/aec/2015/03/revitapido-not-add-or-delete-elements-when-iterating-docum...

Message 7 of 7
matthew_taylor
in reply to: Anonymous

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


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community