agisoft-llc / metashape-scripts

Python scripts for Metashape (former PhotoScan)
MIT License
385 stars 206 forks source link

Libraries imported in script can't access metashape #22

Closed ahalota closed 4 years ago

ahalota commented 4 years ago

I'm trying to create a set of scripts, with one "metashape_util.py" script which is loaded in each of my individual scripts so that I don't have to rewrite much of the code

One big issue I am running into now is that if for example "toolset1.py" has the following code:

import metashape_util

and "metashape_util.py" has the following code:

found_major_version = ".".join(Metashape.app.version.split('.')[:2])

Then when I load "metashape_util.py" with the load script button in the console GUI, I get this error:

2020-03-19 21:44:57 Traceback (most recent call last): 2020-03-19 21:44:57 File "[...]/src/metashape_gliht_tools.py", line 20, in 2020-03-19 21:44:57 import metashape_util as mu 2020-03-19 21:44:57 File "[...]/src/metashape_util.py", line 8, in 2020-03-19 21:44:57 found_major_version = ".".join(Metashape.app.version.split('.')[:2]) #1.5 or 1.6 2020-03-19 21:44:57 NameError: name 'Metashape' is not defined 2020-03-19 21:44:57 Error: name 'Metashape' is not defined

Is there any suggested work around for this?

PolarNick239 commented 4 years ago

Does "metashape_util.py" contain line import Metashape above found_major_version = ...?

PolarNick239 commented 4 years ago

Feel free to reopen the issue if needed.