Skip to main content
bagonterman
Inspiring
September 20, 2019
Question

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

  • September 20, 2019
  • 2 replies
  • 2284 views

 

 

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)
                }
    
    }

 

This topic has been closed for replies.

2 replies

Legend
September 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"

bagonterman
Inspiring
September 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.
Legend
September 23, 2019
You need to use the correct name for the schema. The one you have is wrong.
bagonterman
Inspiring
September 20, 2019
myXmpFile.canPutXMP(myXmp)

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

bagonterman
Inspiring
September 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.