Good start for attributes-app

Started by sinus, June 14, 2017, 03:04:45 PM

Previous topic - Next topic

sinus

Hi all scripters  :D

In IMatch 5 I have some scripts, what I am afraid, I am almost not able to "convert" (means write new) in JavaScript for IMatch 2017.
Hence I cannot change to IMatch 2017.  :-\
Since IMatch works fine, it is not really necessary to change, but since IMatch 2017 offers some nice things, I would like to change.

Until now I tried several things, like writing an App and use the Html-Export-Modul.
Both is really very difficult. 10 times harder then visual Basic - for me.   :-\

One of the most important thing seems finally easy, but is in fact hard for me:

I want do:
1) select some files (1-10), each file has some filled attributes-fields
2) The script or the Export-Modul should take some fields from the attributes and send them to a file, the target would be a Word-Doc

Hm, that's it. Seems easy, but is very, very difficult for me.
In my VB-script each field goes directly to a Word-Doc, neatly formated.

But here with JS I would be happy for now, if the fields would exported to a txt or a html - file, then I could work there further (maybe with VB from Word  ;D ::))

My fields in the attributes are the following (well, shortend to be easier understandable):
Attributes:
Global: Adress: Name, City (both data-type text)
File: Sum (data-type Real), Client (data-type Referenz: Adress:Name)

And my question is:
Do someone of you has an idea, which way would be the easiest (Html-export, app ...?)
Or do you have an idea, where I should start?

Sorry for the basic question, but I see the horse (JS), know, I should move up on the horse, but find even not the stirrups ... or, maybe I should take a donkey?  8)
Best wishes from Switzerland! :-)
Markus

Mario

#1
Why don't you use the Text Exporter module instead? No need for a custom script.
The Text Export Module can output any data you can grab via a variable, which includes metadata and Attributes.
Did you try that?

Word can import CSV files directly into tables, even perform calculations.
Excel too.

This would be the first thing I would try. The CSV format is ideal for that.



If you have some experience with writing Word Macros / VBA scripts, it is possible to call a web service like IMatch directly from VBA. The only problem seems to be to parse the JSON text data, which VBA cannot do out of the box. For that one would need a JSON helper library for VBA. There are some, but I did not look into this.

The principal code to make a call to IMatch/IMWS and to get information about the database and to put the answer into the current document is this:

    Dim MyRequest As Object
    Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")

' Call IMatch
    MyRequest.Open "GET", "http://127.0.0.1:50519/info", False
    MyRequest.send
   
' Result into the document
    ActiveDocument.Content.InsertAfter Text:=MyRequest.responseText


The problem is that the output looks like Chinese because VBA does not out-of-the-box understand JSON encoded return data or UTF-8 encoding. For that you need the JSON library which takes the response and converts it into something you can handle with BASIC...

To do more complex requests e.g. getting specific attributes for all selected files in the file window, you would use an URL for the /attributes endpoint,. like this (see the IMWS documentation for details) and the Attributes sample, which produces these URLS when you use it:

http://127.0.0.1:50519/v1/attributes?setid=1&idlist=%40imatch.filewindow.active.selection&resolverefs=true&auth_token=8e57015f6ce3f56a4cdd17339233581370beb80aca2901327cd012e75c576bab

IMWS responds to this with a JSON-formatted reply, which contains the Attribute data for all selected files.
All you need to do in your VBA macro, JavaScript, PHP, Python, BASIC, PowerShell or whatever yo use is to process the data and to do whatever you need to do.
This is the main advantage of the new IMWS-based scripting: It works with all programming languages.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Quote from: Mario on June 14, 2017, 04:52:12 PM
Why don't you use the Text Exporter module instead? No need for a custom script.
The Text Export Module can output any data you can grab via a variable, which includes metadata and Attributes.
Did you try that?

Word can import CSV files directly into tables, even perform calculations.
Excel too.

This would be the first thing I would try. The CSV format is ideal for that.

Ha! Cool, Mario, that could be THE thing.   :D
Stupid me, not to thought at that.

Thanks for this very good hint, I will try this.

Hey, if this works, IMatch2017 comes nearer  :D ... at the moment I have a try-version on another computer, where nothing bad can happens ... on knows never, stupid user error for example  ;D

Best wishes from Switzerland! :-)
Markus

sinus

Mario,
You are right, I tried it and this could be indeed a solution.

I exported some files to csv (not txt) and imported it into Excel (Word works also).

But maybe I will do this in the future with Excel, because there I can even better do some calculations.

What I have to do now, I think, is read a bit about Excel and csv, how tho format things and so.
For example that the adress would be in the correct place with a bigger font than other stuff.

I think, to do this I should be able, at least csv's are fields and I have to put them in the correct place.
If it works not, I do look for import into Word.

I see light at the end of the tunnel  8) and I will check now also, what else for scripts I must find a way to "convert". But this one here is the most important one.

Thanks again.
Best wishes from Switzerland! :-)
Markus

Mario

CSV files only contain data. How the receiving application (Excel, in this case) formats this is not related to IMatch. It's doable but you will have to read some tutorials or watch some bits on YouTube to learn this.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Quote from: Mario on June 14, 2017, 06:47:17 PM
CSV files only contain data. How the receiving application (Excel, in this case) formats this is not related to IMatch. It's doable but you will have to read some tutorials or watch some bits on YouTube to learn this.

Thanks, this I will do, at least (I think) this is far easier then scripting a new JavaScript.
Best wishes from Switzerland! :-)
Markus