How to print category structure?

Started by Panther, August 08, 2016, 02:47:12 AM

Previous topic - Next topic

Panther

I've gotten the hang of exporting my category list/hierarchy from one of my databases and importing it into another database, BUT I haven't been able to figure out how to do what seems like it should be fairly simple, i.e., print the category list from inside iMatch or open the exported .imcsx file iMatch creates into something that will create a usable list that I could then print from that other program.   I'd like to be able to print out my category structure and the one my wife is using and compare them side-by-side on paper to help us decide how we might settle on a common set of categories.

I've tried searching the forums and hunting through the help file (I suspect it's in there somewhere 'cause it's such a voluminous file) but I can't figure out how to do this.

Is it possible, and if so, how is it done?

Mario

There is no feature to print a category tree. I doubt that this is something users need to do frequently.

The native export format for categories is an XML file (with the. imcx extension). If you rename the file to use .xml you can open it with any capable text editor (e.g. Notepad++) and use it's built-in print features. It will format the XML nicely as well.

If you want to compare two category tries, you can export them both and then use one of the text "diff" tools to analyze both files and show the differences.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Panther

Mario - thanks for the response and advice.  I had already tried opening the exported file in Notepad++, but it comes up with all the extra html code or whatever it is and yields something that isn't very easy to use because of all the clutter and the extra length.   


Is anybody here familiar enough with Notepad++ or these kinds of .xml files to clue me in as to how I might easily take the output of a file such as shown below:



and weed out all the extraneous stuff so that only the categories themselves (on the lines with the red arrows) would appear in the document so I could print out a list of my iMatch categories?

Mario

NotePad++ loads the XML file alright, including the actual XML tags which make up the file.

If this is not sufficient for your purpose. I suggest you create a script. Open the script editor and paste the following code:

[code]
Sub Main

Dim c As Category
For Each c In Database.Categories
Debug.Print c.QualifiedName
Next

End Sub


This dumps the fully qualified name of all categories into the script output window.

Note: If your database has thousands of categories, the dump window will spill over. In that case we would need to write the category names into a text file or something. You can modify this to whatever you need. See the IMatch help for a full documentation of the scripting classes.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Panther

#4
Mario - thanks!

Never messed with scripts in iMatch, but it sounds like now is my opportunity.  I only have 200-ish categories in my real database so far (I expect that number to grow, but not hugely), so spill-over shouldn't be a problem.

Maybe the help file will answer this, but is there a way to print from the "script output window" or would I need to figure out a way to "write the category names into a text file or something" as you suggest in order to print them to compare side by side?

[EDIT] - perfect!  I ran the script you provided (THANK YOU!), and then just highlighted/copy/pasted the list of categories in the output window into a text file in Notepad++, and printed the list from there.  Just exactly what I needed.

Thanks again for this amazing program and your continued support.  Will be buying a fourth copy soon for my sister, who I have gotten hooked on iMatch's possibilities by talking her ear off about it on our recent visit.


[EDIT AGAIN] - oops - probably spoke too soon (about the result, not about your support :) )

I took a look at the list I printed out more closely, and realized that while it looks like all the categories are probably on the list, they are all jumbled up and in the wrong order.  For example, in my iMatch workspace the categories are listed in alphabetical order, but in the list in the output window created by the script things are not sorted that way (just seem to be randomly jumbled around).  Any idea why that script isn't retaining the alphabetical sort order of the categories? (or how to tweak it to do so?)

Mario

I have written a small 'category dumper' script for the next release. This script dumps category names into a text file.
There is a flat mode (fully qualified name) and a hierarchical mode (where child categories are indented). There is even an  option to exclude data-driven categories.

I have attached the script for you below.
Extract the contents of the ZIP file to

C:\ProgramData\photools.com\IMatch5\scripts\system\Utility

and restart IMatch. The new script will show up in the script manager under System > Utilities.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Quote from: Mario on August 09, 2016, 08:51:13 AM
I have written a small 'category dumper' script for the next release. This script dumps category names into a text file.
There is a flat mode (fully qualified name) and a hierarchical mode (where child categories are indented). There is even an  option to exclude data-driven categories.

The new script will show up in the script manager under System > Utilities.

:D :D :D Thanks!
Best wishes from Switzerland! :-)
Markus

oldhank

+ One. Many thanks. I have wanted this for a long time. :) :) :)

jch2103

Thank you! I've desired this option several times in the past.
John

Mario

Geez. It took me only 10 minutes to write this.
You should bump / Like feature requests more  ;)
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Panther

Mario - this is awesome - thanks!

I could tell from just reading the forums over the years that the scripting capabilities of iMatch were tremendous, but they always seemed pretty scary/complex and way beyond both my meager programming skills and my rather mundane needs/uses as far as what I was trying to do with the program.  Good to see that this particular thing was both pretty simple to do (for you, not me) and something that other people will also find useful.

Panther

Hey Mario - just tried this and it worked great, BUT I did notice one little quirk that you may want to think about for the version in the next release.  When I first ran the script you provided, it looked like everything was now sorted the same way that the categories were sorted in my workspace/category panels (so, a big improvement over the jumbled results from yesterday's initial version). 

However, I noticed that some of my categories with numbers were not sorting in the order I would have expected (in either my category panels or in the print out) - for example, category called "1869" was listed before "500", and "6" was after "18".  I remembered (vaguely) that certain sort routines/methods could cause that type of result, so I went plowing through the Help file until I found the place to configure the sort order for the Category Panel, and I changed it from "Alphabetically (case-sensitive)" to "Standard (also sorts numerical values)".  This fixed the issue just fine in the list of categories in the Category Panel, but when I ran the script again it still listed them out in the same sort order as it had the first time.    (I tried closing the database and restarting iMatch, in case it needed to somehow have that sort order "saved" in some fashion, but it was still sorted that original way when I ran the script again after that.)

It seems that the script isn't recognizing/applying the sort order the user has selected for the category panel, and I would think it would be best if it would.  Hope that doesn't complicate things too much, but I do think most users would hope/expect that the category list dumped out like this would match up with what they're seeing in their category panels.

In any event, this has certainly solved my immediate need to be able to compare my list with my wife's (very few of the categories in our real databases have numbers such that they would be affected by this little quirk), so I'm extremely grateful for this amazing level of support!


Mario

#12
Just change the line where the script sorts the categories to

srt.SortCategories(cats,ecmStrCmpLogical,True)

(I did that now for the standard script I will ship with IMatch).

And if you have manually resorterd categories, you may need to use ecmCustom instead of ...Logical even.

The idea with scripting is that you can make your own scripts or customize scripts provided by others to do what you need to do...

More information about the new script can be found in the new on-line release notes at http://www.photools.com/release-notes/
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Quote from: Mario on August 09, 2016, 09:33:39 PM
Geez. It took me only 10 minutes to write this.
You should bump / Like feature requests more  ;)

IMatch is natevely very strong.
But for some tasks, sometimes very easy ones, or more complicated, a script can do wonder. But true, for users, who does never "fiddled" with scripts, it is not that easy.
Best wishes from Switzerland! :-)
Markus

Mario

#14
Quote from: sinus on August 10, 2016, 10:31:21 AM
IMatch is natevely very strong.
But for some tasks, sometimes very easy ones, or more complicated, a script can do wonder. But true, for users, who does never "fiddled" with scripts, it is not that easy.
But at least IMatch offers you ways to extend the built-in functionality. If you want something that's not there, you or somebody with some scripting experience can add it. Or you hire a programmer to do it for you.

The upcoming IMatch AnywhereTM is built on this strong concept and carries it even further. The main component, IMatch WebServicesTM, offers an open programming interface for IMatch databases, using modern web technologies. This allows other applications, services and web browsers to query and browse IMatch databases. On the same computer, over a network or even over the Internet using any device or technology.

The programming language used to access IMatch WebServices are URLs  - yes, the same things you enter in your browser to reach a web site. But instead of the latest news, IMatch WebServices returns data in standardized JSON format

For example, to get a list of all categories in your database, you can use the following URL:

http://COMPUTERNAME/v1/categories?fields=name,children

You can do that right in your web browser!

This request returns all categories in the database. For each category, the name and the children are included in the result (you could also request other data). Match WebServices returns a result in JSON format which can not only be directly displayed by web browsers but also handled by JavaScript or other programming languages:

{
    "categories" : [
      {
          "name" : "@All",
          "children" : [
          ]
      },
      {
          "name" : "@Keywords",
          "children" : [
            {
                "name" : "paul"
            },
            {
                "name" : "peter"
            },
            {
                "name" : "mary"
            }
          ]
        ...


If you look at this small fragment, you should be able to see how it works. JSON is not really intended to be read by humans, but it is not hard to make sense of it. If you now have a bit of JavaScript in your HTML page, you can transform this standard result into something that's more aimed at humans, maybe even output it as a tree structure. Or re-format it for printing directly in the browser. Or write it to a text file.

What's important here is that no special tools are needed. Everything is already available in your browser. And that on any device and on any operating system. And you can access your IMatch database that way whether it runs on the same computer as your web browser, on another computer somewhere in your local network, or on a computer 2,000 miles away!
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Panther

Thanks for all the extra info - may just get tempted to look into learning how to do this scripting stuff after all.

I tried your change and it did work, but I take it that it just changes to a specific sort order rather than telling it to use whatever sort order the user has selected (I tested it again after changing the sort order in the category panel and it still sorted the same way it did before).  So, I assume that basically it might be necessary to create several different versions, one for each desired sort order that would have that particular line you mentioned modified to specifically reference each particular sort method.  Easy enough to do, of course (assuming that somewhere in the help file or whatever there's a list of the script lines/commands that correspond to each of the available sort method choices).

Too bad it's not elegant enough to just detect and use whatever sort order selection the user has made in the category panel, but as they say beggars can't be choosers so I'm really happy with what you've provided - thanks again!

Mario

What can be done with the sorter in scripting and what can be done in the IMatch UI is not always identical.
Feel free to change the script to your needs. Add a drop-down combo box where you can select the order in which you want the categories to be sorted. There is no way for a script to find out the sort order the user has selected for any of the views.

As for elegance: I wrote that script for you at no cost. I think it's elegant enough for free.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Panther

Mario - I hope I wasn't appearing to be ungrateful (that was not my intent), and I certainly agree - it was even more than I asked for and was plenty elegant for the price :)

I think a drop down with a choice of sort methods would be a great idea - perhaps that will be a good subject for my first attempt at scripting.  Hopefully I can figure out what you did in this script to provide the option to choose between the flat versus indented file format and perhaps adapt it to providing a choice about sort orders.

Thanks again for all your help!