Skip to main content
Participating Frequently
October 9, 2023
Question

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

  • October 9, 2023
  • 1 reply
  • 147 views

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();
This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
October 9, 2023

in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post if it helps you get responses.



<"moved from using the community">