Forum

Author Topic: Auto process on start  (Read 6000 times)

Guillaume

  • Newbie
  • *
  • Posts: 7
    • View Profile
Auto process on start
« on: February 24, 2014, 04:51:38 PM »
Hi,

I wrote script what I placed in "Agisoft\PhotoScan Pro\scripts\" for it run on start.
When I launch PhotoScan I have an error on this script but when I launch this script in consol it's run normaly.

Code: [Select]
def import_photos() :
global repertoire_de_travail
global document

repertoire_photos = repertoire_de_travail+'/Photos/'
liste_photos = os.listdir(repertoire_photos)

# Creation du chunk
my_chunk = PhotoScan.Chunk()
my_chunk.label = "Guigui_Chunk"


for nom_photo in liste_photos :
if my_chunk.cameras.add(repertoire_photos + nom_photo) :
my_chunk.cameras.remove((len(my_chunk.cameras)) - 1)
print(nom_photo, " - imported")
else :
print(nom_photo, " - erreur")
PhotoScan.app.update()

# Creation du document et ajout du chunk
document = PhotoScan.app.document
my_chunk.enabled = True
document.chunks.add(my_chunk) # ERROR ON THIS LINE
return

This is because access to PhotoScan.app.document is blocked for autorun scripts...
The support suggest me to use custom menu item and bind all functionality to this custom option but I need to execute (Align / Optimization / Build mesh) automaticly when I open PhotoScan.


Chicane5

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Auto process on start
« Reply #1 on: March 12, 2014, 07:39:37 PM »
Have support confirmed this functionality is for sure deprecated? It does seem like trying to grab:
Code: [Select]
doc = PhotoScan.Application.documentfrom a script that autoruns on startup from your 'Scripts' directory does indeed return None.

The workaround of
Code: [Select]
newdoc = PhotoScan.Document()
PhotoScan.Application.document = newdoc

fails as the document attribute of the Application object is read only...

I guess the only way, as suggested, is to place the script under a custom menu item and have the user start it from there. Shame to lose some degree of automation though :(


wp_Guillaume

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Auto process on start
« Reply #2 on: April 16, 2014, 07:26:31 PM »
I'm facing this issue too in an automation process.

Does someone found any workaround to access PhotoScan.Application.document at startup ?
It should be a priority feature request for the dev team ;-)

best regards.

mcstieg

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Auto process on start
« Reply #3 on: August 09, 2020, 09:04:41 AM »
Same problem with my script. Found no workaround till now.

Script works fine via "run script" but right after Metashape starts it seems to be unable to open doc and create chunk ...
Please help!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14765
    • View Profile
Re: Auto process on start
« Reply #4 on: August 09, 2020, 07:19:23 PM »
Please provide additional information regarding the issue.

If you need to open/create some project at the application start automatically (via auto-run scripts) you should use the following concept:

Code: [Select]
doc = Metashape.Document()
doc.save(...)

doc.open(...)

chunk = doc.addChunk()
Best regards,
Alexey Pasumansky,
Agisoft LLC

mcstieg

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Auto process on start
« Reply #5 on: August 10, 2020, 07:36:30 AM »
Thank you for that!
Do I really need to save and open the project to start working?

When launching my python code manually I don't...

[edit]
Code: [Select]
                test_project = r"E:\Arbeitsordner\Test\Test.psx"
                doc = Metashape.Document()
                doc.addChunk()
                doc.save(test_project)
                doc.open(test_project)
                doc.addChunk()
                chunk = doc.chunk

                [...my functions for startup...]

--> no chunk is open when my code launches.
--> In GUI the add-chunk-button is greyed out as you can see in the screenshot.

Hopefully you can help!
« Last Edit: August 10, 2020, 07:45:39 AM by mcstieg »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14765
    • View Profile
Re: Auto process on start
« Reply #6 on: August 10, 2020, 12:54:18 PM »
Hello mcstieg,

Auto-start scripts do not provide access to the active application instance (Metashape.app.document). But the approach mentioned above allows to process the data in the background and save the project.
Best regards,
Alexey Pasumansky,
Agisoft LLC

mcstieg

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: Auto process on start
« Reply #7 on: August 10, 2020, 01:14:13 PM »
Hello Alexey!

Is it possible to fix that in one of the next versions?
Thank you  ;D