Author Topic: AddFile to collection fails  (Read 2694 times)

tazman

  • New Members
  • *
  • Posts: 5
AddFile to collection fails
« on: September 13, 2016, 09:18:16 PM »
Hi,

I am trying to write a script that assigns a red label to all files in the current file window with a certain string in the name. 

Everything seems to be running ok until the script comes to the AddFile statement for the collection. Here the script stops with a beep/sound. No error message is displayed.

Both, the file already in the collection as well as the file to be added look the same when watched:
1: f -> [File@0x4081b75c]
1: f2 -> [File@0x3befeb3c]

f adds without problem to mybucket

Changing the declaration of f from File to IMatch.File did not do anything.

Thanks for pointing me in the right direction on how to make this work.

Best regards,

Thomas

Code: [Select]
'#Language "WWB-COM"
Option Explicit

Sub Main
Dim cnt As Integer
Dim Files As Files
Dim f As IMatch.File
Dim f2 As IMatch.File
Dim mybucket As New Files
Dim col As Collection
Dim S As String

       Set Files = Application.GetFileWindow(imfwtCurrent).Files
Set col = Database.Collections.Get(ctypeLabel,"Red")

        If Not col Is Nothing Then   
          Set f2 = col.Files(1)
End If

For Each f In Files
If InStr(f.FileName, "HDR") > 0 Or InStr(f.FileName, "BW") > 0 Or InStr(f.FileName, "Panorama") > 0 Then
mybucket.AddFile f
col.AddFile(f)
End If
Next
End Sub
« Last Edit: September 13, 2016, 09:21:02 PM by tazman »

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29760
Re: AddFile to collection fails
« Reply #1 on: September 13, 2016, 09:49:51 PM »
The error message in the status bar of the script editor is?

tazman

  • New Members
  • *
  • Posts: 5
Re: AddFile to collection fails
« Reply #2 on: September 14, 2016, 12:07:20 PM »
(&H80004005) [45013] '#RM.STR.MISSING: 'PTR_ERRMSG_35013"

Thanks!

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29760
Re: AddFile to collection fails
« Reply #3 on: September 14, 2016, 04:44:15 PM »
This does not look like an error message. I meant the status bar in the script editor.


It will also highlight the line where the error happens.

Your statement

Set f2 = col.Files(1)

will fail when the collection is empty, for example.
« Last Edit: September 14, 2016, 04:51:37 PM by Mario »

tazman

  • New Members
  • *
  • Posts: 5
Re: AddFile to collection fails
« Reply #4 on: September 14, 2016, 05:22:41 PM »
Hi Mario,

Agreed that the set of f2 will fail. I just included it to test how a member of that collection looks like.

The error message i pasted is from the location you are referring to. See screenshot.


Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29760
Re: AddFile to collection fails
« Reply #5 on: September 14, 2016, 06:04:54 PM »
This looks like either f or col is invalid. Did you check the IMatch log file for additional details?

ubacher

  • Oldtimer
  • ****
  • Posts: 2358
Re: AddFile to collection fails
« Reply #6 on: September 14, 2016, 09:37:26 PM »
Rather than adding the file to the collection you could just use:'

Code: [Select]
f.Label = "Red" to assign the red label to a file (and thus add it to the collection)

Much simpler you will agree.

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29760
Re: AddFile to collection fails
« Reply #7 on: September 15, 2016, 11:19:12 AM »
Ah, silly me!

The label collection is not mutable (cannot be changed from a script). It is build dynamically from the labels you assign to files (same for the rating collection).
If you change the label as ubacher explains above, the collection updates automatically. Same for the Rating property of files.

See the help topic for the Collection class to see which collections are mutable. You can also use the Mutable property of the collection to check if you can modify it,
« Last Edit: September 15, 2016, 11:21:47 AM by Mario »

tazman

  • New Members
  • *
  • Posts: 5
Re: AddFile to collection fails
« Reply #8 on: September 17, 2016, 05:42:02 AM »
You are right. I actually saw the mutable attribute but didn't read it properly. Labels are mentioned there as non-mutable. I guess I must have thought that they are because logically they should be writeable, Other than e.g. recent files.

Thanks to ubacher for the alternative. I can confirm that this works.

For a while I suspected a more serious issue as imatch crashed when closing followed by a blue screen. I am not sure if those two are related. The blue screen error message points to an USB device problem.

I tried to attach the crash dump file but the message does not post with it. I will see if I can mail it to you (the mail function on the crash window produced an IMAP error).

Thanks for your help!

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29760
Re: AddFile to collection fails
« Reply #9 on: September 17, 2016, 08:16:57 AM »
An application like IMatch is very unlikely to cause a blue screen. Maybe in Windows XP, but not in Windows 10.
If the blue screen refers to an USB device, that's where the problem happened.

If you experience a Windows crash message when closing Windows and you have Windows 10 with update 2016.7 installed, please update to IMatch 5.7.