Author Topic: TPCMD commands only partially work in a script (.bat file)  (Read 4743 times)

0 Members and 1 Guest are viewing this topic.

nzmike

  • Member
  • **
  • Posts: 13
    • View Profile
I'm not sure if anyone here can/will help because I know that officially TPCMD is not supported but here goes nothing...

Say I have 20 images, Pic001.jpg thru Pic020.jpg freshly added to a folder managed by TP10.  Thumbnails are created and all look good in the program.  I then have a batch file with 20 Keyword commands in it, like so:

tpcmd.exe Keyword("+mountain;+lake;+snow|d:\pics\landscapes\pic001.jpg")
tpcmd.exe Keyword("+desert;+snow;+mountain|d:\pics\landscapes\pic002.jpg")
..etc...
tpcmd.exe Keyword("+river;+waterfall;+jungle|d:\pics\landscapes\pic020.jpg")

The problem is that when I run this script (or any variation on it) to add keywords to a number of images only some of the images in the folder will get keywords assigned, the rest get nothing.  This appears to be random because if I recreate the new images again (or delete all assigned keywords) and run the script again, different images will not get keywords assigned.  Sometimes it's only 2 or 3 and sometimes it's up to half or more of them, but it's never the same twice.

The above example is a very simplified use-case - my real world situation is that the script is auto-generated as part of a C# image management app that I have developed and it doesn't matter if the script is executed from the app or if I run it standalone using cmd.exe, I've never yet seen all the images get assigned their keywords.

Can anyone at Cerious tell me why this would be happening?  Can TP10 only handle a certain amount of TPCMD requests at once? Am I flooding it with too many commands which are not being queued in TP10 correctly?

I have tried catching the output of the commands (when submitting via my C# app) hoping to get an error message or a code or something that gives me a hint of what is going on but the commands do not seem to return anything - am I correct in this?  If not, what is returned and how can I capture it?

I have also noticed other TPCMD commands submitted as part of a script often do not get executed so it seems like there is a definite issue with TP10 'losing' commands submitted via a batch file.

Anyway, just hoping someone can help me out because it stops my photography workflow and causes me a lot of wasted time and effort having to assign custom keywords manually in TP10.

Daan van Rooijen

  • Administrator
  • Sr. Member
  • *****
  • Posts: 938
    • View Profile
TPCMD commands only partially work in a script (.bat file)
« Reply #1 on: 2017-06-16 06:23:28 »
Hi Mike,

Well, this is a user-to-user forum, for a reply from Cerious you'd have to contact their support directly.

Some thoughts:

I'm surprised that you got it to work (partially) at all - tpcmd was made for the previous generation of ThumbsPlus, which ended with ThumbsPlus v7 sp2. I'm not saying that it can't or shouldn't work, but compatibility issues could be a source of problems.

When you issue multiple calls to tpcmd, I'd do it sequentially; i.e. don't launch a new instance until the previous one has terminated (use Start /Wait or Start /Wait /B to launch tpcmd). I suspect that this is what causing the present errors.

When you say 'script', there are two kinds that you could use: operating system scripts (batch files) or a single tpcmd script that performs operations on multiple files in one go. See the tpcmd documentation (as included with tpcmd, or the DDE command section of the ThumbsPlus helpfile, or [link=http://www.cerious.com/tpcommand.shtml]this[/link] - confusingly I believe these are all slightly different).

Final thought: If you can't get this to work reliably, you could probably use Phil Harvey's '[link=http://www.sno.phy.queensu.ca/~phil/exiftool/]exiftool[/link]' instead.
I'm volunteering as a moderator - I do not work for Cerious Software, Inc.

nzmike

  • Member
  • **
  • Posts: 13
    • View Profile
TPCMD commands only partially work in a script (.bat file)
« Reply #2 on: 2017-06-16 18:59:20 »
Hi Daan,

Thanks for your reply - I wasn't sure if Cerious developers actually posted here but you have given me some new info so if I try that and still can't get it working I may just email support and ask them if they can help.

First, I didn't know TPCMD was pretty much part of TP7 - I only discovered it after I'd installed v8 and have not used it much until recently.  I did know it wasn't officially supported but given it was designed for for the previous generation of TP then that could explain the issues I'm having.  

After I posted yesterday I re-read the TPCMD readme file again and changed the way I did the script a little bit so I just put the Keyword commands in the script (without the tpcmd.exe bit) and ran it like this:

tpcmd -f cropimages.bat -l tpcmds.log -v

However this still gives the same result (random images with no keywords) and the log shows nothing except 'sending DDE command: ....' and then 'DDE command accepted by Thumbsplus'... none of them returned of an error or anything that suggested anything went wrong.

I do agree that I probably need to do the operations sequentially  but it does not look like the Keyword command has the wait parameter as some of the other commands do.  I have tried putting a pause between the commands (up to 2 seconds) but I get the same result.  I also can't see anything in the tpcmd readme file that mentions using /start or /wait or /B - can you elaborate a bit on this?  

Thanks for the tip about ExifTool - if I use that and assign the keywords directly to the image does ThumsPlus pick those up when you add the image?  If so then that could the best option.

The other potential issue is that I use SQL Server 2012 as my Pics DB so maybe the DDE commands are actually being rejected or not handled by SQL Server correctly.

I'm thinking the best alternative is just to insert or update the keywords in the database directly via C# and SQL commands. I use SQL Server 2012 as my Pics DB so can easily alter the database - maybe I just do this then issue an UpdateAll() command on the folder so ThumbsPlus then shows the assigned keywords.

Thanks again for the reply - much appreciated.

Daan van Rooijen

  • Administrator
  • Sr. Member
  • *****
  • Posts: 938
    • View Profile
TPCMD commands only partially work in a script (.bat file)
« Reply #3 on: 2017-06-16 20:55:50 »
Hi Mike,

> I do agree that I probably need to do the operations sequentially  but it does not look like the Keyword command has the wait parameter as some of the other commands do.

Well, actually I was refering to the DOS (well, command shell) "Start /wait" command there. You could use it in your batchfile to call tpcmd, so that the shell would wait until tpcmd has terminated before it processes the next command. So, in your batchfile, you'd use "Start /wait tpcmd.exe" instead of just "tpcmd.exe".

> Thanks for the tip about ExifTool - if I use that and assign the keywords directly to the image does ThumsPlus pick those up when you add the image?  

Yes, if you have configured TP to copy metadata (IPTC keywords) to the database when it creates thumbnails, that's what it will do. ExifTool has been around for a very long time and from what I hear it's very versatile and reliable (as well as somewhat complicated :).

> The other potential issue is that I use SQL Server 2012 as my Pics DB so maybe the DDE commands are actually being rejected or not handled by SQL Server correctly.

Well, theoratically at least there should be no difference between how TP works with the database, whether you issue commands to it through DDE (as tpcmd does) or from the menu or keyboard.
 
> I'm thinking the best alternative is just to insert or update the keywords in the database directly via C# and SQL commands.

That's an option too, but then you'll have the keywords stored only in the database and not in the image files. It's generally best to have them in both, just so you'll always have access to the keywords as long as you have the images.

BTW, do you happen to still have a copy of ThumbsPlus 7 on your system? It's probably a stupid thought, but I'm wondering if tpcmd.exe might be running that instead of TP10.
I'm volunteering as a moderator - I do not work for Cerious Software, Inc.

nzmike

  • Member
  • **
  • Posts: 13
    • View Profile
TPCMD commands only partially work in a script (.bat file)
« Reply #4 on: 2017-06-17 20:13:32 »
Thanks again for the input Daan.

I ended up adding the keywords via C# and a SQL Server stored procedure - it's faster and works every time. In hindsight I should have taken this approach first off but I got lazy thinking TPCMD would do it for me. (Naughty programmer!!). The only time I call TPCmd in the whole exercise now is to do an UpdateAll() and then OpenDir() to update and re-select the folder so ThumbsPlus refreshes all the images.

One thing I've noticed is that when I assign keywords directly in TP it does not seem write the IPTC keywords to the image file - 'tags' is always empty when I look at the properties in Explorer. Is this an option somewhere or should this be happening by default? (I just searched for something like this in the TP options but can't see anything.)

Most of the JPG images I use do not have the ITPC keywords on them as they come from a variety of different places (hence using TP to make it easy to assign keywords) but having had a closer look at ExifTool I think I may write a small app in C# to take a bunch of images, grab their TP keywords from my DB and apply them to the images in case I ever have to rebuild my DB or switch to another app like Lightroom.

Thanks again for your suggestions, all very helpful :-)

Daan van Rooijen

  • Administrator
  • Sr. Member
  • *****
  • Posts: 938
    • View Profile
TPCMD commands only partially work in a script (.bat file)
« Reply #5 on: 2017-06-18 02:55:03 »
> One thing I've noticed is that when I assign keywords directly in TP it does not seem write the IPTC keywords to the image file - 'tags' is always empty when I look at the properties in Explorer. Is this an option somewhere or should this be happening by default?

Well, adding keywords to the database, versus adding them to an image's own IPTC header, are two different actions in ThumbsPlus. For the latter, you'd use the Image | Batch Edit Metadata command (from the menu, not available through tpcmd).

(however, when the setting Options | Preferences | Keywords | 'Automatically generate keywords from: XMP keywords' is active, adding keywords to IPTC will als copy them into the database).
I'm volunteering as a moderator - I do not work for Cerious Software, Inc.

nzmike

  • Member
  • **
  • Posts: 13
    • View Profile
TPCMD commands only partially work in a script (.bat file)
« Reply #6 on: 2017-06-19 04:17:39 »
> Well, adding keywords to the database, versus adding them to an image's own IPTC header, are two different actions

I'm aware of that, what I was hoping was there an option I could set to always write/update/delete (in other words "synch") keywords in the DB with the image.

> you'd use the Image | Batch Edit Metadata command (from the menu, not available through tpcmd).

That is a nice little tool in TP which I will use if I don't write a C# program to do it with ExifTool.  I haven't used it too much yet but hopefully I can select all child folders and then run the Batch Edit Metadata command, that would help me get the keywords into the files.

It's not something I have a huge amount of time to look at now due to other work coming in but I got my main problem solved of getting keywords assigned for new/cropped images via my photography workflow app but I really appreciate your input and help :-)

leedell

  • Member
  • **
  • Posts: 4
    • View Profile
TPCMD commands only partially work in a script (.bat file)
« Reply #7 on: 2017-07-03 17:08:16 »
Timimg!  I encountered some issues in a fresh database in ThumbsPlus 10 trying to use TPCMD and submitted a support request on June 27th.  I hadn't checked the forums.

You might find this excerpt of the submission of use to explain the seeming randomness of the behavior.  I determined that it's a buffer/string not being cleared between DDE requests to ThumbsPlus:

I've used TPCMD often under version 7, mostly ScanTree() and Keyword().  
Since I've been unable to get TP10 to accept a TP7 text export or to
convert a copy of a TP7 database to the new format, I decided to just
build all the thumbnails in TP10's new database, then use a
very...very...long .BAT file to assign keywords to the files.  
Unfortunately, TP10 doesn't properly respond to TPCMD requests for scans
or keywords.

When the error occurs for keywords, it just doesn't "appear" to do anything.

For scans, at least the Task List in Thumbs 10 shows me what's wrong.
The following occurs in SP1-Beta2 (Build 4007) and SP1 (Build 4011).

Commands:
tpcmd ScanTree("T:\Pix\January")
tpcmd ScanTree("T:\Pix\February")
tpcmd ScanTree("T:\Pix\March")
tpcmd ScanTree("T:\Pix\April")
tpcmd ScanTree("T:\Pix\May")
tpcmd ScanTree("T:\Pix\June")
tpcmd ScanTree("T:\Pix\July")
tpcmd ScanTree("T:\Pix\August")
tpcmd ScanTree("T:\Pix\September")
tpcmd ScanTree("T:\Pix\October")
tpcmd ScanTree("T:\Pix\November")
tpcmd ScanTree("T:\Pix\December")

Resulting Task list:
Scan Tree: T:\Pix\January
Scan Tree: T:\Pix\February
Scan Tree: T:\Pix\March)ry
Scan Tree: T:\Pix\April)ry
Scan Tree: T:\Pix\May)l)ry
Scan Tree: T:\Pix\June))ry
Scan Tree: T:\Pix\July))ry
Scan Tree: T:\Pix\August)y
Scan Tree: T:\Pix\September
Scan Tree: T:\Pix\October)r
Scan Tree: T:\Pix\November)
Scan Tree: T:\Pix\December)
--
Normally, with ThumbsPlus 7, I would do this with

for /F "tokens=*" %f in (%temp%\dirlist.txt) do tpcmd ScanTree("%f")&sleep 1

Due to the error in ThumbsPlus 10, I have to sort the lines in the
directory list by increasing length. For the moment, I'm working around
the buffer error with the following, which depends upon awk, sed and
sort from GnuWin32

cat %temp%\dirlist.txt | awk "{print length,$0}" | sort -n | sed -e
"s;^[0-9]* ;;" > %temp%\dirlist_sorted.txt & for /F "tokens=*" %f in
(%temp%\dirlist_sorted.txt) do tpcmd ScanTree("%f")&sleep 1

leedell

  • Member
  • **
  • Posts: 4
    • View Profile
TPCMD commands only partially work in a script (.bat file)
« Reply #8 on: 2017-07-03 17:33:18 »
I'd be curious to see what your wrote for this scenario.

> I ended up adding the keywords via C# and a SQL Server stored procedure - it's faster and works every time. In hindsight I should have taken this approach first off but I got lazy thinking TPCMD would do it for me. (Naughty programmer!!). The only time I call TPCmd in the whole exercise now is to do an UpdateAll() and then OpenDir() to update and re-select the folder so ThumbsPlus refreshes all the images.