creating guides at 25% of doc and 50%

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

lukasz

creating guides at 25% of doc and 50%

Post by lukasz »

I'm trying to create a vertical guide at 25% and 50% of a document, I tried using code provided in scripting guide but it returns: "cannot convert"

Code: Select allvar half = app.activeDocument.width/2;
var SF = app.activeDocument.width*.75;
activeDocument.guides.add (Direction.HORIZONTAL,UnitValue(half,half))
activeDocument.guides.add (Direction.HORIZONTAL,UnitValue(SF,SF))

tried reading this post but was VERY confused. no idea what is going on there, not even sure if that is what I need.
bb/viewtopic.php?f=13&t=2818
Mike Hale

creating guides at 25% of doc and 50%

Post by Mike Hale »

That other topic was for dealing with guides before CS5 which added them to the DOM.

There are several things wrong with your code.

Code: Select all// this is one way to fix
var half = app.activeDocument.width.value/2;// width is a unitvalue, just get the value
var SF = app.activeDocument.width.value*.75;
activeDocument.guides.add (Direction.VERTICAL, new UnitValue(half,app.activeDocument.width.unit));// if you want a guide at 50% of the width you need a vertical guide
activeDocument.guides.add (Direction.VERTICAL, new UnitValue(SF,app.activeDocument.width.unit));// unitvalue takes two arguments, a number for value and a string for unit

Or because width is already a unitvalue
Code: Select allvar half = app.activeDocument.width/2;
var SF = app.activeDocument.width*.75;
activeDocument.guides.add (Direction.VERTICAL, half);
activeDocument.guides.add (Direction.VERTICAL, SF);

In either case the current ruler unit can be set to any but %.