AllDocs.Count 0 after first guide image taken

Discussion in 'Scripting and Programming' started by Richard Gray, Jan 7, 2020.

  1. Richard Gray

    Richard Gray Standard User

    Joined:
    Nov 29, 2014
    Messages:
    21
    Hi,
    I have a new query about AllDocs.Count, why it remains zero even after the first guide image is taken. Consider the following code (in python) which follows very closely an example in the documentation

    import win32com.client
    import pythoncom
    import time

    Cam = win32com.client.Dispatch("MaxIm.CCDCamera")

    Cam.LinkEnabled = True
    Cam.DisableAutoShutdown = True

    MApp = win32com.client.Dispatch("MaxIm.Application")
    AllDocs = MApp.Documents

    Cam.GuiderExpose(1.0)
    while(Cam.GuiderRunning):
    time.sleep(1)

    time.sleep(2)

    print(str(AllDocs.Count))

    If we start with Maxim DL newly opened, with no image displayed, the first time this program is run, AllDocs.Count, after the guide image has been taken and displayed, is still zero. It should be 1. Run the code a second time, and now it is 1, as it should be. The difficulty comes with that initial zero. I have an application which requires saving the guide image for image analysis. My program cannot find the first guide image, and so a second must be taken. While not a serious problem, it requires a work around which should be unnecessary.

    I encounter this problem with real cameras, but it also occurs with the dual-chip simulator.

    I would appreciate it if you either correct this apparent bug or explain to me why the program works as it does.

    Richard
     
  2. Adam Robichaud

    Adam Robichaud Staff Member

    Joined:
    Sep 29, 2014
    Messages:
    775
    Location:
    Ottawa
    Works for me... Are you sure the image has time to download and display in MaxIm before you try reading the document count?
     
  3. Richard Gray

    Richard Gray Standard User

    Joined:
    Nov 29, 2014
    Messages:
    21
    Yes, that is what that extra time.sleep(2) is about. I can change that to any delay, or have the program go off and do other stuff. The result is the same.
     
  4. Richard Gray

    Richard Gray Standard User

    Joined:
    Nov 29, 2014
    Messages:
    21
    Incidently, the first time.sleep(1) should be indented so that it is inside the while(Cam.GuiderRunning) loop. Your forum software seems to remove indents.
     
  5. Adam Robichaud

    Adam Robichaud Staff Member

    Joined:
    Sep 29, 2014
    Messages:
    775
    Location:
    Ottawa
    I had about 5 seconds delay between GuiderExpose() and AllDocs.Count(), and it worked as intended. The only thing I can see in your source code (though this might be a quirk of Python) is that IDocuments::Count is a method, not a property. I don't know if accessing a method as a property can lead to undefined behavior from Python. All I know is that it works in C#.

    re. tab removal: that's standard for WYSIWYG editors. Sadly, not a lot of forums have baked-in support for sharing source code.
     

Share This Page