Author Topic: How to collect files to create a stack  (Read 2813 times)

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1632
How to collect files to create a stack
« on: March 04, 2016, 08:16:24 PM »
I'm trying to automate a certain type of stacking by script.
Code: [Select]
Sub Categorize_Parts (img As IFile , dest_cat As Category)

Dim comp_min As String
Dim comp_max As String
Dim n As Integer

Dim imdb As Database
Set imdb = Application.Database

Dim im As File
Dim StackFiles As Files
Dim newStack As IMStack

comp_min = UCase$(Left(img.Name, 12))
comp_max = UCase$(Left(img.Name,  9) & Mid(img.Name, 14,3))

Debug.Print "From " & comp_min & " to " & comp_max

n = 0
For Each im In imdb.Files
If ((im.Name = Left(im.Name,12)) And (UCase$(im.Name) >= comp_min) And (UCase$(im.Name) <= comp_max)) Then
Debug.Print im.Name & " is part of " & img.Name
dest_cat.AssignFile im
StackFiles.AddFile im
n = n + 1
End If
Next im

If (n > 0) Then
Set newStack = Database.CreateStack StackFiles,img
End If

End Sub

But I get an error "(10094) ActiveX Automation Object var is 'Nothing' when I try to add a file to a Files object at this line:
Code: [Select]
StackFiles.AddFile im
See attached screenshot of the code with the error. I can't find out what the problem is.

[attachment deleted by admin]

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 27473
Re: How to collect files to create a stack
« Reply #1 on: March 05, 2016, 08:22:59 AM »
You must new StackFiles, not just declare a variable.

dim StackFiles as new Files

If you check StackFiles it will be nothing (NULL) in your script

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1632
Re: How to collect files to create a stack
« Reply #2 on: March 05, 2016, 09:22:51 AM »
Thanks Mario!
Somehow I supposed that by declaring the variable it would be "ready to use" as other variables too.
Works like a charm now!

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1632
Re: How to collect files to create a stack
« Reply #3 on: March 05, 2016, 09:38:14 AM »
Ah, problem: A stack is created, but it shows zero members and I can't un-stack, expand or delete stack ...
And the stacked images are hidden ...

[attachment deleted by admin]

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1632
Re: How to collect files to create a stack
« Reply #4 on: March 05, 2016, 10:52:05 AM »
Here's the log file (debug mode).

[attachment deleted by admin]

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 27473
Re: How to collect files to create a stack
« Reply #5 on: March 05, 2016, 11:14:38 AM »
Somehow I supposed that by declaring the variable it would be "ready to use" as other variables too.
That is standard Basic syntax for variables. Please refresh your know-how about variables, objects ans suchlike.

Your other question:

How many members does IMatch show for the stack?
What does the stack panel show?
Maybe you have just created a stack with only the top?

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1632
Re: How to collect files to create a stack
« Reply #6 on: March 05, 2016, 04:53:52 PM »
iMatch shows zero members (see my screenshot on previous post).
Open stack in viewer does nothing (the viewer doesn't open).

I'm definetely adding all the images, as they disappear from the file window.

Here's the current code and it's output:
Code: [Select]
Sub Categorize_Parts (img As IFile , dest_cat As Category)

Dim comp_min As String
Dim comp_max As String
Dim n As Integer

Dim imdb As Database
Set imdb = Application.Database

Dim im As File
Dim StackFiles As New Files
Dim newStack As IMStack

comp_min = UCase$(Left(img.Name, 12))
comp_max = UCase$(Left(img.Name,  9) & Mid(img.Name, 14,3))

Debug.Print "From " & comp_min & " to " & comp_max

n = 0
For Each im In imdb.Files
If ((im.Name = Left(im.Name,12)) And (UCase$(im.Name) >= comp_min) And (UCase$(im.Name) <= comp_max)) Then
Debug.Print im.Name & " is part of " & img.Name
dest_cat.AssignFile im
Debug.Print "Adding " & im.Name & " to stack"
StackFiles.AddFile im
n = n + 1
End If
Next im

If (n > 0) Then
Debug.Print "Creating stack With " & n & " images plus top image " & img.Name
Set newStack = Database.CreateStack StackFiles,img
End If

End Sub

Code: [Select]
From D20150624152 to D20150624155
D20150624152 is part of D20150624152-155_stitched
Adding D20150624152 to stack
D20150624153 is part of D20150624152-155_stitched
Adding D20150624153 to stack
D20150624154 is part of D20150624152-155_stitched
Adding D20150624154 to stack
D20150624155 is part of D20150624152-155_stitched
Adding D20150624155 to stack
Creating stack With 4 images plus top image D20150624152-155_stitched

The only way to get back to normal is to remove the top image from the database and then rescan the folder to get all images back.

[attachment deleted by admin]

sinus

  • Global Moderator
  • *****
  • Posts: 4254
  • IMatch-User since 2001 (IMatch 3.6)
Re: How to collect files to create a stack
« Reply #7 on: March 08, 2016, 08:58:18 AM »
Hi Carlo

Sorry, I did not understand, what are you trying to create? For what?
What kind of stacking do you use (automatic, manual)?

I am asking, because I work a lot with stacking (Automatic normal stacks, and version stacks).

I am using only one scripts:

- select a top file from a normal stack, let run the script. The script expands the stack, select all members, goes into a special category, empty this cat, assign all stack-members to this cat, and finally goes to that category. There I can "analyse" all the files in the stack. Another click on the script simply collapses the stack again.

 
Best wishes from Switzerland! :-)
Markus

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1632
Re: How to collect files to create a stack
« Reply #8 on: March 08, 2016, 10:25:42 AM »
Markus, this is actually to become part of my "new/modified image event" script.

When I have stitched images or an HDR from several images, the resulting file is named, for example, like this: D20160117035-037_pano.TIF (or ..._HDR.TIF in case of an HDR) which means it is made from images D20160117035, D20160117036 and D20160117037 (normally DNGs).
Now when such a new composite file is detected, I want to automatically stack it with the component images:
D20160117035-037.TIF = top of stack
D20160117035.DNG, D20160117036.DNG, D20160117037.DNG = parts of the stack.
So, I actually create a new stack.
The stack is created and the component images are hidden in the stack, but iMatch displays the stack as having 0 images and I can't do any stack operations on it. Maybe a bug. Or there's still something missing in my script.

sinus

  • Global Moderator
  • *****
  • Posts: 4254
  • IMatch-User since 2001 (IMatch 3.6)
Re: How to collect files to create a stack
« Reply #9 on: March 08, 2016, 11:49:24 AM »
Thanks, Carlo, interesting.

The auto-stack-option is not of interest for you? Maybe this could be a good thing for you, specialy because panos are, I guess, mostly taken in a short period of time.
Best wishes from Switzerland! :-)
Markus

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1632
Re: How to collect files to create a stack
« Reply #10 on: March 08, 2016, 03:35:21 PM »
I can't imagine how to auto-stack, based on my file naming.

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1632
Re: How to collect files to create a stack
« Reply #11 on: March 08, 2016, 04:09:36 PM »
... panos are, I guess, mostly taken in a short period of time.
They probably are, but that's not a foolproof way to identify those images. There may be other images falling in the same time frame without being part of the pano/HDR (maybe from a second camera), or some images may fall out of the time frame but belong to the pano/HDR (because I had a pause during the shooting). Neither of the auto-stacking options would be guaranteed to be 100% accurate. And if it's not 100% correct, I might as well do the stack manually as that wouldn't take more time than to control, and maybe correct, the auto-stacking.

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1632
SOLVED! Re: How to collect files to create a stack
« Reply #12 on: March 08, 2016, 04:37:33 PM »
I found it!

What I didn't get from the documentation was that I had to add the top image to the list of images in the stack before creating the stack and specifying it as the top image:

Sub Categorize_Parts (img As File , dest_cat As Category)

   Dim comp_min As String
   Dim comp_max As String
   Dim n As Integer

   Dim imdb As Database
   Set imdb = Application.Database

   Dim im As File
   Dim StackFiles As New Files
   Dim newStack As IMStack

   StackFiles.AddFile img

   comp_min = UCase$(Left(img.Name, 12))
   comp_max = UCase$(Left(img.Name,  9) & Mid(img.Name, 14,3))

   Debug.Print "From " & comp_min & " to " & comp_max

   n = 0
   For Each im In imdb.Files
      If ((im.Name = Left(im.Name,12)) And (UCase$(im.Name) >= comp_min) And (UCase$(im.Name) <= comp_max)) Then
         Debug.Print im.Name & " is part of " & img.Name
         dest_cat.AssignFile im
         Debug.Print "Adding " & im.Name & " to stack"
         StackFiles.AddFile im
         n = n + 1
      End If
   Next im

   If (n > 0) Then
      Debug.Print "Creating stack With " & n & " images plus top image " & img.Name
      Set newStack = Database.CreateStack StackFiles,img
   End If

End Sub


sinus

  • Global Moderator
  • *****
  • Posts: 4254
  • IMatch-User since 2001 (IMatch 3.6)
Re: How to collect files to create a stack
« Reply #13 on: March 08, 2016, 05:01:00 PM »
Congratulaton! Well done!  :)
Best wishes from Switzerland! :-)
Markus