Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Property doesn't write when schema isn't present.

Engaged ,
Sep 20, 2019 Sep 20, 2019

 

 

app.document.deselectAll();  

  
var count = app.document.visibleThumbnailsLength;  
 app.synchronouseMode=true; 
for ( var i = 0; i < count; i++ ) {  
    if ( app.document.visibleThumbnails[i].name.indexOf("-lr")==-1&&app.document.visibleThumbnails[i].name.split(".")[1]=="pdf") {  
        var selectedFile = app.document.visibleThumbnails[i].spec;  
         app.document.select( app.document.visibleThumbnails[i] );  
         var thumbnailMeta=app.document.visibleThumbnails[i].metadata;
         //var addIPTC_Core=thumbnailMeta.applyMetadataTemplate ("Imaging_Template_1.0","append");
         $.writeln(thumbnailMeta)
        if (ExternalObject.AdobeXMPScript == undefined){
            ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");   
            }
            var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);   
            var myXmp = myXmpFile.getXMP();   

 

 

So if I use this library I am only able to write to this file if that schema exists. Right now I have a PDF that just has some custom metatdata and I want to add some ITPC_Core metat data to it but That schema doesn't exist. So I either need to figure out how to write to the custom schema or create a new ITPC_Core schema and then edit that. Any help is appreciated.

 

function setXMPValue (xmpType,propertyValid,propertyToSet,propertyValue,propertyFlag){
    
         // var Email = myXmp.getStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo",XMPConst.NS_IPTC_CORE, "CiEmailWork");///gets the value of the structure
         try{
            if(propertyValid){
                    myXmp.setArrayItem(xmpType, propertyToSet,1,propertyValue); 
                    }
               else{
                    if(propertyFlag=="field"){
                        //if the property is nested and does not exists already we have to setStructField which requires a different constructor
                        var setAField= myXmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo",XMPConst.NS_IPTC_CORE, "CiEmailWork",propertyValue);///sets the value of the structure for field
                        }
                    else{
                        myXmp.appendArrayItem(xmpType, propertyToSet, propertyValue, 0, XMPConst.PROP_IS_ARRAY); 
                        }
                    
                    
                    }
                }
            catch(err){
                $.writeln(err)
                }
    
    }

 

TOPICS
How to , Metadata , Problem or error , Scripting
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 20, 2019 Sep 20, 2019
myXmpFile.canPutXMP(myXmp)

This is returning false unless I add something in the metadata tab. How do I do this automatically?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 20, 2019 Sep 20, 2019

var thumbnailMeta=app.document.visibleThumbnails[i].metadata; $.writeln("/// "+thumbnailMeta.hasMetadata)

 

This returns nothing. I would think it would return true or false but i get nothing.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Sep 20, 2019 Sep 20, 2019

There should be no problem writing IPTC data if not existed, just tested it on a newly created PDF and all details were entered.

#target bridge;
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
//For test pupose use the first selected file
var selectedFile = app.document.selections[0].spec;           
            var xmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);   
            var xmp = xmpFile.getXMP();  
try {
     xmp.appendArrayItem( XMPConst.NS_DC, "creator", "Creator", 0, XMPConst.ARRAY_IS_ORDERED );
     xmp.setLocalizedText( XMPConst.NS_DC, "title", null, "en-US", "Title" );
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "AuthorsPosition", "Author Position");
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Headline", "Headline");
     xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", "Caption/Description" ); 
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "DateCreated", new XMPDateTime(new Date()), XMPConst.XMPDATE);
     var Keys=["Keyword1","Keyword2","Etc."];
     for(var s in Keys){
	 xmp.appendArrayItem(XMPConst.NS_DC, "subject", Keys[s], 0,XMPConst.PROP_IS_ARRAY);
	  }
     xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrCtry", "England" );
     xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiEmailWork", "Joe.Bloggs@email.com" );
     xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrCity","Leeds");
     xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrExtadr","Address");
     xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrPcode","LS12PP");
     xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiAdrRegion","West Yorkshire");
     xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiTelWork","0132999999");
     xmp.setStructField( XMPConst.NS_IPTC_CORE, "CreatorContactInfo", XMPConst.NS_IPTC_CORE, "CiUrlWork","<a href="http://www.mysite.co.uk" target="_blank">www.mysite.co.uk</a>");
     xmp.setProperty( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:Location","Sub Location");
     xmp.setProperty( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:IntellectualGenre","Itellectual Genre");
     xmp.appendArrayItem( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:SubjectCode","IPTC Subject Code",0,XMPConst.PROP_IS_ARRAY);
     xmp.appendArrayItem( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:Scene","IPTC Scene Code",0,XMPConst.PROP_IS_ARRAY);
     xmp.setProperty( XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:CountryCode", "ISO Country Code" );
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "City", "London");
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "State", "State/Province");
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Country", "Britain");
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "CaptionWriter", "Description Writer");
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "TransmissionReference", "Job Identifier");
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Instructions", "Instructions");
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Credit", "Credit Line");
     xmp.setProperty(XMPConst.NS_PHOTOSHOP, "Source", "Source");
     xmp.setLocalizedText( XMPConst.NS_DC, "rights", null, "x-default", "Copyright Notice" ); 
     xmp.appendArrayItem( XMPConst.NS_XMP_RIGHTS, "UsageTerms","Rights Usage",0,XMPConst.PROP_IS_ARRAY);
     xmp.setProperty( XMPConst.NS_XMP_RIGHTS, "Marked",true, XMPConst.STRING);  //true = copyright, false = public domain     if( xmpFile.canPutXMP( xmp ) )
     {
               xmpFile.putXMP(xmp);
     }
     xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
} catch( e ) {
          $.writeln("ERROR SETTING METADATA: \n" + e + "\n"+e.line );
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 20, 2019 Sep 20, 2019

You need to clean this up, you have typos and missing semicolons.

 

visibleThumbnails doesn't always work well, app.document.thumbnail.children is more reliable in my experience.

 

You might have better luck with this namespace:

xmlns:Iptc4xmpCore="http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/"

 

You can also try thumbnail.mimeType to determine what kind of file you have. A PDF returns "application/pdf"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 23, 2019 Sep 23, 2019
Bridge won't even add a template if the schema isn't there. I need to either be able to add a schema. Or be able to write to a custom schema.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 23, 2019 Sep 23, 2019
LATEST
You need to use the correct name for the schema. The one you have is wrong.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines