Forum

Author Topic: Undo via Python?  (Read 3867 times)

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Undo via Python?
« on: October 17, 2021, 03:55:09 PM »
Is it possible to Undo/Redo via python?

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Undo via Python?
« Reply #1 on: October 21, 2021, 02:38:07 PM »
Pretty please?  :-*

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15067
    • View Profile
Re: Undo via Python?
« Reply #2 on: October 21, 2021, 05:27:13 PM »
Hello wojtek,

Which operations do you need to Undo via Python?
Best regards,
Alexey Pasumansky,
Agisoft LLC

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Undo via Python?
« Reply #3 on: October 22, 2021, 12:08:57 PM »
Hello wojtek,

Which operations do you need to Undo via Python?

Essentially what I'm doing is the following:

1. Select a section of a model I want to edit in an external package
2. Crop selection (works via script)
3. Export & Import to the external package (works via script)
after editing:
4. Import edited section as a new model (works via script)
5. Go back to the original model (works via script)
6. Undo the Cropping
7. Delete original selection

So I'm stuck at 6 and have been doing this part manually instead.

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Undo via Python?
« Reply #4 on: November 30, 2021, 05:16:15 PM »
Hey, any hope for Undo in the api for the next 1.8.0 build? :) Pretty please :)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15067
    • View Profile
Re: Undo via Python?
« Reply #5 on: December 07, 2021, 06:29:54 PM »
Hello wojtek,

It seems that implementation of undo/redo commands via API wouldn't be straightforward, so I can suggest to consider some workaround for your task, i.e. duplicate the original model and then, when performing the selection of mesh faces to be cropped, apply the same face selection to the duplicated model (it should have the same order of the faces), then crop faces in the original model and remove faces in the duplicated model.
Best regards,
Alexey Pasumansky,
Agisoft LLC

wojtek

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: Undo via Python?
« Reply #6 on: December 12, 2021, 11:23:16 AM »
Hello wojtek,

It seems that implementation of undo/redo commands via API wouldn't be straightforward, so I can suggest to consider some workaround for your task, i.e. duplicate the original model and then, when performing the selection of mesh faces to be cropped, apply the same face selection to the duplicated model (it should have the same order of the faces), then crop faces in the original model and remove faces in the duplicated model.

Thanks for looking into it, I'll try your workaround though I assume it will be pretty slow with big geometry (duplication takes a while) so undo+delete manually might still make more sense.

Seboon

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Undo via Python?
« Reply #7 on: December 12, 2021, 01:48:00 PM »
Hello Wojtek,

Try this in your script :

for widget in QtWidgets.QApplication.allWidgets():
    if widget.inherits("QToolBar") and widget.windowTitle() != "Actions":
        if widget.isEnabled():
            widget.actions()[4].trigger()

Please, let me know if it worked.
« Last Edit: December 12, 2021, 01:50:49 PM by Seboon »
S.Poudroux
Archaeologist - Topographer - Drone remote pilot