Skip to main content
gdwd
Known Participant
November 7, 2017
Question

Photoshop CC 2018 Freezes When Running Scripts

  • November 7, 2017
  • 1 reply
  • 1700 views

I have two simple scripts that split one text layer into multiple text layers. One creates a new text object for every character, one creates a new text object for every word (characters separated by a space). These scripts functioned as intended in previous versions of Photoshop. With the 2018 update, Photoshop will sometimes lock up when I use these scripts, necessitating a force close with Task Manager.

Here is an example. Text layer before script:

Text layers after script (intended):

Text later after script (Photoshop freezes):

When Photoshop freezes, toolbar, menu, and tool buttons can be clicked, but do not do anything. The layer panel is completely frozen, which I think might be related to the cause. Text becomes selected, cannot be unselected. No layers are created, the base layer is just edited. This issue does not always occur; it seems more likely to happen the longer Photoshop has been open.

Was something changed in the 2018 update with regard to scripting? If so, what do I have to change to fix my script? Or is there some problem with Photoshop itself?

Here is the script being used:

doc = app.activeDocument;

layer = doc.activeLayer;

var text = layer.textItem.contents;

var textArray = text.split(" ") || text.split("/r");

var pos = layer.textItem.position;

var sze = layer.textItem.size;

var DPI = app.activeDocument.resolution;

layer.textItem.contents = textArray[0];

layer.name = textArray[0];

for (var k=1; k<textArray.length; k++){

    tmp = layer.duplicate();

    tmp.textItem.position = [pos[0]+(Number(sze)*Number(DPI)*k*.015), pos[1]];

    tmp.textItem.contents = textArray;

}

This topic has been closed for replies.

1 reply

JJMack
Community Expert
Community Expert
November 7, 2017

Does the help

var orig_ruler_units = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS

doc = app.activeDocument; 

layer = doc.activeLayer; 

 

var text = layer.textItem.contents; 

var textArray = text.split(" ") || text.split("/r"); 

 

var pos = layer.textItem.position; 

var sze = layer.textItem.size; 

var DPI = app.activeDocument.resolution; 

layer.textItem.contents = textArray[0]; 

layer.name = textArray[0]; 

for (var k=1; k<textArray.length; k++){ 

    tmp = layer.duplicate(); 

    tmp.textItem.position = [pos+(Number(sze)*Number(DPI)*k*.015), pos[1]]; 

    tmp.textItem.contents = textArray

}

app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings

JJMack
gdwd
gdwdAuthor
Known Participant
November 7, 2017

Unfortunately that change doesn't prevent the crash from happening. Oddly enough, it seems like any time the script would cause a freeze, "app.preferences.rulerUnits = Units.PIXELS;" opens the units preferences screen instead of just doing it.

JJMack
Community Expert
Community Expert
November 7, 2017

What OS are you using.  If Photoshop crashes post the crash report.  If Photoshop hangs what is it hanging on?  I needed to add units pixels because the script would fail to add text to the duped text layers. position was most likely off. Photoshop CC 2018 on my Windows 10 machine never crashed or hung.  The text layers added were empty and the original text layer was edited to the first word..

JJMack