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

Manipulating objects inside a "LayerKind.SMARTOBJECT" object ?

New Here ,
Nov 04, 2007 Nov 04, 2007
for(var i=0;i<docRef.artLayers.length;i++)<br />{<br /> if(docRef.artLayers.kind==LayerKind.SMARTOBJECT)<br /> {<br /> // how do I access this smart object's layers?<br /> }<br />}<br /><br />Hello!<br />I have a PSD doc I have fully created with Photoshop CS3 Extended (Middle Eastern).<br />With a script (or you can suggest another way) - I want to be able to hide all the text layers ("LayerKind.TEXT") in that doc, but most of them are inside smart objects that I have created in order to keep everything clean.<br />Anyway, the code above detects all the smart objects, but how do I access the objects inside those (e.g 'sub-objects') ?<br /><br />And If I'm asking already, maybe anyone knows how do I change the align of a text layer in a doc?<br /><br />The scripting manuals *didn't* offer any keyword/solution :(<br />This is pretty disappointing to see such a GREAT program lacking such "simple" scripting-keywords/commands.<br /><br />Will be extremly happy if someone here knows the answer(s) ! (:
TOPICS
Actions and scripting
1.3K
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
Adobe
Advocate ,
Feb 28, 2008 Feb 28, 2008
I know this is an older message, but I use this often and thought I'd share.

The answer is to 'record' the opening step using the scriptlistener plugin and use the recorded code. Here is the function I have used in my scripts (pass it a reference to the smart object):

///////////////////////////////////////////////////////////////////////////////
// Function: openSmartObject
// Usage: Opens Smart Object layer
// Input: Layer object
// Return: none
///////////////////////////////////////////////////////////////////////////////
function openSmartObject (objectRef) {
//NEED TO CHECK FOR VECTOR???
var id3 = charIDToTypeID( "slct" );
var desc2 = new ActionDescriptor();
var id4 = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var id5 = charIDToTypeID( "Lyr " );
ref1.putName( id5, objectRef.name );
desc2.putReference( id4, ref1 );
var id6 = charIDToTypeID( "MkVs" );
desc2.putBoolean( id6, false );
executeAction( id3, desc2, DialogModes.NO );
var id7 = stringIDToTypeID( "placedLayerEditContents" );
var desc3 = new ActionDescriptor();
executeAction( id7, desc3, DialogModes.NO );

}

NOTE - I haven't found any way just yet to determine if the layer is a vector smart object - this can cause errors in your code because Photoshop no longer has access to the opened file.
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
Guru ,
Mar 08, 2008 Mar 08, 2008
Mark,

This function will let you know what type of contect a smart object layer contains.

//
// returns either vectorData or rasterizeContent if smart cbject
// or undefined if not smart object
//
function getSmartObjectType(){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
var desc = executeActionGet(ref);
if(desc.hasKey(stringIDToTypeID('smartObject'))){// is smart object?
var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('smartObject')).getEnumerationValue(stringIDToTypeID('placed'));
return typeIDToStringID(desc);
};
};;
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
Advocate ,
Mar 10, 2008 Mar 10, 2008
Thanks! That looks great.

Right now, from what I can guess, I believe it's acting on the selected layer(?) - I'd like to be able to pass a reference to a layer to this function, but I don't see where to change the function to have it check a specific layer.
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
Guru ,
Mar 10, 2008 Mar 10, 2008
My function does act on the active layer. You could change the function to match yours by replacing the line

ref.putEnumerated(...

with

ref.putName( charIDToTypeID('Lyr '), objectRef.name );

I would like to point out that your function does not really use a layer object but rather the string property name. If there are more than one layer with the same name the function may not match the layer object in the argument.
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
Advocate ,
Mar 10, 2008 Mar 10, 2008
Ah, thanks!

I had recorded that function long ago using scriptlistener, and had forgotten that, although the function is passed a reference to the layer, it does use the layer name (since that is what shows up in the recorded action, and was able to be changed). I haven't noticed it having any problems thus far, but would like to change it to use the actual layer reference, if possible, in case that becomes necessary in the future.
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
Guru ,
Mar 10, 2008 Mar 10, 2008
I do not know of any direct way of using a JS layer object with scriptlistner code.

That is why I use the activeLayer with most of my scriptlistner functions, I'm sure that the function uses the layer I intended.

You can also use layer name if you are sure that each layer has a unique name.
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
Explorer ,
Mar 11, 2008 Mar 11, 2008
Michael_L_Hale@adobeforums.com wrote:
> I do not know of any direct way of using a JS layer object with scriptlistner code.


There are four ways of specifying which layer to use in scriptlistener code:
1) By name
2) By index
3) By ID
4) By making the layer the activeLayer.

1) and 4) are easiest. 2) and 3) are a bit more difficult. I have APIs in
stdlib.js and other scripts that use all four mechanism, but, by and larger, I
use 4).

For instance, here is a function that clears layer styles/effects:

Stdlib.clearEffects = function(doc, layer) {

// _ftn contains the actual scriptingListener code
function _ftn() {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
desc.putReference( cTID('null'), ref );
executeAction( sTID('disableLayerStyle'), desc, DialogModes.NO );
}


// this block of code switches to the desired doc and layer
// (if specified)
var ad = app.activeDocument;
var al = app.activeLayer;

if (doc) {
app.activeDocument= doc;
}
if (layer) {
app.activelayer = layer;
}

try {
_ftn(); // call the actual code

} finally {
// reset back to the original doc and layer
if (doc) {
app.activeDocument = ad;
}
if (layer) {
app.activelayer = al;
}
}
};

This way it doesn't matter what the active document and layer are when the
function is called.

-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com
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
Guru ,
Mar 11, 2008 Mar 11, 2008
LATEST
By using cTID('Nxt ') or cTID('Prvs') instead of cTID('Trgt'), you can specify the layer above or below the active layer as well.
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