Skip to main content
bagonterman
Inspiring
Sep 20, 2019 3:17 PM UTC
Question

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

 

 

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 is closed to new replies. Start a new post to keep the conversation going.

6 replies

Legend
Sep 20, 2019 6:52 PM UTC

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
bagonterman
Inspiring
Sep 23, 2019 1:00 PM UTC
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
Legend
Sep 23, 2019 6:41 PM UTC
You need to use the correct name for the schema. The one you have is wrong.
Translate
bagonterman
Inspiring
Sep 20, 2019 4:08 PM UTC
myXmpFile.canPutXMP(myXmp)

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

Translate
bagonterman
Inspiring
Sep 20, 2019 4:56 PM UTC

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