scripting "app.closeall()" doesn't close all documents

Discussion in 'Scripting and Programming' started by robert tremblay, Sep 3, 2018.

  1. robert tremblay

    robert tremblay Cyanogen Customer

    Joined:
    Aug 26, 2015
    Messages:
    32
    Hi all,

    I'm trying to write a VB program to combine colorimages and save the result in .jpg format.

    The problem comes whenever i want to clear maxim DL screen: applying close all doesn't work.
    See below:

    Dim dir As String
    Dim max As MaxIm.Document
    Dim theapp As Object
    Dim rdoc As Object
    Dim gdoc As Object
    Dim bdoc As Object
    theapp = New MaxIm.Application
    max = New MaxIm.Document
    dir = "C:\Users\\Documents\"
    trying to load RGB files
    Without using max.duplicate, only one file is loaded. why?????

    max.OpenFile(dir + "ngc7000-G-120-SUM-222450.fit")
    max.Duplicate()
    max.OpenFile(dir + "ngc7000-B-120-SUM-222450.fit")
    max.Duplicate()
    max.OpenFile(dir + "ngc7000-R-120-SUM-222450.fit")
    Dim AllDocs As MaxIm.Documents
    AllDocs = theapp.Documents
    ListBox1.Items.Add(Str(AllDocs.Count))
    rdoc = AllDocs.Item(1).displayname
    gdoc = AllDocs.Item(2).displayname
    bdoc = AllDocs.Item(3).displayname
    max.AlignImages(MaxIm.AlignType.mxAutoStarMatch, True, AllDocs)
    max.CombineColor(MaxIm.CombineColorType.mxRGB, True, rdoc, gdoc, bdoc)
    max.SaveFile(dir + "ngc7000-RGB", MaxIm.ImageFormatType.mxJPEG, True)
    Trying to close all opened documents
    theapp.closeall()
    Now, looking at maxim DL screen, NOT ALL files are closed as they still appear on maxim's main screen. (see attached screen: still showing 3 files instead of 4.???
    System.Runtime.InteropServices.Marshal.ReleaseComObject(max)
    End Sub
    clear skies,
    Robert
     

    Attached Files:

    • rgb.JPG
      rgb.JPG
      File size:
      48 KB
      Views:
      4
  2. Colin Haig

    Colin Haig Cyanogen Customer

    Joined:
    Oct 27, 2014
    Messages:
    1,417
    Robert, I'm just another customer.
    I haven't looked at your code in depthFor starters, your dir= is incorrect. You need to use your \ backslashes consistently. That may explain why it only loads one file, although am surprised it loads any as that is a bad path.
    You might want to upload the code as an attachment for others to play with.
     
  3. robert tremblay

    robert tremblay Cyanogen Customer

    Joined:
    Aug 26, 2015
    Messages:
    32

    Hi Colin,
    i found out that the use of alldocs.item(x).displayname creates the problem and keep maxim dl from closing all documents!
    Please look at the attached listing
     

    Attached Files:

  4. robert tremblay

    robert tremblay Cyanogen Customer

    Joined:
    Aug 26, 2015
    Messages:
    32
    problem solved:
    try Finalreleasecomobject instead.
     
  5. Doug

    Doug Staff Member

    Joined:
    Sep 25, 2014
    Messages:
    4,634
    We depend on Microsoft's COM infrastructure; if the access count is non-zero then the document will not unload.

    In general it is better to delete the references to the objects to close the documents. CloseAll is something of a last resort, and is useful in situations where documents created outside of COM need to be closed out.
     
  6. Bob Denny

    Bob Denny Cyanogen Customer

    Joined:
    Oct 12, 2014
    Messages:
    619
    Location:
    DC-3 Dreams, SP, Mesa, Arizona +1 480 396 9700
    I believe you are looking for Marshal.ReleaseComObject(), the Finalxxx call could pull the rug from under other existing references. I am traveling so I am drawing from memory!
     

Share This Page