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.
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'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
ClickData.Func.Command.RunCommand(cmdline)
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.