Skip to main content
JokerMartini
Participant
September 8, 2015
Answered

Place image in active document 'not as smart object'

  • September 8, 2015
  • 1 reply
  • 427 views

How can i place an image into the active document, but not as a smart object?

This topic has been closed for replies.
Correct answer uberplugins

var filePath = new File(decodeURI('~/Downloads/Safari_logo.png')),

    currentValue = getPlaceRasterSmartObjectValue();


if (currentValue == true) {

    placeRasterSmartObject(false);

}


placeEmbedded(filePath); /* Place Image */


placeRasterSmartObject(currentValue); /* Return the default value */


function placeRasterSmartObject(__bool) {

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putProperty(charIDToTypeID('Prpr'), charIDToTypeID('GnrP'));

    ref1.putEnumerated(charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));

    desc1.putReference(charIDToTypeID('null'), ref1);

    var desc2 = new ActionDescriptor();

    desc2.putBoolean(stringIDToTypeID("placeRasterSmartObject"), __bool);

    desc1.putObject(charIDToTypeID('T   '), charIDToTypeID('GnrP'), desc2);

    executeAction(charIDToTypeID('setd'), desc1, DialogModes.NO);

}


function placeEmbedded(filePath) {

    var actDesc = new ActionDescriptor();

    actDesc.putPath(charIDToTypeID('null'), filePath);

    actDesc.putEnumerated(charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa'));

    executeAction(charIDToTypeID('Plc '), actDesc, DialogModes.NO);

}


/* Update: Check current value */

function getPlaceRasterSmartObjectValue() {

    var ref = new ActionReference();

    ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("GnrP"));

    ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

    var psKey = executeActionGet(ref).getObjectValue(charIDToTypeID("GnrP")).getBoolean(stringIDToTypeID("placeRasterSmartObject"));

    return psKey

}

1 reply

uberplugins
Inspiring
September 8, 2015

Edit > Preferences > General > Always Crete Smart Objects when Placing

placeRasterSmartObject(false);

/* Do something */

placeRasterSmartObject(true);

function placeRasterSmartObject(__bool) {

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putProperty(charIDToTypeID('Prpr'), charIDToTypeID('GnrP'));

    ref1.putEnumerated(charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));

    desc1.putReference(charIDToTypeID('null'), ref1);

    var desc2 = new ActionDescriptor();

    desc2.putBoolean(stringIDToTypeID("placeRasterSmartObject"), __bool);

    desc1.putObject(charIDToTypeID('T   '), charIDToTypeID('GnrP'), desc2);

    executeAction(charIDToTypeID('setd'), desc1, DialogModes.NO);

}

JokerMartini
Participant
September 8, 2015

Could you demonstrate this being using with an actual image file?

uberplugins
uberpluginsCorrect answer
Inspiring
September 8, 2015

var filePath = new File(decodeURI('~/Downloads/Safari_logo.png')),

    currentValue = getPlaceRasterSmartObjectValue();


if (currentValue == true) {

    placeRasterSmartObject(false);

}


placeEmbedded(filePath); /* Place Image */


placeRasterSmartObject(currentValue); /* Return the default value */


function placeRasterSmartObject(__bool) {

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putProperty(charIDToTypeID('Prpr'), charIDToTypeID('GnrP'));

    ref1.putEnumerated(charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));

    desc1.putReference(charIDToTypeID('null'), ref1);

    var desc2 = new ActionDescriptor();

    desc2.putBoolean(stringIDToTypeID("placeRasterSmartObject"), __bool);

    desc1.putObject(charIDToTypeID('T   '), charIDToTypeID('GnrP'), desc2);

    executeAction(charIDToTypeID('setd'), desc1, DialogModes.NO);

}


function placeEmbedded(filePath) {

    var actDesc = new ActionDescriptor();

    actDesc.putPath(charIDToTypeID('null'), filePath);

    actDesc.putEnumerated(charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa'));

    executeAction(charIDToTypeID('Plc '), actDesc, DialogModes.NO);

}


/* Update: Check current value */

function getPlaceRasterSmartObjectValue() {

    var ref = new ActionReference();

    ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("GnrP"));

    ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

    var psKey = executeActionGet(ref).getObjectValue(charIDToTypeID("GnrP")).getBoolean(stringIDToTypeID("placeRasterSmartObject"));

    return psKey

}