How to Pass a Field Value to Create a Shape?
Hello I have a script that doesn't seem to be passing the field values I enter to create either a new Rectangle or Elliptical shape within the active document and layer. Where did I go wrong?
var doc = app.activeDocument
var myLayer = doc.activeLayer
// Create the window
var win = new Window("dialog", "Path Dimensions");
// Create a group to hold the width and height fields
var dimGroup = win.add("group");
// Add the width and height input fields
dimGroup.add("statictext", undefined, "Width (inches):");
var widthField = dimGroup.add("edittext", undefined, 5);
widthField.value = 5;
widthField.preferredSize.width = 50;
dimGroup.add("statictext", undefined, "Height (inches):");
var heightField = dimGroup.add("edittext", undefined, 5);
heightField.value = 5;
heightField.preferredSize.width = 50;
win.add("statictext", undefined, "Offset (inches):");
var offsetField = win.add("edittext", undefined, 0);
offsetField.value = 0;
offsetField.preferredSize.width = 50;
// Add the radio buttons
var radioGroup = win.add("group");
var rectButton = radioGroup.add("radiobutton", undefined, "Rectangle");
rectButton.value = true;
var ellipseButton = radioGroup.add("radiobutton", undefined, "Elliptical");
// Add the OK and cancel buttons
var btnGroup = win.add("group");
btnGroup.add("button", undefined, "OK", {name: "ok"});
btnGroup.add("button", undefined, "Cancel", {name: "cancel"});
// Show the window
win.show();
// Check if the OK button was clicked
if (win.ok) {
// Get the width, height, and offset values
var wdth = widthField.value*72;
var hdth = heightField.value*72;
var offset = offsetField.value*72;
alert("Width is set to" + wdth)
alert("Height is set to" + hdth)
alert("Offset is set to" + offset)
// Create the path
if (rectButton.value) {
var myRect = createRectangle(myLayer, 200, 200, wdth, hdth);
function createRectangle(layer, x, y ,h ,w){
return layer.pathItems.rectangle((x), (y), (wdth), (hdth))
}
} else {
var path = app.activeDocument.pathItems.ellipse(0, 0, wdth, hdth);
}
path.stroked = false;
path.fillColor = new CMYKColor();
path.fillColor.cyan = 100;
path.fillColor.magenta = 100;
path.fillColor.yellow = 100;
path.fillColor.black = 100;
if(offset != 0) {
path.createOutline(offset);
}
} else {
alert("No path created");
}
Thank you for your advice!
