Highlighted

Script to section a circle?

Explorer ,
Aug 23, 2020

Copy link to clipboard

Copied

Is anyone aware of a script that will section a circle?

 

So if I draw a circle, run the script and enter a value, it will autoatically section to this number?  ie, enter 12 it equally sections the circle into 12?

 

I know i can do this manually, draw a line from centre to it's circumference, rotate it by required %age and so on.  I belive Illustrator has this function, but that's outwith my budget 🙂

 

many thanks

Most Valuable Participant
Correct answer by JJMack | Most Valuable Participant

 

With Transform and Layers and scripts you can do all sort of layer duplicating and rotating. Create a stroke Shape fill or no fill  have fun rotating it.

// 2015  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 {
	//Set First Time Defaults here
	var dfltCpys = 12;	// default number of copies including the original
	var dfltPos = 4;	// default Middle Center
	//End Defaults
	
	var Prefs ={}; //Object to hold preferences.
	var prefsFile = File(Folder.temp + "/RotateLayerAboutPreferences.dat");
	//If preferences do not exit use Defaults from above
	if(!prefsFile.exists){
		Prefs.Cpys  = dfltCpys;
		Prefs.Pos  = dfltPos;
		prefsFile.open('w');
		prefsFile.write(Prefs.toSource());
		prefsFile.close();
	}
	else{//Preferences exist so open them
		prefsFile.open('r');
		Prefs = eval(prefsFile.read());
		prefsFile.close();
	}
	
	try {
		
		function createDialog(){
		// begin dialog layout
		var DupRotateDialog = new Window('dialog');
		DupRotateDialog.text = 'Duplicate and Rotate Layer';
		DupRotateDialog.frameLocation = [78, 100];
		DupRotateDialog.alignChildren = 'center';

		DupRotateDialog.NumLayerPnl = DupRotateDialog.add('panel', [2, 2, 300, 56], 'Number of Layers and Rotation Anchor Point');
			DupRotateDialog.NumLayerPnl.add('statictext', [10, 16, 50, 48], 'Copies ');
			DupRotateDialog.NumLayerPnl.imgCpysEdt = DupRotateDialog.NumLayerPnl.add('edittext', [50, 13, 90, 34], Prefs.Cpys, {name:'imgCpys'});
			DupRotateDialog.NumLayerPnl.imgCpysEdt.helpTip = 'Number of copies of selected Layer';
			
			DupRotateDialog.NumLayerPnl.add('statictext',[96, 16, 240, 48],'Location');
			var position =['Top Left','Top Center','Top Right','Center Left','Center','Center Right','Bottom Left','Bottom Center','Bottom Right','Doc Center','Samples','Path Points'];
			DupRotateDialog.NumLayerPnl.dd1 = DupRotateDialog.NumLayerPnl.add('dropdownlist',[150, 13, 260, 34],position);
			DupRotateDialog.NumLayerPnl.dd1.selection=Prefs.Pos;
	
		var buttons = DupRotateDialog.add('group');
			buttons.orientation = 'row';
				var okBtn = buttons.add('button');
			okBtn.text = 'OK';
			okBtn.properties = {name: 'ok'};
				var cancelBtn = buttons.add('button');
			cancelBtn.text = 'Cancel';
			cancelBtn.properties = {name: 'cancel'};
		return DupRotateDialog;
		}
				
		dispdlg(createDialog());
		function dispdlg(DupRotateDialog){ 
			// display dialog and only continues on OK button press (OK = 1, Cancel = 2)
			DupRotateDialog.onShow = function() {
				var ww = DupRotateDialog.bounds.width;  
				var hh = DupRotateDialog.bounds.height;  
				DupRotateDialog.bounds.x  = 78;  
				DupRotateDialog.bounds.y  = 100;  
				DupRotateDialog.bounds.width  = ww;  
				DupRotateDialog.bounds.height  = hh;  
			}
			if (DupRotateDialog.show() == 1) {
				//variables passed from user interface
				var copies	= String(DupRotateDialog.NumLayerPnl.imgCpys.text); if (copies=="") { copies = Prefs.Cpys;}
				if (isNaN(copies)) { alert("Non numeric value entered"); dispdlg(createDialog());}
				else {
					if (copies<2 || copies>360) { alert("Number of layer allow is 2 to 360"); dispdlg(createDialog());}  // Not in range
					else {
						var AnchorPoint = Number(DupRotateDialog.NumLayerPnl.dd1.selection.index) + 1;
						cTID = function(s) { return app.charIDToTypeID(s); };
						sTID = function(s) { return app.stringIDToTypeID(s); };
						// Save the current preferences
						Prefs.Cpys  = copies;
						Prefs.Pos  = Number(DupRotateDialog.NumLayerPnl.dd1.selection.index);
						prefsFile.open('w');
						prefsFile.write(Prefs.toSource());
						prefsFile.close();
						var startRulerUnits = app.preferences.rulerUnits;
						var startTypeUnits = app.preferences.typeUnits;
						var startDisplayDialogs = app.displayDialogs;
						// Set Photoshop to use pixels and display no dialogs
						app.preferences.rulerUnits = Units.PIXELS;
						app.preferences.typeUnits = TypeUnits.PIXELS;
						app.displayDialogs = DialogModes.NO;
						app.togglePalettes();
						try { app.activeDocument.suspendHistory('RotateLayerAbout','main(copies, AnchorPoint)' );} 
						catch(e) {alert(e + ': on line ' + e.line);} 
						// Return the app preferences
						app.togglePalettes();
						app.preferences.rulerUnits = startRulerUnits;
						app.preferences.typeUnits = startTypeUnits;
						app.displayDialogs = startDisplayDialogs;
					}
				}
			}
			else {
				//alert('Operation Canceled.');
			}
		}		
	}
	catch(err){
		// Lot's of things can go wrong, Give a generic alert and see if they want the details
		if ( confirm("Sorry, something major happened and I can't continue! Would you like to see more info?" ) ) { alert(err + ': on line ' + err.line ); }
	}
}
	
function main(stemsAmount, Position) {
	if  (  Position == 11 && app.activeDocument.colorSamplers.length==0 ) {
		alert("No Color Sampler set");
		return;
	}
	if  (  Position == 12 ) {
		var thePath = selectedPath();
		if (thePath == undefined) {
			alert("No Path Selected");
			return;
		}
		var myPathInfo = extractSubPathInfo(thePath);  
	}
	// Save selected layer to variable:
	var originalStem = app.activeDocument.activeLayer;
	// Run the copying process
	if(stemsAmount != null){ 
		// Calculate the rotation angle
		var angle = 360 / parseInt(stemsAmount);

		// Create a group for stems
		var stemsGroup = app.activeDocument.layerSets.add();
			stemsGroup.name = originalStem.name + " ("+stemsAmount+" stems)";
		// Place original layer in group
		originalStem.move(stemsGroup, ElementPlacement.INSIDE);

		// Duplicate and rotate layers:
		for(var i = 1; i < stemsAmount; i++){
			// Duplicate original layer and save it to the variable
			var newStem = originalStem.duplicate();

			// Rotate new layer				
			switch (Position){
				case 1 : newStem.rotate(angle * i, AnchorPosition.TOPLEFT); break;
				case 2 : newStem.rotate(angle * i, AnchorPosition.TOPCENTER); break;
				case 3 : newStem.rotate(angle * i, AnchorPosition.TOPRIGHT); break;
				case 4 : newStem.rotate(angle * i, AnchorPosition.MIDDLELEFT); break;
				case 5 : newStem.rotate(angle * i, AnchorPosition.MIDDLECENTER); break;
				case 6 : newStem.rotate(angle * i, AnchorPosition.MIDDLERIGHT); break;
				case 7 : newStem.rotate(angle * i, AnchorPosition.BOTTOMLEFT); break;
				case 8 : newStem.rotate(angle * i, AnchorPosition.BOTTOMCENTER); break;
				case 9 : newStem.rotate(angle * i, AnchorPosition.BOTTOMRIGHT); break;
				case 10 : app.activeDocument.activeLayer = newStem; rotateAroundPosition(angle * i,activeDocument.width/2,activeDocument.height/2); break;
				case 11 : for (var s=0,len=app.activeDocument.colorSamplers.length;s<len;s++) {
							if (s!=0) {
								// Duplicate original layer and save it to the variable
								var newStem = originalStem.duplicate();
							}
							newStem.name = originalStem.name + " " + (i+1) + " p" + (s+1) ;
							app.activeDocument.activeLayer = newStem;
							var colorSamplerRef = app.activeDocument.colorSamplers[s];
							//alert("angle=" + (angle * i) +  " ,x=" + colorSamplerRef.position[0].value + " ,y=" + colorSamplerRef.position[1].value);
							rotateAroundPosition(angle * i,colorSamplerRef.position[0].value,colorSamplerRef.position[1].value);
							newStem.move(stemsGroup, ElementPlacement.PLACEATEND);
		               		}; 
							break; 
				case 12 :	for(var k=0;k<myPathInfo.length;k++){  
								for(var j=0;j<myPathInfo[k].entireSubPath.length;j++){ 
									if (k!=0 || j!=0) {
										// Duplicate original layer and save it to the variable
										var newStem = originalStem.duplicate();
									}
									newStem.name = originalStem.name + " " + (i+1) + " p" + (j+1) ;
									app.activeDocument.activeLayer = newStem;
									rotateAroundPosition(angle * i,myPathInfo[k].entireSubPath[j].anchor[0],myPathInfo[k].entireSubPath[j].anchor[1]);
									newStem.move(stemsGroup, ElementPlacement.PLACEATEND);
								}
							}
							break;
				default : break;
			}

			// Add index to new layers
			if (Position!=11) {
				newStem.name = originalStem.name + " " + (i+1);
				// Place new layer inside stems group
				newStem.move(stemsGroup, ElementPlacement.PLACEATEND);
			}
		};

		// Add index to the original layer
		if (Position!=11) originalStem.name += " 1";
		else originalStem.name += " 1 p1";
		};
		activeDocument.activeLayer = activeDocument.layers[0]; // Target top
		var groupname = app.activeDocument.activeLayer.name // remember name of group  
		var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" ); // this part from  Script Listene -- ungroup group  
		var desc14 = new ActionDescriptor();  
		var idnull = charIDToTypeID( "null" );  
		var ref13 = new ActionReference();  
		var idLyr = charIDToTypeID( "Lyr " );  
		var idOrdn = charIDToTypeID( "Ordn" );  
		var idTrgt = charIDToTypeID( "Trgt" );  
		ref13.putEnumerated( idLyr, idOrdn, idTrgt );  
		desc14.putReference( idnull, ref13 );  
		executeAction( idungroupLayersEvent, desc14, DialogModes.NO );  
		var idMk = charIDToTypeID( "Mk  " ); // this part from  Script Listene --  group selected layers  
		var desc15 = new ActionDescriptor();  
		var idnull = charIDToTypeID( "null" );  
		var ref14 = new ActionReference();  
		var idlayerSection = stringIDToTypeID( "layerSection" );  
		ref14.putClass( idlayerSection );  
		desc15.putReference( idnull, ref14 );  
		var idFrom = charIDToTypeID( "From" );  
		var ref15 = new ActionReference();  
		var idLyr = charIDToTypeID( "Lyr " );  
		var idOrdn = charIDToTypeID( "Ordn" );  
		var idTrgt = charIDToTypeID( "Trgt" );  
		ref15.putEnumerated( idLyr, idOrdn, idTrgt );  
		desc15.putReference( idFrom, ref15 );  
		executeAction( idMk, desc15, DialogModes.NO );  
		app.activeDocument.activeLayer.name = groupname // recall group name  
	}

function rotateAroundPosition(_angle,x,y) {  
    var desc1 = new ActionDescriptor();  
    var desc2 = new ActionDescriptor();  
    var ref1 = new ActionReference();  
    ref1.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));  
    desc1.putReference(charIDToTypeID('null'), ref1);  
    desc1.putEnumerated(charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), stringIDToTypeID("QCSIndependent"));  
    desc2.putUnitDouble(charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), x);  
    desc2.putUnitDouble(charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), y);  
    desc1.putObject(charIDToTypeID('Pstn'), charIDToTypeID('Pnt '), desc2);  
    desc1.putUnitDouble(charIDToTypeID('Angl'), charIDToTypeID('#Ang'), _angle);  
    desc1.putEnumerated(charIDToTypeID('Intr'), charIDToTypeID('Intp'), charIDToTypeID('Bcbc'));  
    executeAction(charIDToTypeID('Trnf'), desc1, DialogModes.NO);  
	}
////// determine selected path //////
function selectedPath () {
	try {
		var ref = new ActionReference(); 
		ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
		var desc = executeActionGet(ref);
		var theName = desc.getString(charIDToTypeID("PthN"));
		return app.activeDocument.pathItems.getByName(theName)
	}
	catch (e) {
		return undefined
	}
};
////// michael l hale’s code //////
function extractSubPathInfo(pathObj){  
    var pathArray = new Array();// each element can be used as the second arugment in pathItems.add ie doc.pathItems.add("myPath1", [pathArray[0]]);  
    var pl = pathObj.subPathItems.length;  
    for(var s=0;s<pl;s++){  
        var pArray = new Array();  
          for(var i=0;i<pathObj.subPathItems[s].pathPoints.length;i++){  
             pArray[i] = new PathPointInfo;  
             pArray[i].kind = pathObj.subPathItems[s].pathPoints[i].kind;  
             pArray[i].anchor = pathObj.subPathItems[s].pathPoints[i].anchor;  
			 //alert("Anchor " + pathObj.subPathItems[s].pathPoints[i].anchor );
             pArray[i].leftDirection = pathObj.subPathItems[s].pathPoints[i].leftDirection;  
             pArray[i].rightDirection = pathObj.subPathItems[s].pathPoints[i].rightDirection;  
          };  
        pathArray[pathArray.length] = new Array();  
        pathArray[pathArray.length - 1] = new SubPathInfo();  
        pathArray[pathArray.length - 1].operation = pathObj.subPathItems[s].operation;  
        pathArray[pathArray.length - 1].closed = pathObj.subPathItems[s].closed;  
        pathArray[pathArray.length - 1].entireSubPath = pArray;  
    };  
    return pathArray;  
}; 

 

 

Capture.jpg

RotateShape.gif

Topics

Actions and scripting, How to, Mac

Views

122

Likes

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

Script to section a circle?

Explorer ,
Aug 23, 2020

Copy link to clipboard

Copied

Is anyone aware of a script that will section a circle?

 

So if I draw a circle, run the script and enter a value, it will autoatically section to this number?  ie, enter 12 it equally sections the circle into 12?

 

I know i can do this manually, draw a line from centre to it's circumference, rotate it by required %age and so on.  I belive Illustrator has this function, but that's outwith my budget 🙂

 

many thanks

Most Valuable Participant
Correct answer by JJMack | Most Valuable Participant

 

With Transform and Layers and scripts you can do all sort of layer duplicating and rotating. Create a stroke Shape fill or no fill  have fun rotating it.

// 2015  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 {
	//Set First Time Defaults here
	var dfltCpys = 12;	// default number of copies including the original
	var dfltPos = 4;	// default Middle Center
	//End Defaults
	
	var Prefs ={}; //Object to hold preferences.
	var prefsFile = File(Folder.temp + "/RotateLayerAboutPreferences.dat");
	//If preferences do not exit use Defaults from above
	if(!prefsFile.exists){
		Prefs.Cpys  = dfltCpys;
		Prefs.Pos  = dfltPos;
		prefsFile.open('w');
		prefsFile.write(Prefs.toSource());
		prefsFile.close();
	}
	else{//Preferences exist so open them
		prefsFile.open('r');
		Prefs = eval(prefsFile.read());
		prefsFile.close();
	}
	
	try {
		
		function createDialog(){
		// begin dialog layout
		var DupRotateDialog = new Window('dialog');
		DupRotateDialog.text = 'Duplicate and Rotate Layer';
		DupRotateDialog.frameLocation = [78, 100];
		DupRotateDialog.alignChildren = 'center';

		DupRotateDialog.NumLayerPnl = DupRotateDialog.add('panel', [2, 2, 300, 56], 'Number of Layers and Rotation Anchor Point');
			DupRotateDialog.NumLayerPnl.add('statictext', [10, 16, 50, 48], 'Copies ');
			DupRotateDialog.NumLayerPnl.imgCpysEdt = DupRotateDialog.NumLayerPnl.add('edittext', [50, 13, 90, 34], Prefs.Cpys, {name:'imgCpys'});
			DupRotateDialog.NumLayerPnl.imgCpysEdt.helpTip = 'Number of copies of selected Layer';
			
			DupRotateDialog.NumLayerPnl.add('statictext',[96, 16, 240, 48],'Location');
			var position =['Top Left','Top Center','Top Right','Center Left','Center','Center Right','Bottom Left','Bottom Center','Bottom Right','Doc Center','Samples','Path Points'];
			DupRotateDialog.NumLayerPnl.dd1 = DupRotateDialog.NumLayerPnl.add('dropdownlist',[150, 13, 260, 34],position);
			DupRotateDialog.NumLayerPnl.dd1.selection=Prefs.Pos;
	
		var buttons = DupRotateDialog.add('group');
			buttons.orientation = 'row';
				var okBtn = buttons.add('button');
			okBtn.text = 'OK';
			okBtn.properties = {name: 'ok'};
				var cancelBtn = buttons.add('button');
			cancelBtn.text = 'Cancel';
			cancelBtn.properties = {name: 'cancel'};
		return DupRotateDialog;
		}
				
		dispdlg(createDialog());
		function dispdlg(DupRotateDialog){ 
			// display dialog and only continues on OK button press (OK = 1, Cancel = 2)
			DupRotateDialog.onShow = function() {
				var ww = DupRotateDialog.bounds.width;  
				var hh = DupRotateDialog.bounds.height;  
				DupRotateDialog.bounds.x  = 78;  
				DupRotateDialog.bounds.y  = 100;  
				DupRotateDialog.bounds.width  = ww;  
				DupRotateDialog.bounds.height  = hh;  
			}
			if (DupRotateDialog.show() == 1) {
				//variables passed from user interface
				var copies	= String(DupRotateDialog.NumLayerPnl.imgCpys.text); if (copies=="") { copies = Prefs.Cpys;}
				if (isNaN(copies)) { alert("Non numeric value entered"); dispdlg(createDialog());}
				else {
					if (copies<2 || copies>360) { alert("Number of layer allow is 2 to 360"); dispdlg(createDialog());}  // Not in range
					else {
						var AnchorPoint = Number(DupRotateDialog.NumLayerPnl.dd1.selection.index) + 1;
						cTID = function(s) { return app.charIDToTypeID(s); };
						sTID = function(s) { return app.stringIDToTypeID(s); };
						// Save the current preferences
						Prefs.Cpys  = copies;
						Prefs.Pos  = Number(DupRotateDialog.NumLayerPnl.dd1.selection.index);
						prefsFile.open('w');
						prefsFile.write(Prefs.toSource());
						prefsFile.close();
						var startRulerUnits = app.preferences.rulerUnits;
						var startTypeUnits = app.preferences.typeUnits;
						var startDisplayDialogs = app.displayDialogs;
						// Set Photoshop to use pixels and display no dialogs
						app.preferences.rulerUnits = Units.PIXELS;
						app.preferences.typeUnits = TypeUnits.PIXELS;
						app.displayDialogs = DialogModes.NO;
						app.togglePalettes();
						try { app.activeDocument.suspendHistory('RotateLayerAbout','main(copies, AnchorPoint)' );} 
						catch(e) {alert(e + ': on line ' + e.line);} 
						// Return the app preferences
						app.togglePalettes();
						app.preferences.rulerUnits = startRulerUnits;
						app.preferences.typeUnits = startTypeUnits;
						app.displayDialogs = startDisplayDialogs;
					}
				}
			}
			else {
				//alert('Operation Canceled.');
			}
		}		
	}
	catch(err){
		// Lot's of things can go wrong, Give a generic alert and see if they want the details
		if ( confirm("Sorry, something major happened and I can't continue! Would you like to see more info?" ) ) { alert(err + ': on line ' + err.line ); }
	}
}
	
function main(stemsAmount, Position) {
	if  (  Position == 11 && app.activeDocument.colorSamplers.length==0 ) {
		alert("No Color Sampler set");
		return;
	}
	if  (  Position == 12 ) {
		var thePath = selectedPath();
		if (thePath == undefined) {
			alert("No Path Selected");
			return;
		}
		var myPathInfo = extractSubPathInfo(thePath);  
	}
	// Save selected layer to variable:
	var originalStem = app.activeDocument.activeLayer;
	// Run the copying process
	if(stemsAmount != null){ 
		// Calculate the rotation angle
		var angle = 360 / parseInt(stemsAmount);

		// Create a group for stems
		var stemsGroup = app.activeDocument.layerSets.add();
			stemsGroup.name = originalStem.name + " ("+stemsAmount+" stems)";
		// Place original layer in group
		originalStem.move(stemsGroup, ElementPlacement.INSIDE);

		// Duplicate and rotate layers:
		for(var i = 1; i < stemsAmount; i++){
			// Duplicate original layer and save it to the variable
			var newStem = originalStem.duplicate();

			// Rotate new layer				
			switch (Position){
				case 1 : newStem.rotate(angle * i, AnchorPosition.TOPLEFT); break;
				case 2 : newStem.rotate(angle * i, AnchorPosition.TOPCENTER); break;
				case 3 : newStem.rotate(angle * i, AnchorPosition.TOPRIGHT); break;
				case 4 : newStem.rotate(angle * i, AnchorPosition.MIDDLELEFT); break;
				case 5 : newStem.rotate(angle * i, AnchorPosition.MIDDLECENTER); break;
				case 6 : newStem.rotate(angle * i, AnchorPosition.MIDDLERIGHT); break;
				case 7 : newStem.rotate(angle * i, AnchorPosition.BOTTOMLEFT); break;
				case 8 : newStem.rotate(angle * i, AnchorPosition.BOTTOMCENTER); break;
				case 9 : newStem.rotate(angle * i, AnchorPosition.BOTTOMRIGHT); break;
				case 10 : app.activeDocument.activeLayer = newStem; rotateAroundPosition(angle * i,activeDocument.width/2,activeDocument.height/2); break;
				case 11 : for (var s=0,len=app.activeDocument.colorSamplers.length;s<len;s++) {
							if (s!=0) {
								// Duplicate original layer and save it to the variable
								var newStem = originalStem.duplicate();
							}
							newStem.name = originalStem.name + " " + (i+1) + " p" + (s+1) ;
							app.activeDocument.activeLayer = newStem;
							var colorSamplerRef = app.activeDocument.colorSamplers[s];
							//alert("angle=" + (angle * i) +  " ,x=" + colorSamplerRef.position[0].value + " ,y=" + colorSamplerRef.position[1].value);
							rotateAroundPosition(angle * i,colorSamplerRef.position[0].value,colorSamplerRef.position[1].value);
							newStem.move(stemsGroup, ElementPlacement.PLACEATEND);
		               		}; 
							break; 
				case 12 :	for(var k=0;k<myPathInfo.length;k++){  
								for(var j=0;j<myPathInfo[k].entireSubPath.length;j++){ 
									if (k!=0 || j!=0) {
										// Duplicate original layer and save it to the variable
										var newStem = originalStem.duplicate();
									}
									newStem.name = originalStem.name + " " + (i+1) + " p" + (j+1) ;
									app.activeDocument.activeLayer = newStem;
									rotateAroundPosition(angle * i,myPathInfo[k].entireSubPath[j].anchor[0],myPathInfo[k].entireSubPath[j].anchor[1]);
									newStem.move(stemsGroup, ElementPlacement.PLACEATEND);
								}
							}
							break;
				default : break;
			}

			// Add index to new layers
			if (Position!=11) {
				newStem.name = originalStem.name + " " + (i+1);
				// Place new layer inside stems group
				newStem.move(stemsGroup, ElementPlacement.PLACEATEND);
			}
		};

		// Add index to the original layer
		if (Position!=11) originalStem.name += " 1";
		else originalStem.name += " 1 p1";
		};
		activeDocument.activeLayer = activeDocument.layers[0]; // Target top
		var groupname = app.activeDocument.activeLayer.name // remember name of group  
		var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" ); // this part from  Script Listene -- ungroup group  
		var desc14 = new ActionDescriptor();  
		var idnull = charIDToTypeID( "null" );  
		var ref13 = new ActionReference();  
		var idLyr = charIDToTypeID( "Lyr " );  
		var idOrdn = charIDToTypeID( "Ordn" );  
		var idTrgt = charIDToTypeID( "Trgt" );  
		ref13.putEnumerated( idLyr, idOrdn, idTrgt );  
		desc14.putReference( idnull, ref13 );  
		executeAction( idungroupLayersEvent, desc14, DialogModes.NO );  
		var idMk = charIDToTypeID( "Mk  " ); // this part from  Script Listene --  group selected layers  
		var desc15 = new ActionDescriptor();  
		var idnull = charIDToTypeID( "null" );  
		var ref14 = new ActionReference();  
		var idlayerSection = stringIDToTypeID( "layerSection" );  
		ref14.putClass( idlayerSection );  
		desc15.putReference( idnull, ref14 );  
		var idFrom = charIDToTypeID( "From" );  
		var ref15 = new ActionReference();  
		var idLyr = charIDToTypeID( "Lyr " );  
		var idOrdn = charIDToTypeID( "Ordn" );  
		var idTrgt = charIDToTypeID( "Trgt" );  
		ref15.putEnumerated( idLyr, idOrdn, idTrgt );  
		desc15.putReference( idFrom, ref15 );  
		executeAction( idMk, desc15, DialogModes.NO );  
		app.activeDocument.activeLayer.name = groupname // recall group name  
	}

function rotateAroundPosition(_angle,x,y) {  
    var desc1 = new ActionDescriptor();  
    var desc2 = new ActionDescriptor();  
    var ref1 = new ActionReference();  
    ref1.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));  
    desc1.putReference(charIDToTypeID('null'), ref1);  
    desc1.putEnumerated(charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), stringIDToTypeID("QCSIndependent"));  
    desc2.putUnitDouble(charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), x);  
    desc2.putUnitDouble(charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), y);  
    desc1.putObject(charIDToTypeID('Pstn'), charIDToTypeID('Pnt '), desc2);  
    desc1.putUnitDouble(charIDToTypeID('Angl'), charIDToTypeID('#Ang'), _angle);  
    desc1.putEnumerated(charIDToTypeID('Intr'), charIDToTypeID('Intp'), charIDToTypeID('Bcbc'));  
    executeAction(charIDToTypeID('Trnf'), desc1, DialogModes.NO);  
	}
////// determine selected path //////
function selectedPath () {
	try {
		var ref = new ActionReference(); 
		ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
		var desc = executeActionGet(ref);
		var theName = desc.getString(charIDToTypeID("PthN"));
		return app.activeDocument.pathItems.getByName(theName)
	}
	catch (e) {
		return undefined
	}
};
////// michael l hale’s code //////
function extractSubPathInfo(pathObj){  
    var pathArray = new Array();// each element can be used as the second arugment in pathItems.add ie doc.pathItems.add("myPath1", [pathArray[0]]);  
    var pl = pathObj.subPathItems.length;  
    for(var s=0;s<pl;s++){  
        var pArray = new Array();  
          for(var i=0;i<pathObj.subPathItems[s].pathPoints.length;i++){  
             pArray[i] = new PathPointInfo;  
             pArray[i].kind = pathObj.subPathItems[s].pathPoints[i].kind;  
             pArray[i].anchor = pathObj.subPathItems[s].pathPoints[i].anchor;  
			 //alert("Anchor " + pathObj.subPathItems[s].pathPoints[i].anchor );
             pArray[i].leftDirection = pathObj.subPathItems[s].pathPoints[i].leftDirection;  
             pArray[i].rightDirection = pathObj.subPathItems[s].pathPoints[i].rightDirection;  
          };  
        pathArray[pathArray.length] = new Array();  
        pathArray[pathArray.length - 1] = new SubPathInfo();  
        pathArray[pathArray.length - 1].operation = pathObj.subPathItems[s].operation;  
        pathArray[pathArray.length - 1].closed = pathObj.subPathItems[s].closed;  
        pathArray[pathArray.length - 1].entireSubPath = pArray;  
    };  
    return pathArray;  
}; 

 

 

Capture.jpg

RotateShape.gif

Topics

Actions and scripting, How to, Mac

Views

123

Likes

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
Adobe Community Professional ,
Aug 23, 2020

Copy link to clipboard

Copied

You can draw that line. Then Rotate it with anchor point in the center of the circle.
Press Ctrl+Alt+Shift+T   it will transform again with copy like Ctrl+D in Illustrator.

Likes

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
Reply
Loading...
LEGEND ,
Aug 23, 2020

Copy link to clipboard

Copied

What do you actually need at the end of the operation? 

Twelve separate Shape Layers, just lines on a pixel layer , …? 

Likes

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
Reply
Loading...
Explorer ,
Aug 23, 2020

Copy link to clipboard

Copied

Actually either would work.  The end result would give me a sectioned circle that I would then be able to work in...think designing watch faces, so 12s, 60s, etc

 

If seperate shapre layers, then should I want 12, 3, 6, 9, I could just hide the unrequired layers.

 

I know I can create any of these manually and then use as a template, I was hoping that a script would allow a quick creation should my needs change.  ie, create a watch hand with days of the week, months? This would then let me draw to the path and make sure each centred within it's own section (hope I'm making sense here)

Likes

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
Reply
Loading...
LEGEND ,
Aug 23, 2020

Copy link to clipboard

Copied

Is this about Type Layers? 

Could you please post a sketch or mock-up (including the Layers Panel) to clarify? 

Likes

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
Reply
Loading...
Explorer ,
Aug 23, 2020

Copy link to clipboard

Copied

I'm very new to all this, so not sure if I'm asking the right thing.

 

If I draw a circle, then a line from the centre to the outside, in my mind I then run a script, enter a value (ie, 12) and the script goes off, works out the correct % to evenly segments

the circle and adds more lines.  

 

Like this example (I've only added 2 extra lines here so far, so imagine there are 12 in total (30deg rotation) 

 

thanks

 

Screenshot 2020-08-23 at 12.30.11.png

Likes

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
Reply
Loading...
LEGEND ,
Aug 24, 2020

Copy link to clipboard

Copied

I once posted a Script for creating circularly arranged SO instances (see screenshots).

Screenshot 2020-08-25 at 08.22.12.pngScreenshot 2020-08-25 at 08.22.21.png 

// xonverts to smart object, copies and rotates a layer;
// for photoshop cs5 on mac;
// 2011; use it at your own risk;
#target photoshop
////// filter for checking if entry is numeric and positive, thanks to xbytor //////
posNumberKeystrokeFilter = function() {
	this.text = this.text.replace(",", ".");
	this.text = this.text.replace("-", "");
	if (this.text.match(/[^\-\.\d]/)) {
		this.text = this.text.replace(/[^\-\.\d]/g, '');
		}
	};
posNumberKeystrokeFilter2 = function() {
	this.text = this.text.replace(",", "");
	this.text = this.text.replace("-", "");
	this.text = this.text.replace(".", "");
	if (this.text.match(/[^\-\.\d]/)) {
		this.text = this.text.replace(/[^\-\.\d]/g, '');
		};
	if (this.text == "") {this.text = "2"}
	if (this.text == "1") {this.text = "2"}
	};
////////////////////////////////////
var theCheck = photoshopCheck();
if (theCheck == true) {
// do the operations;
var myDocument = app.activeDocument;
var myResolution = myDocument.resolution;
var originalUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
////////////////////////////////////
var dlg = new Window('dialog', "set circle-radius for arrangement", [500,300,840,450]);
// field for radius;
dlg.radius = dlg.add('panel', [15,17,162,67], 'inner radius');
dlg.radius.number = dlg.radius.add('edittext', [12,12,60,32], "30", {multiline:false});
dlg.radius.numberText = dlg.radius.add('statictext', [65,14,320,32], "mm radius ", {multiline:false});
dlg.radius.number.onChange = posNumberKeystrokeFilter;
dlg.radius.number.active = true;
// field for number;
dlg.number = dlg.add('panel', [172,17,325,67], 'number of copies');
dlg.number.value = dlg.number.add('edittext', [12,12,60,32], "30", {multiline:false});
dlg.number.value.onChange = posNumberKeystrokeFilter2;
dlg.number.value.text = "12";
// buttons for ok, and cancel;
dlg.buttons = dlg.add('panel', [15,80,325,130], '');
dlg.buttons.buildBtn = dlg.buttons.add('button', [13,13,145,35], 'OK', {name:'ok'});
dlg.buttons.cancelBtn = dlg.buttons.add('button', [155,13,290,35], 'Cancel', {name:'cancel'});
// show the dialog;
dlg.center();
var myReturn = dlg.show ();
////////////////////////////////////
if (myReturn == true) {
// the layer;
	var theLayer = smartify(myDocument.activeLayer);
	app.togglePalettes();
// get layer;
	var theName = myDocument.activeLayer.name;
	var theBounds = theLayer.bounds;
	var theWidth = theBounds[2] - theBounds[0];
	var theHeight = theBounds[3] - theBounds[1];
	var theOriginal = myDocument.activeLayer;
	var theHorCenter = (theBounds[0] + ((theBounds[2] - theBounds[0])/2));
	var theVerCenter = (theBounds[1] + ((theBounds[3] - theBounds[1])/2));
// create layerset;
	var myLayerSet = myDocument.layerSets.add();
	theOriginal.visible = false;
	myLayerSet.name = theName + "_rotation";
// create copies;
	var theNumber = dlg.number.value.text;
	var theLayers = new Array;
	for (var o = 0; o < theNumber; o++) {
		var theCopy = theLayer.duplicate(myLayerSet, ElementPlacement.PLACEATBEGINNING);
		theLayers.push(theCopy);
		};
// calculate the radius in pixels;
	var theRadius = Number(dlg.radius.number.text) / 10 * myResolution / 2.54;
	myDocument.selection.deselect();
// get the angle;
	theAngle = 360 / theNumber;
// work through the layers;
	for (var d = 0; d < theNumber; d++) {
		var thisAngle = theAngle * d ;
		var theLayer = theLayers[d];
// determine the offset for outer or inner radius;
		var theMeasure = theRadius + theHeight/2;
//		var theMeasure = theRadius + theWidth/2;
		var theHorTarget = Math.cos(radiansOf(thisAngle)) * theMeasure;
		var theVerTarget = Math.sin(radiansOf(thisAngle)) * theMeasure;
// do the transformations;
		rotateAndMove(myDocument, theLayer, thisAngle + 90, - theHorCenter + theHorTarget + (myDocument.width / 2), - theVerCenter + theVerTarget + (myDocument.height / 2));
		};
	};
// reset;
app.preferences.rulerUnits = originalUnits;
app.togglePalettes()
};
////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
////// function to determine if open document is eligible for operations //////
function photoshopCheck () {
var checksOut = true;
if (app.documents.length == 0) {
	alert ("no open document");
	checksOut = false
	}
else {
	if (app.activeDocument.activeLayer.isBackgroundLayer == true) {
		alert ("please select a non background layer");
		checksOut = false
		}
	else {}
	};
return checksOut
};
////// function to smartify if not //////
function smartify (theLayer) {
// make layers smart objects if they are not already;
	if (theLayer.kind != LayerKind.SMARTOBJECT) {
		myDocument.activeLayer = theLayer;
		var id557 = charIDToTypeID( "slct" );
		var desc108 = new ActionDescriptor();
		var id558 = charIDToTypeID( "null" );
		var ref77 = new ActionReference();
		var id559 = charIDToTypeID( "Mn  " );
		var id560 = charIDToTypeID( "MnIt" );
		var id561 = stringIDToTypeID( "newPlacedLayer" );
		ref77.putEnumerated( id559, id560, id561 );
		desc108.putReference( id558, ref77 );
		executeAction( id557, desc108, DialogModes.NO );
		return myDocument.activeLayer
		};
	else {return theLayer}
	};
////// radians //////
function radiansOf (theAngle) {
	return theAngle * Math.PI / 180
	};
////// rotate and move //////
function rotateAndMove (myDocument, theLayer, thisAngle, horizontalOffset, verticalOffset) {
// do the transformations;
myDocument.activeLayer = theLayer;
// =======================================================
var idTrnf = charIDToTypeID( "Trnf" );
    var desc3 = new ActionDescriptor();
    var idFTcs = charIDToTypeID( "FTcs" );
    var idQCSt = charIDToTypeID( "QCSt" );
    var idQcsa = charIDToTypeID( "Qcsa" );
    desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
    var idOfst = charIDToTypeID( "Ofst" );
        var desc4 = new ActionDescriptor();
        var idHrzn = charIDToTypeID( "Hrzn" );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc4.putUnitDouble( idHrzn, idPxl, horizontalOffset );
        var idVrtc = charIDToTypeID( "Vrtc" );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc4.putUnitDouble( idVrtc, idPxl, verticalOffset );
    var idOfst = charIDToTypeID( "Ofst" );
    desc3.putObject( idOfst, idOfst, desc4 );
    var idAngl = charIDToTypeID( "Angl" );
    var idAng = charIDToTypeID( "#Ang" );
    desc3.putUnitDouble( idAngl, idAng, Number(thisAngle) );
executeAction( idTrnf, desc3, DialogModes.NO );
};

 

https://community.adobe.com/t5/photoshop/how-do-i-make-this-type-of-stamp-in-photoshop/m-p/11142325?...

Likes

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
Reply
Loading...
Explorer ,
Aug 25, 2020

Copy link to clipboard

Copied

Thank you!

 

That does the trick, and what i was looking for.

 

thanks again!

Likes

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
Reply
Loading...
Most Valuable Participant ,
Aug 25, 2020

Copy link to clipboard

Copied

 

With Transform and Layers and scripts you can do all sort of layer duplicating and rotating. Create a stroke Shape fill or no fill  have fun rotating it.

// 2015  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 {
	//Set First Time Defaults here
	var dfltCpys = 12;	// default number of copies including the original
	var dfltPos = 4;	// default Middle Center
	//End Defaults
	
	var Prefs ={}; //Object to hold preferences.
	var prefsFile = File(Folder.temp + "/RotateLayerAboutPreferences.dat");
	//If preferences do not exit use Defaults from above
	if(!prefsFile.exists){
		Prefs.Cpys  = dfltCpys;
		Prefs.Pos  = dfltPos;
		prefsFile.open('w');
		prefsFile.write(Prefs.toSource());
		prefsFile.close();
	}
	else{//Preferences exist so open them
		prefsFile.open('r');
		Prefs = eval(prefsFile.read());
		prefsFile.close();
	}
	
	try {
		
		function createDialog(){
		// begin dialog layout
		var DupRotateDialog = new Window('dialog');
		DupRotateDialog.text = 'Duplicate and Rotate Layer';
		DupRotateDialog.frameLocation = [78, 100];
		DupRotateDialog.alignChildren = 'center';

		DupRotateDialog.NumLayerPnl = DupRotateDialog.add('panel', [2, 2, 300, 56], 'Number of Layers and Rotation Anchor Point');
			DupRotateDialog.NumLayerPnl.add('statictext', [10, 16, 50, 48], 'Copies ');
			DupRotateDialog.NumLayerPnl.imgCpysEdt = DupRotateDialog.NumLayerPnl.add('edittext', [50, 13, 90, 34], Prefs.Cpys, {name:'imgCpys'});
			DupRotateDialog.NumLayerPnl.imgCpysEdt.helpTip = 'Number of copies of selected Layer';
			
			DupRotateDialog.NumLayerPnl.add('statictext',[96, 16, 240, 48],'Location');
			var position =['Top Left','Top Center','Top Right','Center Left','Center','Center Right','Bottom Left','Bottom Center','Bottom Right','Doc Center','Samples','Path Points'];
			DupRotateDialog.NumLayerPnl.dd1 = DupRotateDialog.NumLayerPnl.add('dropdownlist',[150, 13, 260, 34],position);
			DupRotateDialog.NumLayerPnl.dd1.selection=Prefs.Pos;
	
		var buttons = DupRotateDialog.add('group');
			buttons.orientation = 'row';
				var okBtn = buttons.add('button');
			okBtn.text = 'OK';
			okBtn.properties = {name: 'ok'};
				var cancelBtn = buttons.add('button');
			cancelBtn.text = 'Cancel';
			cancelBtn.properties = {name: 'cancel'};
		return DupRotateDialog;
		}
				
		dispdlg(createDialog());
		function dispdlg(DupRotateDialog){ 
			// display dialog and only continues on OK button press (OK = 1, Cancel = 2)
			DupRotateDialog.onShow = function() {
				var ww = DupRotateDialog.bounds.width;  
				var hh = DupRotateDialog.bounds.height;  
				DupRotateDialog.bounds.x  = 78;  
				DupRotateDialog.bounds.y  = 100;  
				DupRotateDialog.bounds.width  = ww;  
				DupRotateDialog.bounds.height  = hh;  
			}
			if (DupRotateDialog.show() == 1) {
				//variables passed from user interface
				var copies	= String(DupRotateDialog.NumLayerPnl.imgCpys.text); if (copies=="") { copies = Prefs.Cpys;}
				if (isNaN(copies)) { alert("Non numeric value entered"); dispdlg(createDialog());}
				else {
					if (copies<2 || copies>360) { alert("Number of layer allow is 2 to 360"); dispdlg(createDialog());}  // Not in range
					else {
						var AnchorPoint = Number(DupRotateDialog.NumLayerPnl.dd1.selection.index) + 1;
						cTID = function(s) { return app.charIDToTypeID(s); };
						sTID = function(s) { return app.stringIDToTypeID(s); };
						// Save the current preferences
						Prefs.Cpys  = copies;
						Prefs.Pos  = Number(DupRotateDialog.NumLayerPnl.dd1.selection.index);
						prefsFile.open('w');
						prefsFile.write(Prefs.toSource());
						prefsFile.close();
						var startRulerUnits = app.preferences.rulerUnits;
						var startTypeUnits = app.preferences.typeUnits;
						var startDisplayDialogs = app.displayDialogs;
						// Set Photoshop to use pixels and display no dialogs
						app.preferences.rulerUnits = Units.PIXELS;
						app.preferences.typeUnits = TypeUnits.PIXELS;
						app.displayDialogs = DialogModes.NO;
						app.togglePalettes();
						try { app.activeDocument.suspendHistory('RotateLayerAbout','main(copies, AnchorPoint)' );} 
						catch(e) {alert(e + ': on line ' + e.line);} 
						// Return the app preferences
						app.togglePalettes();
						app.preferences.rulerUnits = startRulerUnits;
						app.preferences.typeUnits = startTypeUnits;
						app.displayDialogs = startDisplayDialogs;
					}
				}
			}
			else {
				//alert('Operation Canceled.');
			}
		}		
	}
	catch(err){
		// Lot's of things can go wrong, Give a generic alert and see if they want the details
		if ( confirm("Sorry, something major happened and I can't continue! Would you like to see more info?" ) ) { alert(err + ': on line ' + err.line ); }
	}
}
	
function main(stemsAmount, Position) {
	if  (  Position == 11 && app.activeDocument.colorSamplers.length==0 ) {
		alert("No Color Sampler set");
		return;
	}
	if  (  Position == 12 ) {
		var thePath = selectedPath();
		if (thePath == undefined) {
			alert("No Path Selected");
			return;
		}
		var myPathInfo = extractSubPathInfo(thePath);  
	}
	// Save selected layer to variable:
	var originalStem = app.activeDocument.activeLayer;
	// Run the copying process
	if(stemsAmount != null){ 
		// Calculate the rotation angle
		var angle = 360 / parseInt(stemsAmount);

		// Create a group for stems
		var stemsGroup = app.activeDocument.layerSets.add();
			stemsGroup.name = originalStem.name + " ("+stemsAmount+" stems)";
		// Place original layer in group
		originalStem.move(stemsGroup, ElementPlacement.INSIDE);

		// Duplicate and rotate layers:
		for(var i = 1; i < stemsAmount; i++){
			// Duplicate original layer and save it to the variable
			var newStem = originalStem.duplicate();

			// Rotate new layer				
			switch (Position){
				case 1 : newStem.rotate(angle * i, AnchorPosition.TOPLEFT); break;
				case 2 : newStem.rotate(angle * i, AnchorPosition.TOPCENTER); break;
				case 3 : newStem.rotate(angle * i, AnchorPosition.TOPRIGHT); break;
				case 4 : newStem.rotate(angle * i, AnchorPosition.MIDDLELEFT); break;
				case 5 : newStem.rotate(angle * i, AnchorPosition.MIDDLECENTER); break;
				case 6 : newStem.rotate(angle * i, AnchorPosition.MIDDLERIGHT); break;
				case 7 : newStem.rotate(angle * i, AnchorPosition.BOTTOMLEFT); break;
				case 8 : newStem.rotate(angle * i, AnchorPosition.BOTTOMCENTER); break;
				case 9 : newStem.rotate(angle * i, AnchorPosition.BOTTOMRIGHT); break;
				case 10 : app.activeDocument.activeLayer = newStem; rotateAroundPosition(angle * i,activeDocument.width/2,activeDocument.height/2); break;
				case 11 : for (var s=0,len=app.activeDocument.colorSamplers.length;s<len;s++) {
							if (s!=0) {
								// Duplicate original layer and save it to the variable
								var newStem = originalStem.duplicate();
							}
							newStem.name = originalStem.name + " " + (i+1) + " p" + (s+1) ;
							app.activeDocument.activeLayer = newStem;
							var colorSamplerRef = app.activeDocument.colorSamplers[s];
							//alert("angle=" + (angle * i) +  " ,x=" + colorSamplerRef.position[0].value + " ,y=" + colorSamplerRef.position[1].value);
							rotateAroundPosition(angle * i,colorSamplerRef.position[0].value,colorSamplerRef.position[1].value);
							newStem.move(stemsGroup, ElementPlacement.PLACEATEND);
		               		}; 
							break; 
				case 12 :	for(var k=0;k<myPathInfo.length;k++){  
								for(var j=0;j<myPathInfo[k].entireSubPath.length;j++){ 
									if (k!=0 || j!=0) {
										// Duplicate original layer and save it to the variable
										var newStem = originalStem.duplicate();
									}
									newStem.name = originalStem.name + " " + (i+1) + " p" + (j+1) ;
									app.activeDocument.activeLayer = newStem;
									rotateAroundPosition(angle * i,myPathInfo[k].entireSubPath[j].anchor[0],myPathInfo[k].entireSubPath[j].anchor[1]);
									newStem.move(stemsGroup, ElementPlacement.PLACEATEND);
								}
							}
							break;
				default : break;
			}

			// Add index to new layers
			if (Position!=11) {
				newStem.name = originalStem.name + " " + (i+1);
				// Place new layer inside stems group
				newStem.move(stemsGroup, ElementPlacement.PLACEATEND);
			}
		};

		// Add index to the original layer
		if (Position!=11) originalStem.name += " 1";
		else originalStem.name += " 1 p1";
		};
		activeDocument.activeLayer = activeDocument.layers[0]; // Target top
		var groupname = app.activeDocument.activeLayer.name // remember name of group  
		var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" ); // this part from  Script Listene -- ungroup group  
		var desc14 = new ActionDescriptor();  
		var idnull = charIDToTypeID( "null" );  
		var ref13 = new ActionReference();  
		var idLyr = charIDToTypeID( "Lyr " );  
		var idOrdn = charIDToTypeID( "Ordn" );  
		var idTrgt = charIDToTypeID( "Trgt" );  
		ref13.putEnumerated( idLyr, idOrdn, idTrgt );  
		desc14.putReference( idnull, ref13 );  
		executeAction( idungroupLayersEvent, desc14, DialogModes.NO );  
		var idMk = charIDToTypeID( "Mk  " ); // this part from  Script Listene --  group selected layers  
		var desc15 = new ActionDescriptor();  
		var idnull = charIDToTypeID( "null" );  
		var ref14 = new ActionReference();  
		var idlayerSection = stringIDToTypeID( "layerSection" );  
		ref14.putClass( idlayerSection );  
		desc15.putReference( idnull, ref14 );  
		var idFrom = charIDToTypeID( "From" );  
		var ref15 = new ActionReference();  
		var idLyr = charIDToTypeID( "Lyr " );  
		var idOrdn = charIDToTypeID( "Ordn" );  
		var idTrgt = charIDToTypeID( "Trgt" );  
		ref15.putEnumerated( idLyr, idOrdn, idTrgt );  
		desc15.putReference( idFrom, ref15 );  
		executeAction( idMk, desc15, DialogModes.NO );  
		app.activeDocument.activeLayer.name = groupname // recall group name  
	}

function rotateAroundPosition(_angle,x,y) {  
    var desc1 = new ActionDescriptor();  
    var desc2 = new ActionDescriptor();  
    var ref1 = new ActionReference();  
    ref1.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));  
    desc1.putReference(charIDToTypeID('null'), ref1);  
    desc1.putEnumerated(charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), stringIDToTypeID("QCSIndependent"));  
    desc2.putUnitDouble(charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), x);  
    desc2.putUnitDouble(charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), y);  
    desc1.putObject(charIDToTypeID('Pstn'), charIDToTypeID('Pnt '), desc2);  
    desc1.putUnitDouble(charIDToTypeID('Angl'), charIDToTypeID('#Ang'), _angle);  
    desc1.putEnumerated(charIDToTypeID('Intr'), charIDToTypeID('Intp'), charIDToTypeID('Bcbc'));  
    executeAction(charIDToTypeID('Trnf'), desc1, DialogModes.NO);  
	}
////// determine selected path //////
function selectedPath () {
	try {
		var ref = new ActionReference(); 
		ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
		var desc = executeActionGet(ref);
		var theName = desc.getString(charIDToTypeID("PthN"));
		return app.activeDocument.pathItems.getByName(theName)
	}
	catch (e) {
		return undefined
	}
};
////// michael l hale’s code //////
function extractSubPathInfo(pathObj){  
    var pathArray = new Array();// each element can be used as the second arugment in pathItems.add ie doc.pathItems.add("myPath1", [pathArray[0]]);  
    var pl = pathObj.subPathItems.length;  
    for(var s=0;s<pl;s++){  
        var pArray = new Array();  
          for(var i=0;i<pathObj.subPathItems[s].pathPoints.length;i++){  
             pArray[i] = new PathPointInfo;  
             pArray[i].kind = pathObj.subPathItems[s].pathPoints[i].kind;  
             pArray[i].anchor = pathObj.subPathItems[s].pathPoints[i].anchor;  
			 //alert("Anchor " + pathObj.subPathItems[s].pathPoints[i].anchor );
             pArray[i].leftDirection = pathObj.subPathItems[s].pathPoints[i].leftDirection;  
             pArray[i].rightDirection = pathObj.subPathItems[s].pathPoints[i].rightDirection;  
          };  
        pathArray[pathArray.length] = new Array();  
        pathArray[pathArray.length - 1] = new SubPathInfo();  
        pathArray[pathArray.length - 1].operation = pathObj.subPathItems[s].operation;  
        pathArray[pathArray.length - 1].closed = pathObj.subPathItems[s].closed;  
        pathArray[pathArray.length - 1].entireSubPath = pArray;  
    };  
    return pathArray;  
}; 

 

 

Capture.jpg

RotateShape.gif

JJMack

Likes

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
Reply
Loading...
Explorer ,
Aug 25, 2020

Copy link to clipboard

Copied

Thank you, I'll have hours of fun playing with that 🙂

 

Now I wish I could create scripts, waaaay beyond my brain!

 

thanks again.

Likes

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
Reply
Loading...
Most Valuable Participant ,
Aug 23, 2020

Copy link to clipboard

Copied

You may be able to to code a script toe uset action managet code the use the marquee tool set to mags a elipytal selection withe a 1:1 aspect ratio. Like my Aspect Ratio Selection plugin does to make Path or Selection.  I developed the Plug in so it for Actions to Crop and mahe Hats anf frames for images.

Capture.jpg

JJMack

Likes

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
Reply
Loading...
Most Valuable Participant ,
Aug 23, 2020

Copy link to clipboard

Copied

Here is the function I used

	// ============================================================================================================
	// Reset Vars Used and create some alias to make things easier for this hacker
	// ============================================================================================================ */
	var type	= "None Set";
	var shape	= "None Set";
	// vars	for shape
	var rectangle	="Rctn";
	var ellipse	="Elps";
	// vars	for Path
	var doPath 	= false;
	// vars	for type
	var diminish	=SelectionType.DIMINISH
	var subtract	=SelectionType.DIMINISH
	var extend	=SelectionType.EXTEND
	var add		=SelectionType.EXTEND
	var intersect	=SelectionType.INTERSECT
	var replace	=SelectionType.REPLACE
	/* ============================================================================================================
	// end vars and Aliases
	// ============================================================================================================ */

 

/* SetMarqueeSelection function from Scriptlistner plugin
// ========================================================================== */
function setMarqueeSelection(x1, y1, x2, y2, type, shape, feather, antiAlias, doPath) {
	if (doPath ==null) { doPath = false; }
	var SelectionType =null;
	if (type ==null)      {	var SelectionType = "setd" }
	if (type ==diminish)  {	var SelectionType = "SbtF" }
	if (type ==extend)    {	var SelectionType = "AddT" }
	if (type ==intersect) {	var SelectionType = "IntW" }
	if (type ==replace)   {	var SelectionType = "setd" }

	var id3	= charIDToTypeID( SelectionType	);
	    var	desc2 =	new ActionDescriptor();
	    var	id4 = charIDToTypeID( "null" );
		var ref1 = new ActionReference();
		if (doPath) {
			var id5	= charIDToTypeID( "Path" );
			var id6	= charIDToTypeID( "WrPt" );
			}
		else {
			var id5	= charIDToTypeID( "Chnl" );
			var id6	= charIDToTypeID( "fsel" );
			}
		ref1.putProperty( id5, id6 );
	    desc2.putReference(	id4, ref1 );
	    var	id7 = charIDToTypeID( "T   " );
		var desc3 = new	ActionDescriptor();
		var id8	= charIDToTypeID( "Top " );
		var id9	= charIDToTypeID( "#Pxl" );
		desc3.putUnitDouble( id8, id9, y1 );
		var id10 = charIDToTypeID( "Left" );
		var id11 = charIDToTypeID( "#Pxl" );
		desc3.putUnitDouble( id10, id11, x1 );
		var id12 = charIDToTypeID( "Btom" );
		var id13 = charIDToTypeID( "#Pxl" );
		desc3.putUnitDouble( id12, id13, y2 );
		var id14 = charIDToTypeID( "Rght" );
		var id15 = charIDToTypeID( "#Pxl" );
		desc3.putUnitDouble( id14, id15, x2 );
	    var	id16 = charIDToTypeID( shape );
	    desc2.putObject( id7, id16,	desc3 );
	    var	id17 = charIDToTypeID( "Fthr" );
	    var	id18 = charIDToTypeID( "#Pxl" );
	    desc2.putUnitDouble( id17, id18, feather );
	    var	id19 = charIDToTypeID( "AntA" );
	    desc2.putBoolean( id19, antiAlias );
	executeAction( id3, desc2, DialogModes.NO );
}

 

 

JJMack

Likes

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
Reply
Loading...
Adobe Community Professional ,
Aug 26, 2020

Copy link to clipboard

Copied

Likes

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
Reply
Loading...