Predefined rectangular ROI

Hi everyone,

We need to use a predefined rectangular shaped ROI in a macro to select multiple areas in one image. We found a script for a circular area and tried to modify for rectangular shape. But we failed… Can anyone help us out! We tried to use the specify option in our script, however we could not duplicate the regions. Here is start of our script, does anyone has any suggestions on fixing our problem?

Thanks in advance!

macro RectangleOn_MouseClick{
        setOption("DisablePopupMenu", true);
        getPixelSize(unit, pixelWidth, pixelHeight);
        rectangle = 200;
                Dialog.addNumber("Set size of rectangle",rectangle);;
        pixelHeight = Dialog.getNumber();
        height = pixelHeight;
        width = pixelHeight;
        x2=-1; y2=-1; z2=-1; flags2=-1;
        getCursorLoc(x, y, z, flags);
        while (flags&rightButton==0){
                getCursorLoc(x, y, z, flags);
                if (flags&leftButton!=0) {
                   if (x!=x2 || y!=y2 || z!=z2 || flags =flags2) 
                              makeRectangle(x, y, width, height);
                              x2=x; y2=y; z2=z; flags2=flags;