Autodesk.Revit.Exceptions.InvalidOperationException

Hi!

I get this message when I run RPS .It has happened many times in different files. What does it mean? How can I solve it?

Thank you!!

Hi @Martinez , welcome to the forum!

Unfortunately this is pyRevit forum, not RPS. You might want to reach RPS developers on their github issues page.

But the message seems quite self-explanatory, you’re trying to edit a model that is not open in write mode.

As per the pinned quickstart guide

And how do you expect we help you if we cannot have a look at the code and get some context?..

Hi Jean-Marc,

you are right. Sorry, I didn´t explain correct. I get this exception in a lot of exercises. But I don´t understand why. Thank u!!

start by removing these quotes in your definition attribute

The error continues…

The whole logic of your script is just weird to say the least.

Let me dumbify your code and write it in plain english:

  • Set the doc variable to the active document
  • Open a transaction to modify element in the active doc
  • collect all rooms
  • Start the transaction
  • create a definition to set the value of an element’s parameter
  • loop through rooms:
    • set the area variable to the room element Area value
    • calculate and set the variable occup_load
    • Set the value of the parameter Occupancy for the element room.Area (which is not an element in the revit DB)
  • Commit the transaction

What I think you want to do is set the value of the Occupancy of the room element to the occup_load value.

SetParameterByName(room, "Occupancy', occup_load)

you should have a look at the pep8 python convention and start using it, that would help you with code clarity. And also help you understand that you are mixing variable names with revitDB elements.

The def seems useless, especially at your level of understanding.

Just do this inside the loop:

room.LookupParameter("Occupancy", occup_load)