Tuesday, December 6, 2011

Format plug-in: Setting file...

Hello,



I am currently writing a plug-in to import a proprietary image format into Photoshop. The people who will use this plug-in believe it would be useful to have some file information displayed in the File Info dialog.



The problem I'm running into is finding the functions necessary to set these properties in the File Info dialog, as currently they are all entirely blank.



As a simple example, if I wanted to have the Document Title, Author, Description and Keywords read ''Hello, world!'' after I've read in an image, what functions would my plug-in have to call to set each of these text fields?

Is there a struct that my plug-in needs to modify, or a group of get/set functions to change these properties?



Any information would be extremely helpful, as documentation on the subject is very difficult to find in the SDK.



Thanks a lot!



Jack
Format plug-in: Setting file...
You're in luck: this is what my DITABIS File Format plugin does. You can inspect the GPL code @ http://www.telegraphics.com.au/svn/ditabis/trunk/



The important code:



%26gt; pb-%26gt;propertyProcs-%26gt;setPropertyProc(kPhotoshopSignature,propCaption,0, 0,h);



Contact me for more help if you need to.
Format plug-in: Setting file...
Thanks for your help, Toby.

I've got an idea of how to configure the properties at this point. Simple properties work now, but I am still running into a bit of trouble setting complex options such as the Caption tag. I create a handle, populate it with the null-terminated string for the caption, and then I use setPropertyProc to link that handle to propCaption. The code would go something like this:



%26gt;Handle h = sPSHandle-%26gt;New( captionLength );

%26gt;if( h )

%26gt;{

%26gt; Boolean locked;

%26gt; Ptr p;

%26gt;

%26gt; sPSHandle-%26gt;SetLock( h, true, %26amp;p, %26amp;locked );

%26gt; // In here, use memcpy to copy a typical C string into p

%26gt; sPSHandle-%26gt;SetLock( h, false, %26amp;p, %26amp;locked );

%26gt;

%26gt;sPSProperty-%26gt;setPropertyProc(kPhotoshopSignature,propCaption,0,0,h);

%26gt;}



Basically when I run my plugin and open a file, the Description field is still blank, as it was before I tried to populate the fields.



Is there something wrong with my approach? Incidentally, I also encounter the same problem when I use the same property and handle suite methods that you do (FormatRecord-%26gt;PropertyProcs and FormatRecord-%26gt;HandleProcs instead of sPSProperty and sPSHandle respectively). From looking at other available code online, I'm assuming that there isn't a difference in behaviour. Please correct me if I'm wrong! :)

Sorry, the formatting ate a lot of my newlines and made my code fairly unreadable. Here is that code section, again:



%26gt; Handle h = sPSHandle-%26gt;New( captionLength );

%26gt;

%26gt; if( h )

%26gt;

%26gt; {

%26gt;

%26gt; Boolean locked;

%26gt;

%26gt; Ptr p;

%26gt;

%26gt;

%26gt; sPSHandle-%26gt;SetLock( h, true, %26amp;p, %26amp;locked );

%26gt;

%26gt;

%26gt; // In here, use memcpy to copy a typical C string into p

%26gt;

%26gt;

%26gt; sPSHandle-%26gt;SetLock( h, false, %26amp;p, %26amp;locked );

%26gt;

%26gt;

%26gt; sPSProperty-%26gt;setPropertyProc(kPhotoshopSignature,propCaption,0,0,h);

%26gt;

%26gt;}

It's quite a while since I wrote that code, but you can see from the source code I linked that propCaption is not a string - it's IPTC formatted data. Look at this file to see how I construct it:



http://www.telegraphics.com.au/svn/ditabis/trunk/metadata.c



Some links from google...



* http://www.controlledvocabulary.com/imagedatabases/iptc_naa.html

* http://libiptcdata.sourceforge.net/docs/iptc-overview.html

Thanks so much, Toby! Your code really helped me out, and now all the properties I need display properly.



Cheers!

Most welcome, Jack - glad I could help.

No comments:

Post a Comment