Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Order of additive elements changes output

Community Beginner ,
May 16, 2023 May 16, 2023

I'm writing a small javascript to automate file setup, and part of it needs to copy one section of the file onto another area.  The second selection is dependent on the size of the file, so I did some simple addition to find the right location:

 

51.5-(startWidth+1.5), where startWidth is assigned from app.activeDocument.width
 
If startWidth is 18, it should add up to 32, but when passed into a prompt to check I noticed it was actually -32 inches.
 
And even more strange, if I change the order of operations to -(startWidth+1.5)+51, it calculates correctly to 32 inches

 

Does anyone know what could be causing this?

 

 

Using Photoshop 2023 on Mac OS Big Sur

 

Thanks!

TOPICS
Actions and scripting
1.1K
Translate
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
Adobe
Community Expert ,
May 16, 2023 May 16, 2023

Have you explicitly set inches as the required ruler units?

Translate
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
Community Beginner ,
May 16, 2023 May 16, 2023

Yes, for both ruler and type.  

Translate
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
People's Champ ,
May 16, 2023 May 16, 2023
Show the full code, including the one where you use "passed into a prompt".
 
 
Translate
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
Community Beginner ,
May 16, 2023 May 16, 2023

Here's the most relevant pieces, just tested it myself on a 20x20 blank new file

 

app.preferences.rulerUnits = Units.INCHES
app.preferences.TypeUnits = Units.INCHES

fileWidth = app.activeDocument.width

prompt(-(fileWidth)+51.5)
prompt(51.5-fileWidth)
 
The prompts give a positive number for one, and a negative for the other... but mathematically there should be no difference
Translate
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
People's Champ ,
May 16, 2023 May 16, 2023

app.preferences.rulerUnits = Units.INCHES
app.preferences.TypeUnits = Units.INCHES

fileWidth = app.activeDocument.width.value

alert(fileWidth)

prompt("This is the title (hint). The result is below the line.", -(fileWidth)+51.5)
prompt("This is the title (hint). The result is below the line.", 51.5-fileWidth)

Translate
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
Community Beginner ,
May 17, 2023 May 17, 2023

Thanks!

 

Pulling the unitless value fixes the issue.

Still curious why the units would cause it in the first place...

Translate
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
People's Champ ,
May 17, 2023 May 17, 2023
LATEST
Most likely this is a bug. According to the documentation, this should not be the case.
zzzz.jpg
Translate
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