DO12 - Beta 5 problems with PDF metadata and scripting

I am trying to develop a script that will allow me to write to the user fields of PDF files. I am a photographer, not a computer programmer, so progress is slow and I guess as far as the niceties of VB scripting for professionals go pretty crude.

But surely this is one of the great delights of Opus, you can hack around to your heart's content to get what you really, really want. So please do not by sniffy about badly spaced code or inefficient code or whatever, like the last time I asked for some help. I am trying my best to learn something that is completely alien to me. And the only reason I have embarked on this project is that the type in the metadata panel is so small I find captioning images via it's interface a thankless task.

The code which I have inserted in this message makes a simple dialog box that you fill in with metadata and then commands insert the strings into the appropriate fields of of the metadata held in a PDF except it does not. If you use Opus scripting to set the Author and Creator fields on a PDF, it works a treat, however put those instructions in VB and those fields will not fill. Use exactly the same instructions to in VB to fill the Comment field and it works a treat. I believe that there are similar problems with the Subject and Title fields also, though I have had the tags field working.

The enclosed script is based on a script I wrote to make it easy to caption my pictures and with pictures it works an absolute treat, with PDFs it is proving something of a nightmare.

dim copysymbol,tagger,author,caption,subject,title Function OnClick(ByRef ClickData) Set dlg = ClickData.Func.Dlg Dlg.template = "pdf" Dlg.Show caption = dlg.Control("caption").Value subject = dlg.Control("subject").Value title = dlg.Control ("title").Value author = dlg.Control("photog").Value tagger = dlg.Control("keyword").Value msgbox author If Not copysymbol = ("") Then copysymbol = "© " + author ClickData.Func.Command.RunCommand("SetAttr META ""Creator:" & copysymbol & """") ClickData.Func.Command.RunCommand("SetAttr META ""author:" & author & """") End If If Not caption = ("") Then ClickData.Func.Command.RunCommand("SetAttr META ""Comment:" & caption & """") End If End Function ==SCRIPT RESOURCES <resources> <resource name="pdf" type="dialog"> <dialog fontsize="10" height="134" lang="english" standard_buttons="ok,cancel" title="PDF METADATA" width="325"> <control halign="left" height="8" name="static1" title="Enter the IPTC metadata, and click a button." type="static" width="159" x="9" y="6" /> <control halign="left" height="30" max="512" multiline="yes" name="caption" type="edit" width="243" x="18" y="76" /> <control halign="left" height="8" name="static3" title="Comment" type="static" width="33" x="20" y="64" /> <control halign="left" height="12" name="photog" tip="PDF Creator" type="edit" width="123" x="71" y="45" /> <control halign="left" height="8" name="Photographer" title="Creator:" type="static" width="44" x="17" y="47" /> </dialog> </resource> </resources>

Sorry about the rant, but it really hit a nerve.

Is this the same as your Scripting problem with dialog box thread or a different problem/question?

If it's different, please give more detail of what is failing and where, and of what you've tried so far. With scripting, it usually makes sense to break things down into the most simple case you can which still triggers the behaviour.

The act of simplifying things often reveals where the mistake is, if it's in the code, and helps us to focus on the real problem while not being bogged down by unimportant details, whether it's in the script code or on the Opus or Windows sides of things.

I got around the the problems I was having Scripting problems with dialog box by totally re-writing the code in a different way to get round an error nobody seemed able to help me with, so it is probably better to let that one lie

However - I suspect - this new one may be an Opus problem.

if I run the Opus command SetAttr META Author:A N Other against PDF files all is fine and the Author field is filled with A N Other.

When I turn to VB script I achieve that with

ClickData.Func.Command.RunCommand("SetAttr META ""author:" & author & """")

where author is a variable containing the the author string

In this case when the script runs the author field is not filled in.

However when I use

ClickData.Func.Command.RunCommand("SetAttr META ""Comment:" & caption & """")

where caption is a variable containing the Comment string

It works fine and the value of caption appears in the comment field of the metadata of the PDF.

As you see the lines are identical apart from different metadata fields and variable values. It does not make much sense.

The problem also seems to affect the Subject and Title fields but not tags

You will see that the rest of the script is mainly checks to make sure the strings from the dialog contain text as I do not wish to overwrite already filled in fields with blank data.

I have been doing more work on this problem.

I changed the line in the code that sets the author code in the PDF file so that the data was sent to Comment field. That worked fine.

However, any attempt to have the script send to the Authors, Title or Subject fields failed. The tags field, however, worked fine.

Does this not show that the code is OK and problem lies in the inability of Opus to address certain metadata fields in PDF files from a VB script?

I'd suggest you print the commands you create to the script console, so you can see exactly what they look like and gives you the option to copy them from there to run them manually, just to make sure they actually work without the VB code wrapped around.

So instead of just:

ClickData.Func.Command.RunCommand("SetAttr META ""author:" & author & """")

Do this:

dim cmdline : cmdline = "SetAttr META ""author:" & author & """"
DOpus.Output "CMD: " & cmdline

Thanks for the tip Tbone. Your VB commands reveal that my script is producing the correct Opus command string.

CMD: SetAttr META "author:© The author"

As I Said in my previous post the problem is that the string is not been written to the Authors field of the PDF.

If I change the destination field to Comment and run your code the result is inserted into the comment field.

This looks lie a bug in Opus 12 to me. Probably not a lot of people want to add Metadata to PDFs, but since I replaced all my EPS files with PDFs I find it very usefgul.

Many thanks to all who helped me with this problem. I have eventually fixed it.

I did so by moving the various Set ATTRMeta statements around in the script. Changing the order seems to have done the trick, though it will take a cleverer man than me to explain why.

My guess is that the commands are being run asynchronously, which means at times some commands may try to write to the file while a previous command still has it locked. It would be more reliable to build your entire command up using AddLine() and then run it as a single command.

That makes perfect sense, Jon, thank you.