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

Script for Document Setup size...

New Here ,
May 07, 2010 May 07, 2010

Hello All,

     I have a request for a script, not sure how one would go about it but here we go.

An AI CS4 user selects a shape, they then execute a script that...

Resizes the Document Setup Art Board to one inch larger (length width) than the selected shape.

Then a rectangle is drawn in the document and is sized the same as the art board.

Any help would be great!!!

Thanks in advanced.

Anton

TOPICS
Scripting
4.7K
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 , Jun 21, 2010 Jun 21, 2010

#target illustrator function main() {      if (app.documents.length == 0) {           alert('Open a document before running this script');           return; // Stop script here no doc open…      } else {           var docRef = app.activeDocument;           with (docRef) {                if (selection.length == 0) {                     alert('No items are selected…');                     return; // Stop script here with no selection…                }                if (selection.length > 1) {  

...
Translate
Adobe
Guide ,
May 08, 2010 May 08, 2010

This should be there or there abouts… I can't test the artboards line as I don't have CS4. The rectangle & artboard should be 1 inch larger on both height & width (half inch all around) single selected shape…

#target illustrator function main() {      if (app.documents.length == 0) {           alert('Open a document before running this script');                return; // Stop script here no doc open…      } else {           var docRef = app.activeDocument;           with (docRef) {                if (selection.length == 0) {                     alert('No items are selected…');                     return; // Stop script here with no selection…                }                if (selection.length > 1) {                     alert('Too many items are selected…');                     return; // Stop script here with selection Array…                } else {                     var selVB = selection[0].visibleBounds;                     var rectTop = selVB[1] + 36;                     var rectLeft = selVB[0] - 36;                     var rectWidth = (selVB[2] - selVB[0]) + 72;                     var rectHeight = (selVB[1] - selVB[3]) + 72;                     var padBox = pathItems.rectangle(rectTop, rectLeft, rectWidth, rectHeight, false);                     padBox.stroked = false;                     artboards[0].artboardRect = (padBox.visibleBounds);                     redraw();                }                     }      } } main();

Illustrator scripting uses 'Points' for measurements so you should easily be able to adjust where I have used values like + 36 etc…

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 ,
Jun 18, 2010 Jun 18, 2010

I am now using AI CS5 and this worked like a charm! Thanks! Sorry for the long delay in the reply. One more thing, how would you copy the size of the original object to the clip board so I could paste it into a text document after executing the script? The format would be (Width X Height).

Thanks again!

Anton

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 ,
Jun 19, 2010 Jun 19, 2010

The clipboard contents is/was out side of the scope of JavaScript. It is settable with either AppleScript, Shell or VB dependent on your OS. It may be that you can create a temporary text frame of your info select a range of characters and use copy(); command but I have not tried this yet… This command is in CS5 but was not in CS2…

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 ,
Jun 19, 2010 Jun 19, 2010

The text selection thing did not work… you could display the string in a prompt where you could use comm+c to get it to the paste board?

var textString = rectWidth + ' x ' + rectHeight; prompt('Copy Me', textString);

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 ,
Jun 21, 2010 Jun 21, 2010

Muppet Mark,

That would do the trick, the size is displayed in points. How would I make the size display in inches in the prompt box?

Thanks again,

Anton

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 ,
Jun 21, 2010 Jun 21, 2010

That would just be…

var textString = rectWidth/72 + ' x ' + rectHeight/72;

Unless you require any sort of rounding?

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 ,
Jun 21, 2010 Jun 21, 2010

Rounding to the tenth would be perfect. ex 10.4 X 6.2

Anton

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
Engaged ,
Jun 21, 2010 Jun 21, 2010

Hi,

it should be

var textString = Math.abs(rectWidth/7.2)/10 + ' x ' + Math.abs(rectHeight/7.2)/10;

See 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
New Here ,
Jun 21, 2010 Jun 21, 2010

That does it but it gives me the size of the art board and not the original object. Just need to subtract 1" from each value.

Thanks

Anton

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
Engaged ,
Jun 21, 2010 Jun 21, 2010

AntonJustad a écrit:

That does it but it gives me the size of the art board and not the original object. Just need to subtract 1" from each value.

Thanks

Anton

Ho.. so..

var textString = Math.abs((rectWidth-72)/7.2)/10 + ' x ' + Math.abs((rectHeight-72)/7.2)/10;
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 ,
Jun 21, 2010 Jun 21, 2010

Thanks!

This gives me the correct size but now it does not round to the tenth?

Anton

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 ,
Jun 21, 2010 Jun 21, 2010

#target illustrator function main() {      if (app.documents.length == 0) {           alert('Open a document before running this script');           return; // Stop script here no doc open…      } else {           var docRef = app.activeDocument;           with (docRef) {                if (selection.length == 0) {                     alert('No items are selected…');                     return; // Stop script here with no selection…                }                if (selection.length > 1) {                     alert('Too many items are selected…');                     return; // Stop script here with selection Array…                } else {                     var selVB = selection[0].visibleBounds;                     var rectTop = selVB[1] + 36;                     var rectLeft = selVB[0] - 36;                     var rectWidth = (selVB[2] - selVB[0]) + 72;                     var rectHeight = (selVB[1] - selVB[3]) + 72;                     var padBox = pathItems.rectangle(rectTop, rectLeft, rectWidth, rectHeight, false);                     padBox.stroked = false;                     artboards[0].artboardRect = (padBox.visibleBounds);                     redraw();                     rectWidth = (rectWidth-72)/72;                     rectWidth = roundToDP(rectWidth,1);                     rectHeight = (rectHeight-72)/72;                     rectHeight = roundToDP(rectHeight,1);                     var textString = rectWidth + ' x ' + rectHeight;                     prompt('Copy Me', textString);                }                    }      } } main(); function roundToDP(nbr, dP) {      dpNbr = Math.round(nbr*Math.pow(10,dP))/Math.pow(10,dP);      return dpNbr; }

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 ,
Jun 21, 2010 Jun 21, 2010

Muppet Mark,

Well done!!!

Thanks for all of the help.

Anton

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 ,
Jun 25, 2010 Jun 25, 2010

Muppet Mark,

I was wondering how hard it would be to expand on this script? I want to take the selection remove the fill put a stroke on it, the stroke would be a 100% magenta spot color with the name of CC.  This item would be placed on a new layer by itself named CC.

On the new box shape that is the same size as the art board I would like to... Make the fill 100% magenta 90% yellow and this would also be a spot color that is named TC. This item would be placed on a new layer by itself named TC

Thanks for any help.

Anton

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 ,
Jun 25, 2010 Jun 25, 2010

Sounds pretty straight forward should only be half/dozen new lines… Just about to clock off here@work but may get chance when home L8R…

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 ,
Jun 25, 2010 Jun 25, 2010

I think that this should be close? I moved the fill to the back so the stroked object could be seen. Don't know if that was wanted?

#target illustrator function main() {      if (app.documents.length == 0) {           alert('Open a document before running this script');           return; // Stop script here no doc open…      } else {           var docRef = app.activeDocument;           with (docRef) {                if (selection.length == 0) {                     alert('No items are selected…');                     return; // Stop script here with no selection…                }                if (selection.length > 1) {                     alert('Too many items are selected…');                     return; // Stop script here with selection Array…                } else {                                         var selVB = selection[0].visibleBounds;                     var rectTop = selVB[1] + 36;                     var rectLeft = selVB[0] - 36;                     var rectWidth = (selVB[2] - selVB[0]) + 72;                     var rectHeight = (selVB[1] - selVB[3]) + 72;                                    selection[0].parent.name = 'CC';                     selection[0].filled = false;                     selection[0].stroked = true;                     var ccColor = cmykColor(0, 100, 0, 0);                                    var ccCol = spots.add()                     ccCol.name = 'CC';                     ccCol.color = ccColor;                     ccCol.tint = 100;                     ccCol.colorType = ColorModel.SPOT;                     var cc = new SpotColor();                     cc.spot = ccCol;                                         selection[0].strokeColor = cc;                     selection[0].strokeWidth = 1;                                         var tcLayer = layers.add();                     tcLayer.name = 'TC';                     var padBox = pathItems.rectangle(rectTop, rectLeft, rectWidth, rectHeight, false);                     padBox.stroked = false;                     padBox.filled = true;                     var tcColor = cmykColor(0, 100, 90, 0);                               var tcCol = spots.add()                     tcCol.name = 'TC';                     tcCol.color = tcColor;                     tcCol.tint = 100;                     tcCol.colorType = ColorModel.SPOT;                     var tc = new SpotColor();                     tc.spot = tcCol;                     padBox.fillColor = tc;                          padBox.move(docRef, ElementPlacement.PLACEATEND);                     artboards[0].artboardRect = (padBox.visibleBounds);                     redraw();                     rectWidth = (rectWidth-72)/72;                     rectWidth = roundToDP(rectWidth,1);                     rectHeight = (rectHeight-72)/72;                     rectHeight = roundToDP(rectHeight,1);                     var textString = rectWidth + ' x ' + rectHeight;                     prompt('Copy Me', textString);                }                    }      } } main(); function roundToDP(nbr, dP) {      dpNbr = Math.round(nbr*Math.pow(10,dP))/Math.pow(10,dP);      return dpNbr; } function cmykColor(c, m, y, k) {      var newCMYK = new CMYKColor();      newCMYK.cyan = c;      newCMYK.magenta = m;      newCMYK.yellow = y;      newCMYK.black = k;      return newCMYK; }

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 ,
Jun 28, 2010 Jun 28, 2010

This did the trick! Thanks again!

Anton

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 ,
Apr 18, 2011 Apr 18, 2011

All,

     I am tweaking this script again and have run into a road block that you may have a simple answer for.  When I execute this script when selecting a single object it works perfect, if I execute it while selecting a group of objects the script will not apply the spot color to the selection.  The script will however do everything but apply the spot color.  Here is the latest edit. Thanks for any input.

Anton

#target illustrator function main() {      if (app.documents.length == 0) {           alert('Open a document before running this script');           return; // Stop script here no doc open…      } else {           var docRef = app.activeDocument;           with (docRef) {                if (selection.length == 0) {                     alert('No items are selected…');                     return; // Stop script here with no selection…                }                if (selection.length > 1) {                     alert('Too many items are selected…');                     return; // Stop script here with selection Array…                } else {                     var ccSpotColor = cmykColor(0, 100, 0, 0);                     var ccCol = spots.add()                     ccCol.name = 'CC';                     ccCol.color = ccSpotColor;                     ccCol.tint = 100;                     ccCol.colorType = ColorModel.SPOT;                     var cc = new SpotColor();                     cc.spot = ccCol;                     var selVB = selection[0].visibleBounds;                     var rectTop = selVB[1] + 36;                     var rectLeft = selVB[0] - 36;                     var rectWidth = (selVB[2] - selVB[0]) + 72;                     var rectHeight = (selVB[1] - selVB[3]) + 72;                     selection[0].parent.name = 'ARTWORK';                     selection[0].filled = false;                     selection[0].stroked = true;                     selection[0].strokeColor = cc;                     selection[0].strokeWidth = 1;                     var regLayer = layers.add(); // Creates Regmark Layer                     regLayer.name = 'Regmark';                     var tcLayer = layers.add(); // Creates TC Layer                     tcLayer.name = 'Through Cut';                     var ccLayer = layers.add(); // Creates CC Layer                     ccLayer.name = 'CC';                          var Cutline = selection[0]                          Cutline.move(ccLayer, ElementPlacement.INSIDE);                                             var ThroughCutBox = tcLayer.pathItems.rectangle(rectTop, rectLeft, rectWidth, rectHeight, false); //This is TC box                     ThroughCutBox.stroked = false;                     ThroughCutBox.filled = true;                     var tcSpotColor = cmykColor(0, 100, 90, 0);                     var tcCol = spots.add()                     tcCol.name = 'TC';                     tcCol.color = tcSpotColor;                     tcCol.tint = 100;                     tcCol.colorType = ColorModel.SPOT;                     var tc = new SpotColor();                     tc.spot = tcCol;                     ThroughCutBox.fillColor = tc;                          tcLayer.visible = false;// Make TC Layer Invisable     Here                     artboards[0].artboardRect = (ThroughCutBox.visibleBounds);                     redraw();                     rectWidth = (rectWidth-72)/72;                     rectWidth = roundToDP(rectWidth,1);                     rectHeight = (rectHeight-72)/72;                     rectHeight = roundToDP(rectHeight,1);                     var textString = rectWidth + ' x ' + rectHeight;                     prompt('Copy Me', textString);                }           }      } } main(); function roundToDP(nbr, dP) {      dpNbr = Math.round(nbr*Math.pow(10,dP))/Math.pow(10,dP);      return dpNbr; } function cmykColor(c, m, y, k) {      var newCMYK = new CMYKColor();      newCMYK.cyan = c;      newCMYK.magenta = m;      newCMYK.yellow = y;      newCMYK.black = k;      return newCMYK; }

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 ,
Apr 18, 2011 Apr 18, 2011

Anton, the script has 2 if statements firstly selection.length = 0… Stop nothing is selected. Then if selection.length > 1… Stop there is no loop to deal with multi items built into it… Its doing exactly what its supposed to… Are you selecting a single illustrator 'group' or are you selecting a bunch of loose items? either way you would need to iterate each item…

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 ,
Apr 18, 2011 Apr 18, 2011

I am selecting 2 or more objects that have been grouped together. So what you are saying is (If selection.length = group then...) handle that type of selection differently?

Anton

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 ,
Apr 18, 2011 Apr 18, 2011

No its not quite like that… an array's (more than one item or list of items if you prefer) length is the count of how many items are in it… When >1 is the case you need to deal with each item in turn. If your group had say 3 path items you would need to change the fill for each path separately within the group… To do this you need a loop statement…

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
Advisor ,
May 10, 2011 May 10, 2011

doing some testing with this script to learn more about a script I need to write. How do I save this text? In Text Edit what format should I save out as and do I put a .js or .jsx on the end of the file name? When running this script I see it targets Illustrator so do I run it through the automator or as a script from the Illustrator Files>Scripts menu?

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
Community Expert ,
May 10, 2011 May 10, 2011

Save out of Text Edit as Plain text with a .jsx extension. You will run it from the Illustrator>File>Script menu after placing the file in HD/Applications>AICS*>Presets>Scripts folder.

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
Advisor ,
May 10, 2011 May 10, 2011
LATEST

Thank you Larry, I got it to run. Now I will tweek it to see if I can make it useful for my workflow. If I have any more questions I will post in new thread as not th hijack this one.

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