Copy link to clipboard
Copied
Hello,
I encountered a problem and out of curiosity I would like to solve it.
I wrote a simple script to present the problem. After creating the rectangle, you can increment the value, but when you reduce it to 0, you lose the ability to increment it again. Realistically, in Illustrator, after creation, the rectangle can have a value of 0.
I don't need this in my project, but thanks to you and solving these types of problems, it becomes better.
var mm = new UnitValue(1 + " " + "mm").as('pt');
var doc = app.activeDocument;
var cyanColor = new CMYKColor();
cyanColor.black = 0;
cyanColor.cyan = 100;
cyanColor.magenta = 0;
cyanColor.yellow = 0;
var myH = 3;
var rect = doc.pathItems.rectangle(0, 0, 60*mm, myH*mm);
rect.stroked = false;
rect.filled = true;
rect.fillColor = cyanColor;
doc.views[0].centerPoint = [0,0];
doc.views[0].zoom = 3.0;
redraw();
var dialog = new Window('dialog {orientation:"row"}');
var txt = dialog.add("statictext", undefined, undefined, {name: "txt"});
txt.text = myH;
var button1 = dialog.add('button', undefined, '-', {name:'button1'});
button1.onClick = function() {
// if(myH > 1) { // works
if(myH > 0) { // when we go to 0, line 39 will no longer execute, but 38 will
myH--;
txt.text = myH;
doc.pathItems[0].height = myH * mm;
redraw();
};
};
var button2 = dialog.add('button', undefined, '+', {name:'button2'});
button2.onClick = function() {
myH++;
txt.text = myH;
doc.pathItems[0].height = myH * mm; // doesn't work
redraw();
};
dialog.show();
1 Correct answer
Your thinking is right.
Explore related tutorials & articles
Copy link to clipboard
Copied
I presume it's a bug. It appears that re-assigning a pathItem's height throws an "unknown scripting error" once it's a 0. This can replicated by the following:
var rect = app.activeDocument.pathItems.rectangle(0, 0, 60, 60);
app.redraw();
alert("rect.height = " + rect.height);
rect.height = 0
app.redraw();
alert("rect.height = " + rect.height);
try {
rect.height = 60;
} catch (e) {
alert(e + "\nrect.height = " + rect.height + " (should be 60)");
}
Copy link to clipboard
Copied
When we create a rectangle in Illustrator with a height of 0, the program will still create it with a height of 0.001 and even when we change this value to 0, the program will manage to further change the height of this rectangle even through the script. Maybe after all, this value of 0.001 still applies, even though the displayed value is 0.
The script that will create a rectangle with the value 0 actually has this much value and the program can't handle it.
Am I thinking right?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Your thinking is right.

