• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
2

Create a shape with the same size as the stroke of a text layer using the script

Explorer ,
Jan 16, 2024 Jan 16, 2024

Copy link to clipboard

Copied

I want to create a script that can create a shape (circle, ellipse, or square) that is the same size as the text layer's stroke (e.g. 100px). Runs only on the current file.
I have combined a script to fill layer with canvas and some actions. But still have to open a new file to get the exact size. Does anyone have any better ideas?

 

Tin34323463s0sm_1-1705406952622.png

 

TOPICS
Actions and scripting

Views

1.2K

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 2 Correct answers

Community Expert , Jan 16, 2024 Jan 16, 2024

The third argument of the function Ā»ellipseShapeLayerĀ« is the Stroke Width (3 in the code I posted), feel free to change it. 

 

quote

I also cannot add other effects like gradients, color overlays to this dialog.

Please explain what you mean with screenshots. 

Votes

Translate

Translate
Community Expert , Jan 21, 2024 Jan 21, 2024

Screenshot 2024-01-21 at 14.10.44.pngScreenshot 2024-01-21 at 14.10.50.png

// create custom shape layer based on layer bounds including styles;
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var layerDesc = executeActionGet(ref);
var b1 = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var b2 = layerDesc.getObjectValue(strin
...

Votes

Translate

Translate
Adobe
New Here ,
Jan 20, 2024 Jan 20, 2024

Copy link to clipboard

Copied

The function Ā»ellipseShapeLayerĀ« takes the Stroke Width as its third argument, which is set to 3 in the provided code. You can modify this value as needed.

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 20, 2024 Jan 20, 2024

Copy link to clipboard

Copied

I tried changing this parameter from 3 to 1. But the stroke became 12.5px instead of 3px.

Nahidku_1-1705821771311.png

 

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
New Here ,
Jan 20, 2024 Jan 20, 2024

Copy link to clipboard

Copied

To create a script that automatically creates a shape (circle, ellipse, or square) with the same size as the text layer's stroke in Photoshop and runs only on the current file, you can use the following JavaScript code. This script assumes that the text layer with the stroke is selected.

javascriptCopy code
// Ensure we have an active document if (app.activeDocument) { var textLayer = app.activeDocument.activeLayer; // Check if the active layer is a text layer if (textLayer.kind == LayerKind.TEXT) { // Get the size of the text layer's stroke var strokeSize = textLayer.textItem.strokeWidth; // Create a new shape layer (circle, ellipse, or square) var shapeLayer = createShapeLayer(strokeSize); // Select the new shape layer shapeLayer.selected = true; } else { alert("Please select a text layer with a stroke."); } } else { alert("Open a document before running this script."); } // Function to create a shape layer with the specified size function createShapeLayer(size) { // Create a new shape layer var shapeLayer = app.activeDocument.artLayers.add(); shapeLayer.kind = LayerKind.SHAPE; shapeLayer.name = "Shape Layer"; // Set the shape color (you can customize this) var shapeColor = new SolidColor(); shapeColor.rgb.red = 255; shapeColor.rgb.green = 0; shapeColor.rgb.blue = 0; // Create a new ellipse shape path var ellipsePath = shapeLayer.pathItems.ellipse( app.activeDocument.width / 2 - size / 2, app.activeDocument.height / 2 - size / 2, size, size ); // Fill the shape with the specified color shapeLayer.fill = shapeColor; return shapeLayer; }

This script checks if there is an active document and if the active layer is a text layer. If conditions are met, it gets the stroke size of the text layer and creates a new shape layer (ellipse, circle, or square) with the same size. Adjust the color and shape type as needed. Save this script with a .jsx extension and run it from the Photoshop Scripts menu.

 

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 21, 2024 Jan 21, 2024

Copy link to clipboard

Copied

Thank you for the script. When I run this message appears. Btw, I'm stuck with custom shape for now...

 

Nahidku_1-1705824880346.png

 

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