Text moves after content change

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Megals
Posts: 3
Joined: Wed Jan 18, 2023 2:52 pm

Text moves after content change

Post by Megals »

Hi Ps-scripts Forum,

when i change the content of a pathed text layer, the whole text moves like 50px to the bottom.

After this code, the whole layer moves:

Code: Select all

layer.textItem.contents = text;
- The original file (12283 x 9134) does not have this issue. It only happens to the resized file(720 x 535)
- I also tried to store the original position and reapply it after the change, but nothing happens, maybe i did it wrong.
- PS2022

Any ideas what is happening here?

Best Regards
Chris
User avatar
Kukurykus
Posts: 506
Joined: Mon Jul 25, 2016 12:36 pm

Re: Text moves after content change

Post by Kukurykus »

Put whole code (at least the working part till the said part) and upload compressed psd files (one for each dimension), so I'll test it for you.

Ps. so far in PS 2023 I created bigger document with resolution 72, added some text, then resized document, finally tried with no problem this code:

Code: Select all

activeDocument.activeLayer.textItem.contents = 'text'
Megals
Posts: 3
Joined: Wed Jan 18, 2023 2:52 pm

Re: Text moves after content change

Post by Megals »

Hi,

i packed a zip with 2 psd and the jsx for you to test. I also checked with 2023 but its still the same.
Attachments
test.zip
(368.03 KiB) Downloaded 3 times
User avatar
Kukurykus
Posts: 506
Joined: Mon Jul 25, 2016 12:36 pm

Re: Text moves after content change

Post by Kukurykus »

I reproduced it. It seems to be a bug when using Document Object Model. Happily it works correctly with Action Manager code:

Code: Select all

sTT = stringIDToTypeID, txt = 'Text1 & Text2  Text1 & Text2  Text1 & Text2  Text1 & Text2  ';
(ref = new ActionReference()).putEnumerated(sTT('textLayer'), sTT('ordinal'), sTT('targetEnum'));
(dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref); (dsc2 = new ActionDescriptor())
.putString(sTT('textKey'), txt), dsc1.putObject(sTT('to'), sTT('textLayer'), dsc2),
executeAction(sTT('set'), dsc1)
Megals
Posts: 3
Joined: Wed Jan 18, 2023 2:52 pm

Re: Text moves after content change

Post by Megals »

ok great that there is a solution! Is there a way to use a layer by name with Document Object Model:

Code: Select all

var textLayer = activeDocument.artLayers.getByName('text');
User avatar
Kukurykus
Posts: 506
Joined: Mon Jul 25, 2016 12:36 pm

Re: Text moves after content change

Post by Kukurykus »

You want to set certain layer to be active one? If so then use this code:

Code: Select all

with(activeDocument) activeLayer = artLayers.getByName('text')