Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

X,Y coordinates are printed wrong on the Second ArtBoard

$
0
0

Hi All,

 

I'm new to the illustrator scripting.

But out of my one month exposure to the scripting have explored plenty of things and started my project of writing script to print X,Y coordinates of different objects in an ai file.

 

My ai file would have different artboards and only for one artboard my script is properly printing the X,Y coordinates properly.

For all other artboards it is taking the coordinate system from the ai file and hence printing wrong.

 

Can somebody help me to sort this issue out.

Below is my script.

 

 

I couldn't attach the .ai file, with this, happy to share my sample file which I am trying to run the script.

Please correct me what is wrong in my script.

// Create an empty dialog window near the upper left of the screen

var dlg = new Window('dialog', 'Design Layout ');

dlg.frameLocation = [100,100];

dlg.size = [250,300];

 

dlg.intro = dlg.add('statictext', [20,20,150,50] );

dlg.intro.text = '"Select 1 (or) more items"';

 

var touchAreaCheckBox = dlg.add ("checkbox", [20,50,150,70], " Touch Areas");

dlg.GenerateButton = dlg.add('button', [20,170,150,200], 'Generate', 'CenterCoord');

 

// number of decimal places

var decimals = 0;

 

// document

var doc = activeDocument;

 

function generateDimensions()

{

       var totalLayers = doc.layers.length;                               

              createLayer('Touch Area Coordinates');

               for ( var i = 0 ; i < totalLayers ; i++)

                          {

                                            var currentLayer = doc.layers[i];  

                                            if (currentLayer.name == "Touch Areas")

                                            {

                                                 currentLayer.hasSelectedArtwork = true;

                                                 break;

                                            }

                                            else

                                            {

                                                 //TO DO

                                            }

                                       

                                //Unlock the layer if needed

                                currentLayer.locked = false;

                             }  

                  getLeftCoord();

}

 

function createLayer(layerName)

{

                                 try

                                {

                                     var speclayerCenter =doc.layers[layerName];

                                }

                                catch(err)

                               {

                                    var speclayerCenter = doc.layers.add();

                                    speclayerCenter.name = layerName;   

                               }

   

}

 

 

// measurement line color

var color = new RGBColor;

color.green = 255;

color.blue = 0;

 

/**

  Start the spec

*/

 

function getLeftCoord()

{

    $.writeln(" doc.selection.length:::::",doc.selection.length);

   for (var iSelectedItems=0; iSelectedItems<doc.selection.length; iSelectedItems++)

   {

      

        

                                 var topLeftPosDoc= doc.selection[iSelectedItems].position;                               

                                 // To get the center coordinates

                                 var topLeftPosArt = doc.convertCoordinate (topLeftPosDoc, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM);

                                 var cenPosArt = topLeftPosArt;

                                 cenPosArt[0] = topLeftPosArt[0] + doc.selection[iSelectedItems].width * 0.5;

                                 cenPosArt[1] = Math.abs(topLeftPosArt[1] - (doc.selection[iSelectedItems].height * 0.5));

                                 //specLabel(concatenate(cenPosArt[0],cenPosArt[1]),(topLeftPosDoc[0]+doc.selection[iSelec tedItems].width * 0.5),(topLeftPosDoc[1] - (doc.selection[iSelectedItems].height * 0.5)));

                                

                                // To get the bottom left coordinates

                                var bottomLeftPosArt= doc.convertCoordinate (topLeftPosDoc, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM);

                                bottomLeftPosArt[1] = Math.abs(bottomLeftPosArt[1] - (doc.selection[iSelectedItems].height ));

                                specLabelGreenForLeftCoord(concatenate(bottomLeftPosArt[0],bottomLeftPosArt[1]),topLeftPo sDoc[0]+10, (topLeftPosDoc[1]- doc.selection[iSelectedItems].height));

}

  dlg.close ();

}

 

function concatenate (value1,value2)

{

var  v1 = value1;

var v2 = value2;

v1 = v1.toFixed (decimals);

v2 = v2.toFixed (decimals);

var result = v1 +" ,"+ v2 ;

return result;

}

 

function specLabelGreenForLeftCoord( val, x, y)

{

     var t = doc.textFrames.add();

  t.textRange.characterAttributes.size = 12;

         var redColor = new RGBColor();

         redColor.red = 0;

         redColor.green = 255;

         redColor.blue = 0;

         t.textRange.characterAttributes.fillColor = redColor;

  t.textRange.characterAttributes.alignment = StyleRunAlignmentType.center;

  var v = val;

        t.contents = v;

  t.top = y;

  t.left = x ;

  return t;

 

}

 

dlg.GenerateButton.addEventListener ('click', generateDimensions);

dlg.show();


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>