Modfiy, SaveAs and Rollback

BenoitE&A
Collaborator
Collaborator

Modfiy, SaveAs and Rollback

BenoitE&A
Collaborator
Collaborator

Hey,

We are creating an add-that would do the following for a given set of areas:

1) modifies the document according to the given area

2) Save the modified document to a new document

3) Rollback the changes

Then switch to the next area of the set.

 

I have tried the following ways, all based on the idea of a TransactionGroup that I rollback at the end of step 3. But none of them work:

Idea 1 : use SaveAs. 

Pb : SaveAs is not authorized in an open Transaction or TransactionGroup

Idea 2 : use a PostCommand with SaveAsLibraryGroup

Pb : the postCommand is executed once the flow is terminated so that I can not Rollback my TransactionGroup.

 

Any idea / suggestions ?

This item is similar to this one :

https://forums.autodesk.com/t5/revit-api-forum/modeless-rollback-a-transaction-after-commit/m-p/8127...

 

Benoit

 


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Reply
Accepted solutions (2)
790 Views
5 Replies
Replies (5)

stever66
Advisor
Advisor
Accepted solution

I'm not sure exactly what you are trying to accomplish, but once you have done a "Save-as", I don't think you can go back and undo a transaction on the previous file.

 

Maybe try a different workflow?  Like copy the original file (or open and do a Save-As), open the copy, make your changes and save, and then just reopen the original unchanged document and repeat?

 

I'm also not sure offhand what you can do without a post command, so I may be way off here.

 

 

 

0 Likes

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Benoit,

 

Thank you for your query.

 

  • Save the original document A.
  • Make modifications and save as B.
  • Open A.
  • Close B.
  • Make modifications and save as C.
  • Open A.
  • Close C.
  • Et cetera ad infinitum.

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

BenoitE&A
Collaborator
Collaborator

Hi Jeremy, hi Stever,

You are both right, the best way is to change the workflow : save before, than modify.

Once answered, some questions look dumb...

The Rollback idea was cool though...

Thanks 

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes

stever66
Advisor
Advisor

Its definitely not a dumb question... I'm sure rolling back the transaction would have been a lot faster than all the open and close business if there was a way to make that work.

 

I did have another thought, but  since I have a pretty limited knowledge of C#, I'm not sure there is a way to make this work either.

 

Is there any way to make a copy of the document in C#?  I'm pretty sure something as simple as this won't work:

 

Document doc1 = uiDoc.Document;

Document doc2 = uiDoc.Document;

 

That obviously won't work because both doc1 & doc2 are just references to the same document. 

 

But if you could do something that is the equivalent of:

 

Document doc2 = doc1 by value;

 

You might be able to start the transaction on doc2 and save it.  Then go back to doc1 and repeat.

 

I'm just not sure C# can really provide a real copy of a document variable without just creating 2 references to the same object.  And you might also be running into the postcommand problem again.

0 Likes

BenoitE&A
Collaborator
Collaborator

Hi Stever,

Thank you for the idea. Yes you can create a Document which is only a pointer to the same document (Document newDoc = uidoc.Document;). But I am not sure whether you can modify this document without saving it (writing in memory), and saving is not allowed as long as your Transactions are not closed.

 

I am back to my original question though. The integral copy of the document then modify it is a real pain for what I want to do (slow, long, and not reliable). So I would really like to do my previous hint : 

1) modify the document

2) extract the modified geometry (the only way I found was with the PostCommand SaveAsLibraryGroup)

3) cancel the modifications

Would anybody have an idea how to do this ?

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes