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

Create a rectangle around object?

Community Beginner ,
Oct 03, 2012 Oct 03, 2012

Copy link to clipboard

Copied

Can this be done in illustrator scripting??

http://coreldraw.com/forums/t/35280.aspx

creating a rectangle around selected object or objects and set margins...

Regards

Martin

TOPICS
Scripting

Views

5.1K

Translate

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

Community Expert , Oct 04, 2012 Oct 04, 2012

Hallo martin_Cahill,

My English is not the best, because of that in German.

Grundsätzlich sind sich VBA und Javascript sehr ähnlich. Versuche die folgende Funktion mit den VBA-Äquivalenten zu vergleichen. Learning by doing

function makeRect() {

if (selection.length == 0) {

    alert("Kein Objekt …");

    return;

}else{

    if (selection.length > 1) {

        alert("Zu viele Objekte …");

        return;

    }else{

        var myDoc = app.activeDocument;

        var Sel = myDoc.selection

        var SelVB = Se

...

Votes

Translate

Translate
Adobe
Advocate ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

traceur --> plotter

Votes

Translate

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
New Here ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

I have just tried it and it's changing the layer name to "PerfCutContour" but I need the spot colour name to be added as "PerfCutContour" not the layer. 

 

See attached as this is the swatch I need to be added as the box's stroke colour, is this possible?

 

Thanks!

Votes

Translate

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
Advocate ,
Aug 05, 2022 Aug 05, 2022

Copy link to clipboard

Copied

Bonjour robo78

Ce n'est pas le calque qui est renommé mais le tracé MargBox.name = "PerfCutContour";

Si vous voulez créer un nouveau spotColor...

// JavaScript Document for Illustrator
// INIT --------------------
  var spotName = "PerfCutContour"; // CutContour
  var PerfColor = macmykColor(0,0,0,50);
// -------------------------
      setSpotColor(PerfColor,spotName);
// -------
function macmykColor(c,m,j,k)
 { //cree une nouvelle couleur CMJN
  var cmykColor = new CMYKColor();
  cmykColor.cyan = c;
  cmykColor.magenta = m;
  cmykColor.yellow = j;
  cmykColor.black = k;
  return cmykColor;
 }
 // -------
  function setSpotColor(newColor,name) {
  // Create the new spot
  var newSpot = app.activeDocument.spots.add();
      newSpot.colorType = ColorModel.SPOT;
      newSpot.name = name;
      newSpot.color = newColor;
      return newSpot;
}
// -------

René

Votes

Translate

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
Community Beginner ,
Oct 26, 2022 Oct 26, 2022

Copy link to clipboard

Copied

Is there any chance to get this working with multiple objects? In short words I'd just like to make a rectangle that replicates the bounding box with a certain offset. Script works with some tweaks fine if it's for example just one circle shape, but I'd like to make one rectangle around two circles. Would be really nice if you or someone else could help me out on where to tweak that script or to tell me if it's even possible to do.

Votes

Translate

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 26, 2022 Oct 26, 2022

Copy link to clipboard

Copied

Feel free to start a new thread, provide specific details, preferably with images, and I'm sure people will be happy to help. 

Votes

Translate

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
Advocate ,
Oct 28, 2022 Oct 28, 2022

Copy link to clipboard

Copied

LATEST

Bonjour,

Je vous donne un de mes premiers scripts (du temps de la version CS2) qui pourra certainement vous satisfaire.

/*bd_bordure_selection.js
Autor Landry René
Trace le contour de la sélection (voir variable typeObjet)
sous forme d'un rectangle qui aura pour dimensions les limites de la sélection,
les couleurs fond et contour sont fixées aux lignes 20 et 21
avec choix de l'un des 3 modes pour ces limites :
V pour visibleBounds incluant le contour visible (plus performent que C))
C pour controlBounds epaisseur du contour.incluse.
G pour GeometriquBounds hors épaisseur du contour
Le rectangle sera placé en arrière-plan
Possibilité de saisir un autre décalage supérieur à 0 pour obtenir un cadre,
la valeur par défaut est 0, l'unité est l'unité choisie pour "Générales" (Préférences),
pour forcer l'unité en point, écrire pt après la valeur numérique.
(les objets ne son pas détruits).
le rectangle est placé sous la sélection et est sélectionné
*/
//Initialisation------------------------------
var factOpacite = 50;
var dec = 0;
var epContour = 1;
var mode = "v";
var nomObjet = "entourRect";
var contourColor = macmykColor(0,62.18,94.12,0);
var fondColor = macmykColor(88,77,0,0)
// La chaine typeObjet permet de faire une restriction en supprimant des types d'objets
var typeObjet = "PathItem SymbolItem TextFrame GroupItem PageItem";
    typeObjet+=" CompoundPathItem GraphItem MeshItem PlacedItem RasterItem PluginItem";
//---------------------------------------------
if ( app.documents.length > 0 ) {
  var docRef = app.activeDocument;
  var selectedItems = selection;
  var endIndex = selectedItems.length;
  if ( endIndex > 0) {
  var monUnite, unite;
  var p; //compteur
  var PlaceLayer, rang = 0;
      app.defaultStroked = true;
      app.defaultFilled = true;
  var p1x = new Array(), p1y = new Array(), p2x = new Array(), p2y = new Array();
  var p1xx, p2xx, p1yy, p2yy;
  var larg, haut;
      uniteMesure();
  var reg = new RegExp("^[vcg]{1}$", "gi");
   do {
   mode = prompt("Mode ( v c g ) ?\r Visible Control Geometric  ",mode,"De Ellere");
   }
   while (!saisie(mode,2) || !mode == null);
     if( mode != null && mode != "") { // echap1
      mode = mode.toLowerCase();
       do
       {
       dec = prompt("Décalage ? en "+monUnite,dec,"De Ellere");
        if (dec != null) {
        dec = dec.toLowerCase();
          if (dec.indexOf("pt",0) != -1) {
          unite = 1;
          dec = dec.substring(0,dec.indexOf("pt"));
          }
        }
       }
       while (!dec == null || !saisie(dec,1));
        if (dec != null && dec != "") { //echap2
        dec = parseFloat(dec)*unite;
           for (p = 0; p< endIndex; p++) // restriction éventuelle de type d'objet
           if (typeObjet.indexOf(selectedItems[p].typename) == -1) selectedItems[p].selected = false;
        selectedItems = selection;
        endIndex = selectedItems.length;
         for (p = 0; p < endIndex; p++) {
           var objetSelect = selectedItems[p];
           PlaceLayer = objetSelect.parent;
           while (PlaceLayer.name != docRef.layers[rang].name) rang++;
               switch (mode) {
               case "v": var rect = objetSelect.visibleBounds; break;
               case "c": var rect = objetSelect.controlBounds; break;
               case "g": var rect = objetSelect.geometricBounds;
               }
           p1x[p]= rect[0]; p1y[p] = rect[1]; p2x[p] = rect[2]; p2y[p] = rect[3];
           p1xx = mini(p1x); p2xx = maxi(p2x);
           p1yy = maxi(p1y); p2yy = mini(p2y);
         }
         docRef.selection = false;
         larg = (p2xx-p1xx)+dec*2;
         haut=(p1yy-p2yy)+dec*2;
         var objetRect = docRef.layers[rang].pathItems.rectangle(p1yy+dec,p1xx-dec,larg,haut);
             objetRect.selected = true;
             objetRect.name = nom(nomObjet);
             objetRect.opacity = factOpacite;
             objetRect.strokeColor = contourColor;
             objetRect.fillColor = fondColor;
             arrierePlan(objetRect);
         } // echap2
      } // echap
  }
  else alert("Au revoir, une sélection est obligatoire","De Elleere");
}
else alert("Pour l'exécution de ce sript un document doit être ouvert !","Script Alerte de Elleere !");
//------------------------------
function arrierePlan(objet)
{ // Place objet en arrière plan
     objet.zOrder(ZOrderMethod.SENDTOBACK);
}
function macmykColor(c,m,j,k)
{ //cree une nouvelle couleur CMJN
         var cmykColor = new CMYKColor();
         cmykColor.cyan = c;
         cmykColor.magenta = m;
         cmykColor.yellow = j;
         cmykColor.black = k;
         return cmykColor;
}
function maxi(tab)
{ // Donne la valeur maximale d'un tableau
for (var i = 0, max = -Infinity; i < tab.length; i++) max = Math.max(tab[i],max);
return max;
}
function mini(tab)
{ // Donne la valeur minimale d'un tableau
for (var i = 0, min = Infinity; i < tab.length; i++) min = Math.min(tab[i],min);
return min;
}
function nom(nomPageItem)
{ // Empeche les noms identiques, retourne le nom suivi d'un indice
         var nom, indice = 1;
         for (var k = docRef.pageItems.length-1; k >= 0; k--)
           {
           nom = docRef.pageItems[k].name;
           if (nom.indexOf(nomPageItem,0)!= -1) indice++;
           }
           return nomPageItem+" "+indice;
}
function saisie(chaine,test)
{
  if (chaine == null || chaine == "") return true;
      switch (test) {
      case (1): if (!isNaN(chaine)) if (chaine >= 0) return true; break;
      case (2): if (reg.test(chaine)) return true;
  }
   return false;
}
function uniteMesure()
{
 var uniteMesure = new Array();
 uniteMesure[0] = new Array("Centimeters","Inches","Millimeters","Picas","Points","Qs","Pixels");
 uniteMesure[1] = new Array("cm","in","mm","Pc","Pt","Q","px");
 uniteMesure[2] = new Array("28.34645","72","2.834645","12","1","0,709","1");
 var regleUniteDoc = "*"+docRef.rulerUnits; //  * ex de résultat rulerUnits.Inches
 monUnite = regleUniteDoc.substring(regleUniteDoc.lastIndexOf(".")+1);
  for (var i = 0; i < uniteMesure[0].length; i++ )
   if (uniteMesure[0][i] == monUnite){
    monUnite = uniteMesure[1][i];
    unite = parseFloat(uniteMesure[2][i]);
    continue;
   }
}

René

Votes

Translate

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