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

How to get width of stroke shape layer

Explorer ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

i need to get width of stroke solid layer (shape) in alert .. and thanks very much 

TOPICS
Actions and scripting

Views

1.6K

Translate

Translate

Report

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

correct answers 1 Correct answer

People's Champ , Jan 02, 2020 Jan 02, 2020

 

 

var r = new ActionReference();    
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("AGMStrokeStyleInfo"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
alert(executeActionGet(r).getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo")).getUnitDoubleValue(stringIDToTypeID("strokeStyleLineWidth")));

 

 

P.S. Does not work in CS6

 

Votes

Translate

Translate
Adobe
Advocate ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

You can use Properties panel to check these infos but if you need an alert you should use script

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

yes i need to use script to make this .. you can help me ?

Votes

Translate

Translate

Report

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
Community Expert ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

To get the stroke information you most likely need to use Action manager code to get that information about a shape layer. You can get much information about layers using Action manager code.  I do not know how to code Action Manager code.  Users like Super Merlin and R-bin do.  I normally copy code they post. For I do not know JavaScript either. Here I used some of their code to see what may be possibles.  Action Descriptor 36 AGMStrokeStyleInfo may be what your are after.

Capture.jpg

JJMack

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

very good .. can you  write the script  here ?

Votes

Translate

Translate

Report

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
Community Expert ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

That for you to do as I wrote I do not know how to code Action Manager code DOM code do not cover all of Photoshop features. I just hack at scripting.... I have not Idea how to ger or use the Action Descriptor 36 AGMStrokeStyleInfo information

JJMack

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

can you write script to get stroke width of current artlayer ?

Votes

Translate

Translate

Report

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
Community Expert ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

Here is a Hack I have for looking at layer info.  Any executeActionGet() code you see I got from searching or help from Super Merlin or R-bin

 

// 2019, use it at your own risk;
var theLayers = collectLayers ();
alert (theLayers.join("\n"));
////// collect layers //////
function collectLayers () {
	// the file;
	var myDocument = app.activeDocument;
	// get number of layers;
	var ref = new ActionReference();
	ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
	var applicationDesc = executeActionGet(ref);
	var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
    //Extendscript seems to had LayerKind index in this order.
	/*
	var Doclayerkind = [
	"Normal", 
	"Text", 
	"Solidfill",
	"GradientFill",
	"Patternfill",
	"Levels",
	"Curves",
	"Colorbalance",
	"Brightnesscontrast",
	"Huesaturation",
	"Selectivecolor",
	"Channelmixer",
	"Gradientmap",
	"Inversion",
	"Threshold",
	"Posterize",
	"Smartobject",
	"Photofilter",
	"Exposure",
	"Layer3d",
	"Video",
	"Blackandwhite",
	"Vibrance",
	"colorlookup"
	]
	 */
	//Action Manager layerKind seems to be like this. 
 	var Doclayerkind = [
	"Pixel", 
	"Adjustment", 
	"Text",
	"Shape",
	"Smartobject",
	"6",
	"7",
	"8",
	"Gradientfill",
	"Patternfill",
	"Colorfill",
	"12",
	"13",
	"14",
	"15",
	"16",
	"17",
	"18",
	"19",
	"20",
	"21",
	"22",
	"23",
	"24"
	]
	/*
	var Doclayerkind = [
	"1", 
	"2", 
	"3",
	"4",
	"5",
	"6",
	"7",
	"8",
	"9",
	"10",
	"11",
	"12",
	"13",
	"14",
	"15",
	"16",
	"17",
	"18",
	"19",
	"20",
	"21",
	"22",
	"23",
	"24"
	]
	*/
	// process the layers;	
	var theLayers = new Array;
	for (var m = 0; m <= theNumber; m++) {
		try {
			var ref = new ActionReference();
			ref.putIndex( charIDToTypeID( "Lyr " ), m);
			var layerDesc = executeActionGet(ref);
			//alert(actionDescriptor(layerDesc));
			if (m==1) alert(actionDescriptor(layerDesc));
			var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
			var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
			// if group collect values;
			//if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" ) {
			if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
				var theName = layerDesc.getString(stringIDToTypeID('name'));
				var theKind = layerDesc.getInteger(stringIDToTypeID('layerKind'));
				var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
				var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
				var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
			theLayers.push([theName, Doclayerkind[theKind-1], "ID", theID, " Bounds ", theseBounds]);
			};
		}
		catch (e) {};
	};
	return theLayers
};

// Thanks to SuperMerlin

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function actionDescriptor(desc){  
	if(desc.typename == 'ActionDescriptor'){  
		var c = desc.count;  
		var msg= "Action Descriptor Item Count = " + c;
		for(var i=0;i<c;i++){ //enumerate descriptor's keys  
			//$.writeln('AD '+zeroPad( i+1, 2 )+' = '+IDTz(desc.getKey(i)) +' : '+desc.getType(desc.getKey(i)));   
			msg =  msg + "\n" + 'AD '+zeroPad( i+1, 2 )+' = '+IDTz(desc.getKey(i)) +' : '+desc.getType(desc.getKey(i)) ; 
		} 
    return msg; 
	}  
	function IDTz(id){  
		try {  
			var res = typeIDToStringID( id );  
			if(res == '' ){  
				var res = typeIDToCharID( id );  
			}  
		}
		catch(e){}  
		return res;  
	}  
	function zTID( s ){  
		if( s.length == 4 ) var res = charIDToTypeID( s );  
		if( s.length > 4 ) var res = stringIDToTypeID( s );  
		return res;  
	}  
	function zeroPad(num,pad) {  
		var z = Math.pow(10,Number(pad))  
		return num <= z ? ((Number( num) + z).toString().substr(1)): num  
	}  
};  

 

 

JJMack

Votes

Translate

Translate

Report

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
Community Expert ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

You can Mix DOM and Action Manager  code.  AM layerKind and DOM LayerKind differ  Using AM  you can filter Shape layer and get their ID and with the Layer ID yoy can use DOM code to see what kind of fill layer ther are.  However Shape that has not fill seem to show the har one of the filltype perhaps is has but its visibility or fill is set to 0.

 

Address the layer stack via  DOM code requires recursion. Here a Hack

/* ==========================================================
// 2017  John J. McAssey (JJMack) 
// ======================================================= */
// This script is supplied as is. It is provided as freeware. 
// The author accepts no liability for any problems arising from its use.
// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher
// bring application forward for double-click events
app.bringToFront();
// ensure at least one document open
if (!documents.length) alert('There are no documents open.', 'No Document');
else {
	// declare Global variables
	var allLayers = ""; 
	//main(); // at least one document exists proceed
    app.activeDocument.suspendHistory('Some Process Name','main()');
}
///////////////////////////////////////////////////////////////////////////////
//                            main function                                  //
///////////////////////////////////////////////////////////////////////////////
function main() {
	// declare local variables
	var orig_ruler_units = app.preferences.rulerUnits;
	var orig_type_units = app.preferences.typeUnits;
	var orig_display_dialogs = app.displayDialogs;
	app.preferences.rulerUnits = Units.PIXELS;  	// Set the ruler units to PIXELS
	app.preferences.typeUnits = TypeUnits.POINTS;   // Set Type units to POINTS
	app.displayDialogs = DialogModes.NO;	    	// Set Dialogs off
	try { code(); }
	// display error message if something goes wrong
	catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
	alert(allLayers);
	app.displayDialogs = orig_display_dialogs;  	// Reset display dialogs 
	app.preferences.typeUnits  = orig_type_units;	// Reset ruler units to original settings 
	app.preferences.rulerUnits = orig_ruler_units;	// Reset units to original settings
}
///////////////////////////////////////////////////////////////////////////////
//                           main function end                               //
///////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////
// The real code is embedded into this function so that at any point it can return //
// to the main line function to let it restore users edit environment and end      //
/////////////////////////////////////////////////////////////////////////////////////
function code() {
	processArtLayers(activeDocument) 
}
function processArtLayers(obj) {  
    for( var i = obj.artLayers.length-1; 0 <= i; i--) {/* alert(obj.artLayers[i]); */processLayers(obj.artLayers[i])}  
    for( var i = obj.layerSets.length-1; 0 <= i; i--) {/* alert(obj.layerSets[i]); */processArtLayers(obj.layerSets[i])} // Process Layer Set Layers  
} 
function processLayers(layer) { 
	//alert('Layer Name = "' + layer.name + '" Layer Kind ' + layer.kind );
	allLayers = allLayers + "ID " + layer.id + ", " + layer.name + ", " + layer.kind + "\n";
	switch (layer.kind){
	case LayerKind.SMARTOBJECT : processSmartObj(layer); break;
	default : break; // none process layer types catch all
	}
} 
//////////////////////////////////////////////////////////////////////////////////
//			Layer Type Functions					//
//////////////////////////////////////////////////////////////////////////////////
function processSmartObj(obj) { 
//	alert('Smart Object = "' + obj.name + '"');
	var localFilePath = "";
	var ref = new ActionReference();    
    ref.putIdentifier(charIDToTypeID('Lyr '), obj.id );    
    var desc = executeActionGet(ref);  
	//alert(actionDescriptor(desc));
    var smObj = desc.getObjectValue(stringIDToTypeID('smartObject'));  
	//alert(actionDescriptor(smObj));	
	try {
		//alert(obj_to_str(smObj), "Object Properties"); 
		//var thePlace = smObj.getEnumerationType(stringIDToTypeID('place'));
		var theDocumentID = smObj.getString(stringIDToTypeID('documentID'));
		//var theCompsList = smObj.getObjectPropertyType(stringIDToTypeID('compsList'));
		var theLinked = smObj.getBoolean(stringIDToTypeID("linked"));
		var theFileReference = smObj.getString(stringIDToTypeID("fileReference"));
		alert(["Smart Object Layer " + obj.name, "\n" + theDocumentID, "\nLinked=" + theLinked, "File='" + theFileReference + "'" ]);
	}
	catch(e) {alert(e);}
	return localFilePath;
}

// Thanks to  r-bin
function obj_to_str(obj){var str = ""; for (var p in obj) if(obj.hasOwnProperty(p))try{str+=p+"::"+obj[p]+"\n";}catch(e){};return str;}  

// Thanks to SuperMerlin

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function actionDescriptor(desc){  
	if(desc.typename == 'ActionDescriptor'){  
		var c = desc.count;  
		var msg= "Action Descriptor Item Count = " + c;
		for(var i=0;i<c;i++){ //enumerate descriptor's keys  
			//$.writeln('AD '+zeroPad( i+1, 2 )+' = '+IDTz(desc.getKey(i)) +' : '+desc.getType(desc.getKey(i)));   
			msg =  msg + "\n" + 'AD '+zeroPad( i+1, 2 )+' = '+IDTz(desc.getKey(i)) +' : '+desc.getType(desc.getKey(i)) ; 
		} 
    return msg; 
	}  
	function IDTz(id){  
		try {  
			var res = typeIDToStringID( id );  
			if(res == '' ){  
				var res = typeIDToCharID( id );  
			}  
		}
		catch(e){}  
		return res;  
	}  
	function zTID( s ){  
		if( s.length == 4 ) var res = charIDToTypeID( s );  
		if( s.length > 4 ) var res = stringIDToTypeID( s );  
		return res;  
	}  
	function zeroPad(num,pad) {  
		var z = Math.pow(10,Number(pad))  
		return num <= z ? ((Number( num) + z).toString().substr(1)): num  
	}  
};  

 

 

JJMack

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

i just need to display a width of stroke in alert 

Votes

Translate

Translate

Report

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
People's Champ ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

 

 

var r = new ActionReference();    
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("AGMStrokeStyleInfo"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
alert(executeActionGet(r).getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo")).getUnitDoubleValue(stringIDToTypeID("strokeStyleLineWidth")));

 

 

P.S. Does not work in CS6

 

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

you are greatest man in this site .. very thanks from egypt to you 

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

The script works done but, although there was no stroke ... i need to change alert to ("no stroke") .. if the shape don`t containt strokes

 

ass.jpg

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

If you want to get the strokes state:

 

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("AGMStrokeStyleInfo"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
alert(executeActionGet(r).getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo")).getBoolean(stringIDToTypeID("strokeEnabled")));

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

it`s just display true and false 

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

i need if true display width of stroke but if false show alert no stroke

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

ou need to combine it with r-bin code

Votes

Translate

Translate

Report

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 ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

how can i make this ? 

Votes

Translate

Translate

Report

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
Community Expert ,
Jan 02, 2020 Jan 02, 2020

Copy link to clipboard

Copied

LATEST

There will be a stroke width 0 to perhaps some limit. And it will either be enabled or not.  How you want to show this is up to you. Code the alert anyway you want. Show Both or if stroke is enabled show width else show no stroke. Both may look line this.

 

var r = new ActionReference();    
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("AGMStrokeStyleInfo"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
alert(executeActionGet(r).getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo")).getUnitDoubleValue(stringIDToTypeID("strokeStyleLineWidth")) + "  " +
      executeActionGet(r).getObjectValue(stringIDToTypeID("AGMStrokeStyleInfo")).getBoolean(stringIDToTypeID("strokeEnabled")) );

 

 

JJMack

Votes

Translate

Translate

Report

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