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

PageItems position false I think

$
0
0

Hi,

I created a javascript file, this file read in an EPS file after it resize and add a new position all items. From 10 EPS file 7 ok, but 3 false.

This EPS, I do not get correct position: http://mezofi.hu/proba_017.eps

Forexample:

An pageItem alert() infó

layerRef.pageItems[17].position[0] = 431.453

layerRef.pageItems[17].position[1] = -110.510

When I see in Illustrator INFO window

x = 5.679 in

y = -4.015 in

I don't know why wrong position x and y . 431.453 != 5.679 and why pixel then inch  .

 

 

My js code:

[code]

// JavaScript Document

//Set up vairaibles

var destFolder, destDoc, sourceDoc, sourceFolder, newLayer, newName, out, kicsinyites;

var out = false; // Kell-e menteni a képet

var kicsinyites = true; // Kell-e a kicsinyíteni

var teszt = true; // Teszteléshez kiíratunk minden félét

 

 

// Select the source folder.

sourceFolder = Folder.selectDialog('Hol vannak a Illustrator fájlok amiket át kell méretezni?', '~');

 

if(out){

// Get the destination to save the files

destFolder = Folder.selectDialog('Válassz egy könyvtárat a mentett PNG fájlok részére.', '~' );

}

 

 

// If a valid folder is selected

if (sourceFolder != null) {

    files = new Array();

 

    // Get all files matching the pattern

    files = sourceFolder.getFiles();

 

    if (files.length > 0) {

       for (k = 0; k < files.length; k++) {

            sourceDoc = app.open(files[k]); // returns the document object

            //alert(sourceDoc.name);

           

            //Mi a kép eredeti neve - File name

            fileUrl = files[k];

            fileUrl = fileUrl.toString();

            fileUrlTomb = fileUrl.split("/");

            tagDb = fileUrlTomb.length;

            fileName = fileUrlTomb[(tagDb-1)];

            fileNameArray = fileName.split(".");

            newName = fileNameArray[0];

           

        // Select All layers in Active Document

        var myLayers = sourceDoc.layers;

         //Go through all layers of source document and copy artwork

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

         myLayers[i].hasSelectedArtwork = true;

         };

            

           

        // középre igazítja a grafikát, körben 1 pixel margót hagy -position center + 1px space

        AdjustArtboardSize(0, true);

       

        function AdjustArtboardSize(abMargin, useLongSideMargin) {

          var aDoc = activeDocument;

         // var cb =  new Array(aDoc.cropBox);

         // alert(aDoc.cropBox);

          var vb = new Array(aDoc.visibleBounds);

          vb = aDoc.visibleBounds;

          var width = (vb[2] - vb[0]);  // left-right

          var height = -(vb[3] - vb[1]);  // bottom-top

          if (useLongSideMargin == true)

            {

              var margin = Math.max(width, height) * (abMargin / 100) +1;

              vb[0] -= margin;    // left

              vb[1] += margin;   // top

              vb[2] += margin;   // right

              vb[3] -= margin;   // bottom

            }

          else

            {

              vb[0] -= (width * (1 + abMargin / 100) - width);  // left

              vb[1] += (height * (1 + abMargin / 100) - height); // top

              vb[2] += (width * (1 + abMargin / 100) - width);  // right

              vb[3] -= (height * (1 + abMargin / 100) - height); // bottom

            }

           

           

            //alert(vb[0]+"\n"+vb[1]+"\n"+vb[2]+"\n"+vb[3]);

          aDoc.artboards[0].artboardRect = vb;

        }

       

       

         var aDoc = activeDocument;

          var vb = new Array(aDoc.visibleBounds);

          vb = aDoc.visibleBounds;

            var docWidth = aDoc.width;

            var docHeight = aDoc.height;

           

            var myPathItem = aDoc.pathItems.add();

            alert(myPathItem[0]+"\n"+myPathItem[1]);

       

       

       

           if(kicsinyites){

       

            engWidthMM = 97.89583333; // 370 pixel

            engHeightMM = 97.89583333; // 370 pixel

           

            engWidthPix = 370;

            engHeightPix = 370;

           

            percent = 100; //Alapból 100, tehát nem kell kicsínyíteni

       

           

                //Kicsínyítés ha kell

                if(docWidth > engWidthPix || docHeight > engHeightPix){

                //Szélesebb, ezért csökkenteni kell az engedélyezettre

                     if (docWidth > docHeight) {

                     percent =  ( engWidthPix / docWidth ) * 100;

                    } else {

                     percent = ( engHeightPix /  docHeight ) * 100;

                   }

                }else if( docWidth < engWidthPix ){

                // Kisebb, meg kell nagyítani

                     if (docWidth > docHeight) {

                     percent =  ( engWidthPix / docWidth ) * 100;

                    } else {

                     percent = ( engHeightPix /  docHeight ) * 100;

                   }

                }

               

                if(teszt){

                alert("Percent number: "+percent);

                }

               

            var docRef = app.activeDocument;

             var layerRef = docRef.layers[0];

             var pageItemCount = layerRef.pageItems.length;

             //Minden elemre végig kell futtatni a kicsinyítést

 

             var resize_count = 0;

             with(sourceDoc) {

                var count = pageItems.length;

          

                   

                 if(pageItemCount > 1){

                    for (var i = 0; i < pageItemCount; i++) {

                       

                    oldX = layerRef.pageItems[i].position[0];

                    oldY = layerRef.pageItems[i].position[1];

               

                    oszto = percent/100;

                    newX = oldX*oszto;

                    newY = oldY*oszto;

                       

                    layerRef.pageItems[i].resize( percent , percent );

                    layerRef.pageItems[i].position = new Array(newX,newY);

                    resize_count++;

                    }

                 }else{

                  layerRef.pageItems[0].resize( percent , percent );

                 }

            }

           

            if(teszt){

            alert("Resize count: "+resize_count);

            }

          

             /* 380*380 pixel image */   

             aDoc = activeDocument;

             var vbc = aDoc.visibleBounds;

             

             

             if(pageItemCount > 1){

            // more pageItem

             var fix = 380;

                 

                

              szelesseg = Math.abs(vbc[2] - vbc[0]);

              magassag =  (vbc[3] - vbc[1]);

              //With

              if( szelesseg < fix){

              kulonbozet = (fix-szelesseg)/2;

              vbc[0] -= kulonbozet;

              vbc[2] +=  kulonbozet;

              }

             

              //Height

              if( Math.abs(magassag) < fix){

              kulonbozet = (fix - Math.abs(magassag) )/2;

               if(magassag > 0){

               vbc[1] -= kulonbozet;

               vbc[3] += kulonbozet;

               }else{

                 //Negatív  tesztelve

                vbc[1] += kulonbozet;

                vbc[3] -= kulonbozet;

               }

              }

            

           

             }else{

              vbc[0] = 107;    // left 105

              vbc[1] = 610;   // top  614

              vbc[2] = 487;   // right 485

              vbc[3] = 230;   // bottom 225

             }

           

         aDoc.artboards[0].artboardRect = vbc;

        

         

             

           

           } // if(kicsinyites){ end

              

       }

    }

    else {

        alert('Nincs fájl a könyvtárban');

    }

}

[/code]


Viewing all articles
Browse latest Browse all 12845

Trending Articles