Forum

Author Topic: 'NoneType' object has no attribute 'chunk'  (Read 2590 times)

3DWinter

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
'NoneType' object has no attribute 'chunk'
« on: November 16, 2020, 11:44:39 PM »
Hello Agisoft support,
I have worked for  six years with Photoscan and no Metashape, and have coded in python outside of the Agisoft environment for longer. Now I am taking my first steps using Methashape Python API, and I got stuck on what seems to be a straightforward first step, defining the document object and creating the chunk.  I have searched the forum as well to some extent on Stack Overflow and could not find a solution that would resolve my problem.

Basically, after I create a document and try to create a chunk,
Code: [Select]
Import Metashape
doc=Metashape.app.document
chunk=doc.chunk
I get following error:
Code: [Select]
AttributeError                            Traceback (most recent call last)
<ipython-input-2-e7bf1adf3fae> in <module>
      1 #create a processing parameter object
      2 doc=Metashape.app.document
----> 3 chunk=doc.chunk

AttributeError: 'NoneType' object has no attribute 'chunk'

So it seemes like the process of creating the document object is failing- is None. Though the manual states requirements are Python 3.5, I am using Python 3.7.6 becuase that was what I already have, and Python Wheel for Windows is labeled 1.6.5-cp35.cp36.cp37-none-win_amd64.whl, so I don't think that should be the problem.

thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13913
    • View Profile
Re: 'NoneType' object has no attribute 'chunk'
« Reply #1 on: November 17, 2020, 08:46:10 PM »
Hello 3DWinter,

Metashape.app.document returns the active project instance only for GUI mode, so if you want to create a new project using script run from the command line (in headless mode) you should use the following approach:

Code: [Select]
import Metashape
doc = Metashape.Document()
chunk = doc.addChunk()
...
Best regards,
Alexey Pasumansky,
Agisoft LLC

3DWinter

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: 'NoneType' object has no attribute 'chunk'
« Reply #2 on: November 17, 2020, 10:21:09 PM »
Thanks for that.

 I tried looking up references in the manual to working in headless mode and I found none. Even no mention of using Metashape.Document().

thanks