A variable to pull out the amount of files from a category

Started by sinus, September 10, 2019, 08:30:03 PM

Previous topic - Next topic

sinus

Since Mario wrote "Feel free to create a feature request" I do it now.  ;D
It is not a very important thing, but would help me here and there.
We have a LOT of variables, how many keywords-categories are in a file and so on.

But there is not a variable, where I can simply pull out the amount of files, what are in a category.

Hence I ask for a variable to see the amount of files, what a category has, like we can see it in paranthesis in the category-view.
Exactly these numbers are, what I am looking for.
If this is easier, a sub-cat would be good enough, because I could then do some math, if I want have the top-category.

I would like to have such a variable for Design & Print, but also for other things.

This is related:
https://www.photools.com/community/index.php?topic=8709.msg61324#msg61324

As I said, of course, if I am the only one, who would like to have this, it is not worth to do it.
Because I can pull this out with some tricks, but not automatically (I have to write them out).

Best wishes from Switzerland! :-)
Markus

Carlo Didier

If you need that in a script, this should get it:
                    IMatch.get('v1/categories',{
                        path: 'FORMAT',
                        recursive: false,
                        fields:'id,name,children,filescount'
                    }).then(function(result) {
                        intFilesCount = result.categories[0].filesCount
                    });

Just replace 'FORMAT' with the category from which you want to start the count, like 'GEAR|LENS' or 'WHAT|Architecture|Castles', etc

Note that this works with the recursive option set to true or false. It always returns the grand total.

Mario

If you only need the number of files, don't request the names or child categories. Much faster.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Thanks Carlo and Mario

No, I would need it as variable, what works in VarToy.
Tried a lot of things, but as Mario in the other thread wrote, is surely correct:

There are no category-based variables. No variable which returns information about an arbitrary category in some form.


That is why I posted this question.  :D

I tried to find a way with an indirect route, no luck so far.



Best wishes from Switzerland! :-)
Markus

Mario

I would need to create an entire new subset of variables for this purpose.
Currently IMatch links all variables either to files or the application. Or, as a specialty, user-defined variables.

There are no variables which directly process categories, collections, timeline nodes, global attribute sets or similar.
I suppose there are very little use cases for any of these, and supporting them would complicate variable handling and maybe even impact variable performance (which then has an impact on many things in IMatch).

Let's see how many users also would like this type of variable by +1ing this.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Thanks Mario
for your answer. Very detailled to understand for me.

I think the same like you, not worth for only me or a handful of users.

Workaround for me:
I created for now some metadata - fields, what I do never use, e.g. {File.MD.PLUS::XMP\ImageCreator\ImageCreator\0}
About 20 different tags.

There BEFORE I must have access to the number of files in a category, I add manually the number in these fields.
Of course only for one image, means in the whole DB I have only say 50 images with these tags filled.

Then I can have with a variable direct access to these fields.
Works fine, though a bit work.
Best wishes from Switzerland! :-)
Markus

sinus

A short question:

Since it is now not possible to see the amount of files in a category:

If I select a category and select there all files in the file window, I can see the number of files in this category in the upper right corner of IMatch.
Is there a way to somehow read this number, perhaps with a variable?

What I'm trying to achieve is a way to read the number of files in a several categories and then write this number into different metadata fields.
At the moment I do this manually, but since the number of files in a category changes from time to time, it is a bit tedious in the long run.

A script would clearly be very good, Carlo, but that exceeds my possibilities, I have realized that I can't cope with Visal Basic without very, very, very much effort.
Best wishes from Switzerland! :-)
Markus

Mario

There are no variables which process categories on a global level.
For such special requirements, writing a small app is the best solution. IMatch apps are created using JavaScript, not Visual Basic. But you can also use any other programming language you know as long as it allows to call a web service (all modern languages do that).

To get the path and the number of files in the currently selected category, all you need is:



This calls the v1/categories endpoint, asking for the path and the number of files for the currently selected categories.

The response = await IMWS.get(...) does all the magic for you. When IMWS has responded, the variable response contains the data returned by IMWS. Simple as doing it in Basic.
You now can do whatever you want with the number of files, e.g. printing it to the console:

console.log( response.categories[0].filesCount );

A small sample file to get you started:

1. Download and extract the attached HTML file to your PC.
2. For testing purposes, copy it into the folder C:\ProgramData\photools.com\IMatch6\webroot\imatch\samples
3. Open your browser and type in this URL:

http://127.0.0.1:50519/imatch/samples/cat-test.html

Assuming the IMWS on your machine uses the default 50519 port.

This displays the name of the current category and the number of files it contains.
To count only the directly assigned number of files, changes filesCount to directfilescount.

Updating metadata or attributes can be just added to this code as needed.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Quote from: Mario on October 02, 2019, 01:29:11 PM
There are no variables which process categories on a global level.
For such special requirements, writing a small app is the best solution. IMatch apps are created using JavaScript, not Visual Basic.

Visual Basic! I wrote this, SORRY!!!  :-[ ::) ???

Of course JavaScript.
Tsss, I am getting old!  :o

Thanks a lot, really, for your answer.
Too bad, that I have to go away just not ... take pictures in a "banana ripening" (Bananenreiferei), there comes the bananas not ripe from the souther aereas, and in such very big halles the bananas does here ripe here (in controlled athmosphere), until they are ready for clients to buy.
I did not know this before.

Mario, I will study your answer, thank again!

If this works, it will help me a lot.
Best wishes from Switzerland! :-)
Markus

sinus

Hi Mario
WOW, it works!

FOR ME it is a kind of magic.
I see realy the wished output in my browser. (attached)

Thanks for this a lot!  :)

I will now try to add this output (I must have only the amount of files) into a metadata-field.
This will go some days, because JavaScript is still very strange for me.
But because your example is quite short, I hope, I can do it.

It is a kind of magic, really, I open my browser (what has finally nothing to do with IMatch) and voila, the informations is there.
I change the category and refresh the browser, and tac, again, the values are updated and very quickly.

Really cool!
Best wishes from Switzerland! :-)
Markus

Mario

This is easy to do as well.
Check out the code recipes on https://www.photools.com/dev-center/doc/imatch/tutorial-recipes.html, under the Updating Metadata headline.

Assuming you want to store a number (retrieved before from the selected category) into the headline tag of all selected files, all you need is:



This example calls the new function storeCount() after retrieving the information about the selected categories.
storeCount takes a number and updates the headline of all selected files with that number. If you want to update another tag, just change headline to the short code or full variable key, e.g. XMP::photoshop\TransmissionReference\TransmissionReference\0.

Note: I have omitted error handling to keep it short.

Tip: You can get the short codes and tag keys from the helpful Tag Info app:

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Quote from: Mario on October 03, 2019, 09:18:34 AM

If you want to update another tag, just change headline to the short code or full variable key, e.g. XMP::photoshop\TransmissionReference\TransmissionReference\0.

THANKS, Mario, again!!!

Super, it works, I have done like you wrote, took your code and did it, like in the help is written (change json, put in the correct path and so on).
It displays the info in the IMatch-Pane and it writes the amount of files into the headline.

Still magic, but fascinating, what can be done with scripting.  :)

One thing I do wrong or do not understand.

If I change the tag headline e.g. to TransmissionReference, like you wrote, then it works only in a special manner:
The taginfo show me this:

XMP::photoshop\TransmissionReference\TransmissionReference\0

But if I use this
           tag: 'XMP::photoshop\TransmissionReference\TransmissionReference\0',
it works NOT

it works only, if I use this here:

           tag: 'XMP::photoshop\\TransmissionReference\\TransmissionReference', 

I found this out only, because I used your link tot the IMatch Documentation:
tagdate: 'XMP::xmp\\ModifyDate\\ModifyDate',

There I saw these two back-slashes.  :D

I wanted only to remark this.
But you have solved my problem, Mario!
Thanks for the outstandig super-support!
Like always.  :)
Best wishes from Switzerland! :-)
Markus

Mario

The \ has a special meaning in JavaScript strings. You always need to use \\ if you actually mean \
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook