Overblog
Editer la page Suivre ce blog Administration + Créer mon blog
/ / /

 

A la base ce script visualise les points des tracés (pathItems) du document courant.

 

La sélection courante, pour être visualisée, est d'abord transformée en tracé (path) par la fonction SelToPath(1.0), donc avec une tolérance de 1 pixel. Elle sera affichée avec les tracés déjà définis.

 

Pour visualiser les tracés existants, sans la sélection courante, il suffit de mettre cette ligne

// SelToPath(1.0) ;

en commentaire dans le Main.

 

Ce script peut aussi servir d'exemple à une programmation concernant les tracés.

 

/************************************************************************
     Selection/Path Viewer
 ************************************************************************
 25/03/2012 Habaki V1r01b: Display path operation

 20/06/2010 Habaki V1r01 : Creation
 ************************************************************************/
var ScriptName= "Selection/Path Viewer, V1R01b Habaki";

/*----------------------------------------------------------------------*
   Convert selection into Path
 *----------------------------------------------------------------------*/
function SelToPath(
        tolerance  // Tolerance in pixels
        ) {
  var idMk = charIDToTypeID( "Mk  " );
  var AD = new ActionDescriptor();
  var idnull = charIDToTypeID( "null" );
  var AR1 = new ActionReference();
  var idPath = charIDToTypeID( "Path" );
  AR1.putClass( idPath );
  AD.putReference( idnull, AR1 );
  var idFrom = charIDToTypeID( "From" );
  var AR2 = new ActionReference();
  var idcsel = charIDToTypeID( "csel" );
  var idfsel = charIDToTypeID( "fsel" );
  AR2.putProperty( idcsel, idfsel );
  AD.putReference( idFrom, AR2 );
  var idTlrn = charIDToTypeID( "Tlrn" );
  var idPxl = charIDToTypeID( "#Pxl" );
  AD.putUnitDouble( idTlrn, idPxl, tolerance );
  executeAction( idMk, AD, DialogModes.NO );
}
/*----------------------------------------------------------------------*
   Main
 *----------------------------------------------------------------------*/
try {
  var Paths, Path;
  var SubPaths, Item;
  var Points, Point;
  var st;
 
  SelToPath(1.0);   // Remove this line to only view paths


  Paths = app.activeDocument.pathItems;
  for (var i=0; i < Paths.length; i++) {
    Path = Paths[i];
    st = Path.name + "\nkind=" + Path.kind;
    SubPaths = Path.subPathItems;
    for (var j=0; j < SubPaths.length; j++) {
      Item = SubPaths[j];
      st += "\nSubPath " + j + " (" + Item.operation + ") ->";
      Points = Item.pathPoints;
     
      for (var k=0;k < Points.length;k++) {
        Point = Points[k];
        st +=   "\n   Point " + k + ":"
              + " kind=" + Point.kind
              + " x=" + Point.anchor[0] + ", y=" + Point.anchor[1]
              ;
      } // for
     
    } // for
    alert(st, ScriptName);
  } // for
 
} catch (e) {
  alert(e.message, ScriptName);
}

Partager cette page
Repost0
Published by Habaki - dans Scripts

Catégories