Forum

Author Topic: Import model script help  (Read 1133 times)

MetaUser555

  • Newbie
  • *
  • Posts: 29
    • View Profile
Import model script help
« on: October 18, 2024, 11:39:52 PM »
Hello there,
I have this script

import Metashape
import os

# Access the current project document
doc = Metashape.app.document

# Get the project folder and construct the export path
project_folder = doc.path
export_folder = os.path.join(project_folder, "..", "export")

# Loop through all chunks in the project
for chunk in doc.chunks:
    # Construct the model path using the chunk label
    model_path = os.path.join(export_folder, f"{chunk.label}.abc")
    model_format = Metashape.ModelFormatABC

    # Import the model into the current chunk
    chunk.importModel(model_path, format=model_format)

it runs but gives me an error, saying:
2024-10-18 16:33:45 ImportModel: path = N:/Projects/projectFiles/model.psx\..\export\model.abc, format = ModelFormatABC
2024-10-18 16:33:45 Finished processing in 0.001 sec (exit code 0)
2024-10-18 16:33:45 Traceback (most recent call last):
2024-10-18 16:33:45   File "X:/metashape/impmod.py", line 18, in <module>
2024-10-18 16:33:45     chunk.importModel(model_path, format=model_format)
2024-10-18 16:33:45 Exception: IArchive::IArchive( iFileName )
2024-10-18 16:33:45 ERROR: EXCEPTION:
2024-10-18 16:33:45 Could not open as Ogawa file: N:/Projects/projectFiles/model.psx\..\export\model.abc
2024-10-18 16:33:45 Error: IArchive::IArchive( iFileName )
2024-10-18 16:33:45 ERROR: EXCEPTION:
2024-10-18 16:33:45 Could not open as Ogawa file: N:/Projects/projectFiles/model.psx\..\export\model.abc


can you tell me what I'm doing wrong?
cheers

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15168
    • View Profile
Re: Import model script help
« Reply #1 on: October 21, 2024, 12:44:20 PM »
Hello MetaUser555,

Looks like the paths are created incorrectly in the script. Instead of project folder you have path to the project file, so as a result the export folder path is incorrect:
"N:/Projects/projectFiles/model.psx\..\export\model.abc"
Best regards,
Alexey Pasumansky,
Agisoft LLC

MetaUser555

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Import model script help
« Reply #2 on: October 21, 2024, 06:00:24 PM »
Thanks Alexey!
We fixed it a different way to this so all good
As a side note, would you be able to add 'import model' to the batch process ui? It's not there but would be very useful
thanks for all the help