I have been trying to find an easy way to add to the document properties of the metadata fields of images. I have very little VB scripting ability, but after days of hacking through the Opus helpfiles and various internet resources I have come up with the following (probably very crude) VB script which does the job as far as it goes
Using the new dialog features of DO 12 I have created:
Of course, the great problem is that should any field eg Copyright be empty when you submit the results of the form it wipes out what is in the copyright field of the current metadata on the image.
What I cannot figure out is how I can check whether the value of any box on the form is empty, and if it is,skip by the instruction to setAttr META for that field and move onto the next one, where I can run a similar test.
Can some scripting expert like Tbone help me with this problem? I would be very grateful
Many thanks for the prompt reply. I am probably not making myself very clear about what my problem is.
I have worked out:
if dlg.Control("copyright").Value ="" Then
msgbox "WHOOPS!!"
Else
Msgbox "OK"
End If
What I am having the problem with is how, in place of the Msgbox box WHOOPS, I get the script to miss out the instruction to fill the copyright metadata field and move on to the next field. Obviously if there is text in the copyright field I can carry out the instruction in place of Msgbox OK.
I thought of labeling the instructions in the script and using GoTo LABEL to achieve the task, but I cannot get it to work at all.
That kinda solves my problem except that if there is no text in the copyright string I need the script to pass over the instruction to fill the copyright field and move on to (say) the photographer field, where I can start the text check process all over again.
[code]@nodeselect
Function OnClick(ByRef ClickData)
Set dlg = ClickData.Func.Dlg
Dlg.template = "PDFMeta"
Dlg.Show
If Len(dlg.Control("comment").Value) > 0 Then
ClickData.Func.Command.RunCommand("SetAttr META ""comment:" & dlg.Control("commentPDF").Value & """")
End If
If Len(dlg.Control("keywords").Value) > 0 Then
ClickData.Func.Command.RunCommand("SetAttr META ""tags:" & dlg.Control("keywords").Value & """")
End If
End Function
[/code]
As you can see from the screenshot. Incorporating the code that Jon suggested throws up an error that does not seem to make much sense to me, but as I have said, I am no expert on VB, but line 5 position 2 seems to have nothing to do with dlg.control.
The problem could not be anything to do with hidden characters in the script, could it? I often work by doing a lot of cutting and pasting into scripts
If you use "@" modifiers like @deselect within the script code section, the line "counting" seems to be irritated and wrong in case of error.
It halso happened here, while there were no modifiers in the script code section/tab, but new ones were copied and pasted into the correct "Modifiers" tab.
Fake editing the Modifiers tab finally made DO recognize the correct number of lines there (looked like that at least).
So I guess that's what you are dealing with here, some kind of buglet. o) Notice, I'm still at beta4, did not manage to update yet. o(
What kind of hidden characters do you mean? As in non-printing Unicode characters?
(TBone beat me to it: The @nodeselect at the top belongs in the Modifiers tab, by the way.)
The indentation in your code is making it quite hard to read, also, and may be masking some other misunderstanding, perhaps. How well do you understand the basics of VBScript like If/Then/Else statements?
Moving the @nodeselect to the modifiers section cures the script line problem and I can see the logic of that, but it still does not get rid of the error, and that is my real problem
@auden
You use v12 beta5? The .value property is not available in versions prior to that iirc. You'd use .GetText() before beta5.
Maybe post the error with your code again, now that the line numbers are correct (hopefully), it's probably much easier to see what fails and why.
[code] Function OnClick(ByRef ClickData)
Set dlg = ClickData.Func.Dlg
Dlg.template = "PDFMeta"
Dlg.Show
If Len (Dlg.Control ("commentPDF").Value) > 0 Then
ClickData.Func.Command.RunCommand("SetAttr META ""comment:" & dlg.Control("commentPDF").Value & """")
DOpus.Output "Return code = " & Dlg.result
End If
If Len (dlg.Control("keywords").Value) > 0 Then
ClickData.Func.Command.RunCommand("SetAttr META ""tags:" & dlg.Control("keywords").Value & """")
End If
End Function
Maybe it's "comment" (wrong) vs. "Comment" (correct name)?
Don't remember if these control ids/names are case sensitive or not, if not, then you have something to fix. o)