What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Scripting Document Creation help.


Sator

New Member
Messages
2
Likes
0
Hi! I am a noob in Photoshop scripting and i'm asking Gemini for help in starting, however, gemini is not perfect. I believe it has an outdated datasource when creating a new document.
It tells me to use
Code:
app.documents.add(width, height, resolution, name);
, with my values of width, height and resolution being: 900px, 13000px and 300. However i end up with this screen when I run the script (image below), as you see, width and height are nowhere near the actual width and height. My guess is that the function has been updated and adds new arguments, but I haven't been able to find the new arguments needed. Any help?
4a0FaIp.png
 
JavaScript:
app.documents.add(UnitValue(900, "px"), UnitValue(13000, "px"),300,"MyDocument", NewDocumentMode.RGB);

@Sator - As correctly indicated by [ iLLuSioN ] – you need to explicitly set ruler units, unless you know (not assume) that the current ruler units are correct (px). You should always compare AI-generated code to the docs, as sometimes generative LLMs provide fake, non-existent code to be "helpful", sometimes referred to as a "hallucination":

https://theiviaxx.github.io/photoshop-docs/Photoshop/Documents/add.html#documents-add

Another equivalent approach, where the original ruler units are captured in a variable, then the ruler units are set to px and a new document is created, before returning the original ruler units:

JavaScript:
// Set the ruler units
var origUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

app.documents.add(900, 13000, 300, "MyDocument", NewDocumentMode.RGB);

// Restore the original ruler units
app.preferences.rulerUnits = origUnits;

Happy coding!
 
JavaScript:
app.documents.add(UnitValue(900, "px"), UnitValue(13000, "px"),300,"MyDocument", NewDocumentMode.RGB);
@Sator - As correctly indicated by [ iLLuSioN ] – you need to explicitly set ruler units, unless you know (not assume) that the current ruler units are correct (px). You should always compare AI-generated code to the docs, as sometimes generative LLMs provide fake, non-existent code to be "helpful", sometimes referred to as a "hallucination":

https://theiviaxx.github.io/photoshop-docs/Photoshop/Documents/add.html#documents-add

Another equivalent approach, where the original ruler units are captured in a variable, then the ruler units are set to px and a new document is created, before returning the original ruler units:

JavaScript:
// Set the ruler units
var origUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

app.documents.add(900, 13000, 300, "MyDocument", NewDocumentMode.RGB);

// Restore the original ruler units
app.preferences.rulerUnits = origUnits;

Happy coding!
Thank you both! It really helped! Now it goes like a charm!
 

Back
Top