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

create rectangle on all artboard

New Here ,
Aug 15, 2015 Aug 15, 2015

Hello, i've find this code by carlos is very usefull for resizing artboard, there is anyway to create rectangle on all artboard and positioning it ?

resizing artboard by carlos

#target Illustrator 

 

 

//  script.name = resizeArtboards_CS4andUp.jsx; 

//  script.description = resizes all artboards; 

//  script.requirement = one document with at least one artboard; 

//  script.parent = carlos canto // 11/4/12; 

//  script.elegant = false; 

 

if (app.documents.length > 0) { 

 

 

        //alert("more than 0"); 

                    var idoc = app.activeDocument; 

 

 

        var title = "Resize All Artboards"; 

 

   var mm = 2.834645; //(0 to 6) 

        var width = Number(Window.prompt ("Masukan lebar dalam mm", 510, title)); 

        var height = Number(Window.prompt ("Masukan tinggi dalam mm", 400, title)); 

 

 

    for (i=0; i<idoc.artboards.length; i++) { 

        var abBounds = idoc.artboards.artboardRect;// left, top, right, bottom 

 

 

        var ableft = abBounds[0]; // 0 

        var abtop = abBounds[1]; // 612 

        var abwidth = abBounds[2] - ableft; // 792 // width 

        var abheight = abtop- abBounds[3]; // 0 // height 

         

        var abctrx = abwidth/2+ableft; 

        var abctry = abtop-abheight/2; 

              

        var ableft = abctrx-width/2*mm;  

        var abtop = abctry+height/2*mm; 

        var abright = abctrx+width/2*mm;  

        var abbottom = abctry-height/2*mm; 

         

        idoc.artboards.artboardRect = [ableft, abtop, abright, abbottom]; 

    } 

else  { 

        alert ("there are no open documents"); 

}

example

Graphic1.jpg

create rectangle on artboard width and duplicate to bottom artboard

i've succesfull create vb script on coreldraw, but i'm new to this

TOPICS
Scripting
1.4K
Translate
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 , Aug 17, 2015 Aug 17, 2015

rectangle(Top,Left,Width,Height);

artboardRect(Left,Top,Right,Bottom)

so in this script:

pageDims[0] = artboardRect(Left)

pageDims[1] = artboardRect(Top)

pageDims[2] = artboardRect(Right)

pageDims[3] = artboardRect(Bottom)


makes things a bit hard to visualize.

hope this makes it clearer...

function window_for_getting_values(){

        var w = new Window('dialog',"resize All Artboards")

        w.statW = w.add('statictext',undefined,"Width: (in mm)");

        w.width = w.add('edittext',[0,0,100,20],"510"

...
Translate
Adobe
Community Expert ,
Aug 16, 2015 Aug 16, 2015

can you post the script you found? the screen shot is not very clear, I can hardly read the text

Translate
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 ,
Aug 16, 2015 Aug 16, 2015

I think this is what you after.

this just creates the boxes and not the text.

function make_header_and_footer(){

    var boxHeight = 25; //set this to whatever you like - value is in points.

    var blackColor = new GrayColor();

    blackColor.gray = 100;

    var doc = app.activeDocument;

    var pages = doc.artboards;

    for(i=0;i<pages.length;i++){

        var pageDims = pages.artboardRect;

        var head = doc.pathItems.rectangle(pageDims[1],pageDims[0],pageDims[2]-pageDims[0],boxHeight);

        head.stroked = false;

        head.filled = true;

        head.fillColor = blackColor;

        var foot = doc.pathItems.rectangle(pageDims[3]+boxHeight,pageDims[0],pageDims[2]-pageDims[0],boxHeight);

        foot.stroked = false;

        foot.filled = true;

        foot.fillColor = blackColor;

    }

}

make_header_and_footer();

Translate
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
New Here ,
Aug 17, 2015 Aug 17, 2015

@CarlosCanto i've done written in vbs corel draw

Thanks and great Qwertyfly... thats code working

btw i've combine carloscanto script and yours and it work on all artboard, but i've been stuck on change font style

var mm = 2.834645;

var idoc = app.activeDocument;

var pages = idoc.artboards;

if (app.documents.length > 0) {             

        var title = "Resize All Artboards"; 

 

        var width = Number(Window.prompt ("Masukan lebar dalam mm", 510, title));

        var height = Number(Window.prompt ("Masukan tinggi dalam mm", 400, title));

    for (i=0; i<idoc.artboards.length; i++) {

        var abBounds = idoc.artboards.artboardRect;// left, top, right, bottom

        var ableft = abBounds[0]; // 0

        var abtop = abBounds[1]; // 612

        var abwidth = abBounds[2] - ableft; // 792 // width

        var abheight = abtop- abBounds[3]; // 0 // height

        

        var abctrx = abwidth/2+ableft;

        var abctry = abtop-abheight/2;

             

        var ableft = abctrx-width/2*mm; 

        var abtop = abctry+height/2*mm;

        var abright = abctrx+width/2*mm; 

        var abbottom = abctry-height/2*mm;

        

        idoc.artboards.artboardRect = [ableft, abtop, abright, abbottom];

    }

}

else  {

        alert ("there are no open documents");

}

function make_header_footer_and_text(){

    

    var boxHeight = 15*mm; //set this to whatever you like - value is in points. i must convert to mm

    

    for(i=0;i<pages.length;i++){

        var pageDims = pages.artboardRect;

        var head = idoc.pathItems.rectangle(pageDims[1],pageDims[0],pageDims[2]-pageDims[0],boxHeight);

        head.stroked = false;

        head.filled = true;

        head.fillColor = idoc.swatches.getByName( '[Registration]' ).color;

        var foot = idoc.pathItems.rectangle(pageDims[3]+boxHeight,pageDims[0],pageDims[2]-pageDims[0],boxHeight);

        foot.stroked = false;

        foot.filled = true;

        foot.fillColor = idoc.swatches.getByName( '[Registration]' ).color;

        var warningText = idoc.textFrames.add();

   warningText.contents = "PERHATIAN !!! PERIKSA DAHULU SEBELUM NAIK CETAK, KESALAHAN & ISI MATERI SETELAH CETAK DILUAR TANGGUNG JAWAB KAMI !";

   warningText.top = pageDims[3]+boxHeight;

      warningText.left = pageDims[0]+(abBounds[2]/4); //cant center object

      warningText.selected = true;

      warningText.filled = true;

      warningText.fillColor = idoc.swatches.getByName( '[White]' ).color; //doesnt change color   

      redraw();

  }   

}

make_header_footer_and_text();

 

i'm little difficult to find reference how to center object to artboard and change font style and properties, in this case i want to change font to bold italic, and color to white

thanks

Translate
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 ,
Aug 17, 2015 Aug 17, 2015

just got some bad syntax.

but no need to loop twice.

and is a good idea to wrap all code in functions to keep the global space clean.

added a UI for entering values.

its fuggly but it works.

function window_for_getting_values(){

        var w = new Window('dialog',"resize All Artboards")

        w.statW = w.add('statictext',undefined,"Width: (in mm)");

        w.width = w.add('edittext',[0,0,100,20],"510");

        w.statH = w.add('statictext',undefined,"Height: (in mm)");

        w.height = w.add('edittext',[0,0,100,20],"400");

        w.stop = w.add('button',undefined,"Cancel");

        w.stop.onClick = function(){w.close();}

        w.go = w.add('button',undefined,"Start");

        w.go.onClick = function(){

                var height = parseFloat(w.height.text);

                var width = parseFloat(w.width.text);

                make_header_footer_and_text(width,height);

                w.close();

        }

        w.show();

}

function make_header_footer_and_text(width,height){

    if (app.documents.length < 1) {

        alert ("there are no open documents");

        return;

    }

    var mm = 2.834645;

    var idoc = app.activeDocument;

    var pages = idoc.artboards;

    var boxHeight = 15*mm; //set this to whatever you like - value is in points. i must convert to mm 

    var regColor = new CMYKColor();

    var whiteColor = new CMYKColor();

    whiteColor.cyan = 0; whiteColor.magenta = 0; whiteColor.yellow = 0; whiteColor.black = 0;  

    regColor.cyan = 100; regColor.magenta = 100; regColor.yellow = 100; regColor.black = 100;

    for(i=0;i<pages.length;i++){

        var pageDims = pages.artboardRect;

        idoc.artboards.artboardRect = [

            (pageDims[2]-pageDims[0])/2+pageDims[0]-width/2*mm,

            (pageDims[1]-(pageDims[1]-pageDims[3])/2)+height/2*mm,

            (pageDims[2]-pageDims[0])/2+pageDims[0]+width/2*mm,

            (pageDims[1]-(pageDims[1]-pageDims[3])/2)-height/2*mm

        ];

        pageDims = pages.artboardRect;

        var head = idoc.pathItems.rectangle(pageDims[1],pageDims[0],pageDims[2]-pageDims[0],boxHeight);

        head.stroked = false;

        head.filled = true;

        head.fillColor = regColor;

        var foot = idoc.pathItems.rectangle(pageDims[3]+boxHeight,pageDims[0],pageDims[2]-pageDims[0],boxHeight);

        foot.stroked = false;

        foot.filled = true;

        foot.fillColor = regColor;

        var warningText = idoc.textFrames.add();

        warningText.contents = "PERHATIAN !!! PERIKSA DAHULU SEBELUM NAIK CETAK, KESALAHAN & ISI MATERI SETELAH CETAK DILUAR TANGGUNG JAWAB KAMI !";

        warningText.top = pageDims[3]+boxHeight;

        warningText.selected = true;

        warningText.textRange.characterAttributes.fillColor = whiteColor;

        warningText.textRange.characterAttributes.textFont = app.textFonts.getByName("Tahoma");

        warningText.textRange.characterAttributes.size = 7;

        warningText.left = (pageDims[0]+(pageDims[2] - pageDims[0])/2) - (warningText.width/2);

        redraw();  

    }

}

window_for_getting_values();

Translate
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
New Here ,
Aug 17, 2015 Aug 17, 2015

wow that's great..  thanks @Qwertyfly


i need create a option for potrait or landscape, if artboard landscape then block set on top and bottom, else if artboard potrait then block set on left and right

but i'm little confused with reference point in pageDims



Translate
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 ,
Aug 17, 2015 Aug 17, 2015

rectangle(Top,Left,Width,Height);

artboardRect(Left,Top,Right,Bottom)

so in this script:

pageDims[0] = artboardRect(Left)

pageDims[1] = artboardRect(Top)

pageDims[2] = artboardRect(Right)

pageDims[3] = artboardRect(Bottom)


makes things a bit hard to visualize.

hope this makes it clearer...

function window_for_getting_values(){

        var w = new Window('dialog',"resize All Artboards")

        w.statW = w.add('statictext',undefined,"Width: (in mm)");

        w.width = w.add('edittext',[0,0,100,20],"510");

        w.statH = w.add('statictext',undefined,"Height: (in mm)");

        w.height = w.add('edittext',[0,0,100,20],"400");

        w.stop = w.add('button',undefined,"Cancel");

        w.stop.onClick = function(){w.close();}

        w.go = w.add('button',undefined,"Start");

        w.go.onClick = function(){

                var height = parseFloat(w.height.text);

                var width = parseFloat(w.width.text);

                make_header_footer_and_text(width,height);

                w.close();

        }

        w.show();

}

function make_header_footer_and_text(width,height){

    if (app.documents.length < 1) {

        alert ("there are no open documents");

        return;

    }

    var mm = 2.834645;

    var idoc = app.activeDocument;

    var pages = idoc.artboards;

    var boxHeight = 15*mm; //set this to whatever you like - value is in points. i must convert to mm 

    var regColor = new CMYKColor();

    var whiteColor = new CMYKColor();

    whiteColor.cyan = 0; whiteColor.magenta = 0; whiteColor.yellow = 0; whiteColor.black = 0;  

    regColor.cyan = 100; regColor.magenta = 100; regColor.yellow = 100; regColor.black = 100;

    for(i=0;i<pages.length;i++){

        var pageDims = pages.artboardRect;

        idoc.artboards.artboardRect = [

            (pageDims[2]-pageDims[0])/2+pageDims[0]-width/2*mm,

            (pageDims[1]-(pageDims[1]-pageDims[3])/2)+height/2*mm,

            (pageDims[2]-pageDims[0])/2+pageDims[0]+width/2*mm,

            (pageDims[1]-(pageDims[1]-pageDims[3])/2)-height/2*mm

        ];

        pageDims = pages.artboardRect;

        if(height<width){

            var textCol = whiteColor;

            var head = idoc.pathItems.rectangle(pageDims[1],pageDims[0],pageDims[2]-pageDims[0],boxHeight);

            head.stroked = false;

            head.filled = true;

            head.fillColor = regColor;

            var foot = idoc.pathItems.rectangle(pageDims[3]+boxHeight,pageDims[0],pageDims[2]-pageDims[0],boxHeight);

            foot.stroked = false;

            foot.filled = true;

            foot.fillColor = regColor;

        }else{

            var textCol = regColor;

            var left = idoc.pathItems.rectangle(pageDims[1],pageDims[0],boxHeight,pageDims[1]-pageDims[3]);

            left.stroked = false;

            left.filled = true;

            left.fillColor = regColor;

            var right = idoc.pathItems.rectangle(pageDims[1],pageDims[2]-boxHeight,boxHeight,pageDims[1]-pageDims[3]);

            right.stroked = false;

            right.filled = true;

            right.fillColor = regColor;

        }

        var warningText = idoc.textFrames.add();

        warningText.contents = "PERHATIAN !!! PERIKSA DAHULU SEBELUM NAIK CETAK, KESALAHAN & ISI MATERI SETELAH CETAK DILUAR TANGGUNG JAWAB KAMI !";

        warningText.top = pageDims[3]+boxHeight;

        warningText.selected = true;

        warningText.textRange.characterAttributes.fillColor = textCol;

        warningText.textRange.characterAttributes.textFont = app.textFonts.getByName("Tahoma");

        warningText.textRange.characterAttributes.size = 7;

        warningText.left = (pageDims[0]+(pageDims[2] - pageDims[0])/2) - (warningText.width/2);

        redraw();  

    }

}

window_for_getting_values();

Translate
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
New Here ,
Aug 17, 2015 Aug 17, 2015

Thank you very much, you are my savior

cool

Translate
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 ,
Aug 18, 2015 Aug 18, 2015

glad I could help

senang bisa membantu

Translate
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
New Here ,
Aug 18, 2015 Aug 18, 2015

you can speak indonesian? that's awesome...

where do you live qweryfly

Translate
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 ,
Aug 18, 2015 Aug 18, 2015

I cheated...

Google Translate...

Australia.

I was just interested to know what your warning text was saying.

Translate
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
New Here ,
Aug 18, 2015 Aug 18, 2015
LATEST

hahaha .... 

neighbouring countries

thanks again, pleased to meet you

Translate
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