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

Changing the height of the rectangle from 0 up does not work

Explorer ,
Oct 09, 2023 Oct 09, 2023

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();
TOPICS
How-to , Scripting

Views

342
Translate

Report

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

correct answers 1 Correct answer

Guide , Oct 11, 2023 Oct 11, 2023

Your thinking is right. 

Votes

Translate
Adobe
Guide ,
Oct 09, 2023 Oct 09, 2023

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)");
}

Votes

Translate

Report

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
Explorer ,
Oct 10, 2023 Oct 10, 2023

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?

Votes

Translate

Report

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
Explorer ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Zrzut ekranu 2023-10-11 o 08.25.06.pngexpand image

 

Votes

Translate

Report

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
Guide ,
Oct 11, 2023 Oct 11, 2023

Copy link to clipboard

Copied

LATEST

Your thinking is right. 

Votes

Translate

Report

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