Copy link to clipboard
Copied
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
; }
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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..
Copy link to clipboard
Copied
Very sorry about the inconvenience, but I believe I isolated the problem to another script that I use very often (often enough that I forgot it was a script). That script was unintentionally setting "DialogModes.NO". I have no idea how that lead to all my problems, or why it only happened after updating to 2018, but fixing that also fixed my split script. Thanks!
Copy link to clipboard
Copied
I still feel the units.pixel is required and its you position statement need fixing I do not know JavaScript I just hack at it some. I do not understand you positioning statement math I hack a bit on that statement.
tmp.textItem.position = [Number(pos[0])+(Number(sze)*Number(DPI)*k*.032), Number(pos[1])];
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 = [Number(pos[0])+(Number(sze)*Number(DPI)*k*.032), Number(pos[1])];
tmp.textItem.contents = textArray
; }
app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings