Can't save doc opened through OpenDocumentFile method

Hi. GHPython throws the following exception when I try to programatically save documents I’m tinkering with:

Runtime error (InvalidOperationException): Saving is not allowed in the current application mode.

I am suspecting it’s not really a bug and has more to do with the GH window being open at the time of executing the script, since I was able to get it working just by opening the GHPython script window, then clicking outside the GH Window so only the script window is floating but GH is no longer visible (usually bothering behavior, but looks like it’s helping here), then running the script by clicking either “Test” or “OK”. I can submit the code if necessary.

Any plans to make saving and similar actions compatible with running the GH window at the same time? It’s not such a big deal right now since I can just make it work the way I described, but figured this behavior might be worth a look in the future.

Also, it’s such a shame that the Revit API itself seems to be limited regarding automated link creation (Group > Link conversion, or Shared Site setup and modification). I’m trying to develop a script which will create specific named locations in linked documents according to GH Planes in order to keep tidied-up information of their position and angle deviation to True North, but it like there’s some API functionality I’m missing or simply haven’t found yet. Not RiR’s problem, of course, but I just thought I could say it out loud. Will probably submit the idea if it’s not implemented in the API’s next release.

The .Save() method currently does not work inside the Grasshopper since the definition is updated by an event handler, triggered from Revit and thus document is marked as Editable and can not be saved. I have filed an issue for this:

Regarding your question about project locations, they are represented by DB.ProjectLocation which is a subclass of DB.Element. I think you can use the DB.ElementTransformUtils.CopyElements() method to copy the desired project location to another document.

Hi again!

It seems like the latest RiR update, by running in a non-modal UI, won’t let me do the trick I previously mentioned anymore. I never thought I would find myself complaining about it, but here I am… any idea on how to make commands like Save compatible with this environment? I guess it should be possible to do so, since I suspect the Family.New component is able to automate family document creation, modification and saving on the go, but I don’t really understand how (I am considering opening a different thread in order to ask about that).

Anyway, I am always grateful for the hard work put into RiR development. Keep it up!

Hi again @kike @Japhy @eirannejad ,

I’ve been trying to make my script work again, but to no avail.
The Save Document component works now, although if I try to reproduce its functionality through a custom GHPython component I get the same " Saving is not allowed in the current application mode " error as before.
I’m trying to close the newly created, modified and saved documents (they don’t show up in the UI, which makes it impossible to close them manually as far as I know), but the following error appears:
image

I’ve tested my definition bypassing the Save Document component, and it seems to work as long as I open, modify and close the documents in a single run (that is, I can’t create and modify, then later activate the node responsible for closing these documents). This way, unfortunately, I can’t get to save them which is what I need in order to create link instances of these documents.

I’ve tried running the Save Document component and the custom Close Document in parallel, in a single run, but what happens is that the documents close before I get the chance to save them, and thus the Save Document component throws an error.

Here is my GH definition:

Populate + Name Positions.gh (42.8 KB)

If anyone has any idea on how I could solve this problem, I’d be immensely grateful. Thanks.

P.S.: Maybe it could be useful to add a boolean parameter to the Save Document component which indicates whether the file should be closed upon saving?