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

Neo, whats up with this Matrix stuff?

Explorer ,
Mar 23, 2013 Mar 23, 2013

Copy link to clipboard

Copied

I want to evaluate text frames for their x axis and if they are the same shift them slightly because of adobes irritating habit of combining the text frames when it makes a PDF. I have been able to evaluate, but not exactly like I want to but I know it can be done...

var mydoc = app.activeDocument;

var mytext = mydoc.textFrames;

var allX_Vaues = new Array();



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

var mytextFrames = mydoc.textFrames;

var theMatrix = mytextFrames.matrix;

allX_Vaues.push(theMatrix.mValueTX)

var firstEval = allX_Vaues

//$.writeln(theMatrix.mValueA+"\r"+theMatrix.mValueB+"\r"+theMatrix.mValueC+"\r"+theMatrix.mValueD+"\r"+theMatrix.mValueTX+"\r"+theMatrix.mValueTY);

//alert(allX_Vaues);

}

//alert(allX_Vaues[1]);

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

if (allX_Vaues == allX_Vaues[i + 1] ) {

alert(allX_Vaues + " and " + allX_Vaues[i +1] + " are the same");

}

else

{

alert(allX_Vaues + " and " + allX_Vaues[i +1] + " are different");

}

}

my problem is when I try to move text frames...

   var mydoc = app.activeDocument;

    var mytext = mydoc.textFrames[0];

    var matrixValue = mytext.matrix.mValueTX

    var addToMatrix = 1

    var moveMatrix = app.getTranslationMatrix(theMatrix);

    var totalMatrix = concatenateTranslationMatrix(moveMatrix, addToMatrix)

    mytext.transform(totalMatrix);

    //alert(moveMatrix);

It flies way of the page. I just want to move the text a slight amount and concatenate is the only way I have been successful. my question is: Is there a better way and why is my text flying so far of the page?

any help would be appreciated,

Duane

TOPICS
Scripting

Views

1.6K

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 , Apr 06, 2013 Apr 06, 2013

position retruns an (x,y) array, so you can do

x = sel.position[0];

y = sel.position[1];

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 23, 2013 Mar 23, 2013

Copy link to clipboard

Copied

those two matrixes you're using are not the same thing and can't be combined the way you're doing it. If you just want to move a textframe use the translate() method

var mydoc = app.activeDocument;

var mytext = mydoc.textFrames[0];

var deltaX = 1; // distance to move in X direction

var deltaY = 0;

mytext.translate (deltaX, deltaY);

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
Enthusiast ,
Mar 24, 2013 Mar 24, 2013

Copy link to clipboard

Copied

Or just like this:

mytext.left += 10;

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
Explorer ,
Mar 24, 2013 Mar 24, 2013

Copy link to clipboard

Copied

Thanks Carlos,

That worked well. I have one more problem with this. I am wanting to evaluate the Y axis to see if any text frames are close to each other and then if they are evaluate and see if any of those have the same X axis. I have been able to do this by checking text frame 0 against all other text frames, but it escapes me how I would go about having it evaluate all the rest of the frames against each other. For example textFrames[1] against textFrame.length and then textFrames[2] against textFrame.length and so on till all have been evaluated.

Any Ideas?

var mydoc = app.activeDocument;

var mytext = mydoc.textFrames;

var allX_Values = new Array();

var allY_Values = new Array();

var mainTF = 0;

var deltaX = 1; // distance to move in X direction

var deltaY = 0;

for (a =0; a < mytext.length; a++) {

    var mytextFrames = mydoc.textFrames;

    var theMatrix_X = mytextFrames.matrix;

    allX_Values.push(theMatrix_X.mValueTX);

    }  

for (b =0; b < mytext.length; b++) {

    var mytextFrames = mydoc.textFrames;

    var theMatrix_Y = mytextFrames.matrix;

    allY_Values.push(theMatrix_Y.mValueTY);

    }

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

    var differenceOfY = allY_Values[0] - allY_Values[i + 1];

    if(differenceOfY <= 15 && differenceOfY >= -15) {

      

    if (allX_Values[mainTF] == allX_Values[i + 1] ) {

        var theNextValue = allX_Values[i + 1];

        if (theNextValue <= mytext.length) {

            mytext[i + 1].translate (deltaX, deltaY);

            }

        }

    }

}

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 Expert ,
Mar 24, 2013 Mar 24, 2013

Copy link to clipboard

Copied

here you go, I tampered with your code a little bit and moved the text frames in the X and the Y directions, I don't know if that's what you need...but it is just to illustrate.

var mydoc = app.activeDocument;

var mytext = mydoc.textFrames;

var allX_Values = new Array();

var allY_Values = new Array();

for (a =0; a < mytext.length; a++) {

    var mytextFrames = mydoc.textFrames;

    var theMatrix_ = mytextFrames.matrix;

    allX_Values.push(theMatrix_.mValueTX);

    allY_Values.push(theMatrix_.mValueTY); // one loop should be enough to get both TX and TY values

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

    for (j = i+1; j<allY_Values.length; j++) {

        var deltaX = 0; // distance to move in X direction

        var deltaY = 0;

        var differenceOfY = allY_Values - allY_Values;

        var differenceOfX = allX_Values - allX_Values;

       

        if(differenceOfY <= 15 && differenceOfY >= -15)

            var deltaY = 1;

        if(differenceOfX <= 15 && differenceOfX >= -15)

            var deltaX = 1;

        mytext.translate (deltaX, deltaY);

    }

}

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
Explorer ,
Apr 06, 2013 Apr 06, 2013

Copy link to clipboard

Copied

Thanks for the help Carlos. I finished my script but I have a problem with some files giving me a false mValueTX value. I am looking at a file that has two numbers diagonal from each other and they are showing the same value for mValueTX. I copy past those two numbers from that file to a new one and check there x value and it gives me the values that are not the same, like it should. do you have any idea why it would do this?

my script for staggering the text.

staggerText ();

//-------------------------------------------------------------------------------------------------------------------------------

//       This function staggerText

//-------------------------------------------------------------------------------------------------------------------------------

function staggerText () {

var mydoc = app.activeDocument;

var mylayer = mydoc.activeLayer;

var mytext = mylayer.textFrames;

var mainTF = 0;

checkTextOver ();

function checkTextOver () {

    var allX_Values = new Array();

    var allY_Values = new Array();

    var deltaX = 01; // distance to move in X direction

    var deltaY = 0;

    //alert( " inside checkTextOver mainTF = " + mainTF);

    for (a =0; a < mytext.length; a++) { // for loop is for cycling through the I value. in this case the textFrames to evaluate the matrix and save the X axis value in an array

        var mytextFrames = mydoc.textFrames; // this is the current textFrame in the cycle

        var theMatrix_X = mytextFrames.matrix; // to load the matrix to a value

        allX_Values.push(theMatrix_X.mValueTX); // adds theMatrix.mValueTX to the array

        //alert("The X array " +allX_Values); // alert you of the Values added to the array every cycle

               }

    //alert("has finished X array");

    for (b =0; b < mytext.length; b++) { // for loop is for cycling through the I value. in this case the textFrames to evaluate the matrix and save the Y axis value in an array

        var mytextFrames = mydoc.textFrames; // this is the current textFrame in the cycle

        var theMatrix_Y = mytextFrames.matrix; // to load the matrix to a value

        allY_Values.push(theMatrix_Y.mValueTY); // adds theMatrix.mValueTY to the array

        //alert("The y array " + allY_Values); // alert you of the Values added to the array every cycle

        }

    //alert("has finished Y array");

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

        var differenceOfY = allY_Values[mainTF] - allY_Values;

        var textCountPerFrameSecond = mytext.textRange.length;    

        if(mainTF < i) {       

            var textCountPerFrameFirst = mytext[mainTF].textRange.length;

            //alert("differenceOfY = " + differenceOfY + "\r" + "allY_Values[mainTF] = " + allY_Values[mainTF] +  "\r" + "allY_Values = " + allY_Values +  "\r" + "allX_Values[mainTF] = "  + allX_Values[mainTF] +  "\r" + "allX_Values = " + allX_Values + "\r"+ "The mainTF = " + mainTF + "\r" + "The Second value is = " +  i + "\r" +  "textFrame " + mytext[mainTF].contents + " against textFrame " + mytext.contents +  "\r" +  "First frame and Second frame = " + (textCountPerFrameFirst + textCountPerFrameSecond));

            //alert(mainTF + " is less that" + i);             // alert("differenceOfY = " + differenceOfY + "\r" + "allY_Values[mainTF] = " + allY_Values[mainTF] + "\r" + "allY_Values = " + allY_Values + "\r"+ "The mainTF = " + mainTF + "\r" + "The Second value is = " + i + "\r" + allY_Values + "\r" + "textFrame " + mytext[mainTF].contents + " against textFrame " + mytext.contents);

            if(differenceOfY < 15 && differenceOfY > -15 && allX_Values[mainTF] === allX_Values && textCountPerFrameFirst + textCountPerFrameSecond === 2) {

                 // alert( textCountPerFrameFirst + textCountPerFrameSecond); //alert("made it past the difference of Y. So " + differenceOfY + "must be between 16 and -16" );                 //alert("made it past the alignment of x. " + allX_Values[mainTF] + " is the same as " + allX_Values );                // var theNextValue = allX_Values;

                 alert("differenceOfY = " + differenceOfY + "\r" + "allY_Values[mainTF] = " + allY_Values[mainTF] +  "\r" + "allY_Values = " + allY_Values +  "\r" + "allX_Values[mainTF] = "  + allX_Values[mainTF] +  "\r" + "allX_Values = " + allX_Values + "\r"+ "The mainTF = " + mainTF + "\r" + "The Second value is = " +  i + "\r" +  "textFrame " + mytext[mainTF].contents + " against textFrame " + mytext.contents +  "\r" +  "First frame and Second frame = " + (textCountPerFrameFirst + textCountPerFrameSecond));

                 mytext.translate (deltaX, deltaY);

                 //alert("frame " + mainTF + " has and X value of "+ allX_Values[mainTF] + "\r" + "frame " + + " has and X value of "+ allX_Values  + "\r" + " these are the same");                 // alert(i + " is less or equal to " + allX_Values.length);  //alert(" my array is " + allX_Values);

                 }

             }

         //alert("the end " + differenceOfY);     resetTextFrame ();

         }

     resetTextFrame ();

     }

function resetTextFrame () {

    if (mainTF <= mytext.length) {

        mainTF = mainTF + 1;

        // alert( " inside resetTextFrame mainTF = " + mainTF);

        checkTextOver();

        }

    }

}

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 Expert ,
Apr 06, 2013 Apr 06, 2013

Copy link to clipboard

Copied

your code is a little bit complicated, if matrix is not giving you the desired results, try using the more common position property or the top and left properties.

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
Explorer ,
Apr 06, 2013 Apr 06, 2013

Copy link to clipboard

Copied

is the position property a property of the text frame? I would use that. can you show me the proper cintax for using position property?

with this simple script im asking for the two frames x value and as you can see in the image they are not directly above each other but i still get a value for both as -7958. wierd!

var mydoc = app.activeDocument;
var mylayer = mydoc.activeLayer;
var mytext = mylayer.textFrames;

mytext[15].selected = true;
mytext[19].selected = true;


var xValue1 = mytext[15].matrix.mValueTX;
var xValue2 = mytext[19].matrix.mValueTX;

alert(xValue1 + " is the x value of 15 " + "\r" + xValue2 + " is the x value of 19");

problemWithXValue.png

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 Expert ,
Apr 06, 2013 Apr 06, 2013

Copy link to clipboard

Copied

yeah, matrix properties like mValueTX are not actual position values, they are values of the tranformation matrix applied at a text frame.

for what you're trying to do, actual position will work fine, here's a sample on how to use it.

select a text frame before running

var idoc = app.activeDocument;

var sel = idoc.selection[0];

alert(sel.position);

sel.position = [0,0];

alert(sel.position);

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
Explorer ,
Apr 06, 2013 Apr 06, 2013

Copy link to clipboard

Copied

cool! do you know if it is posible to make an if statment that says if sel[0] has the same first value 0,0) as sel[1]? I dont know if you can evaluate only on value without a string since position returns both x and y values.

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
Explorer ,
Apr 06, 2013 Apr 06, 2013

Copy link to clipboard

Copied

Thanks Carlos!!! I got it to work.

var mydoc = app.activeDocument;
var mylayer = mydoc.activeLayer;
var mytext = mylayer.textFrames;
var sel = mydoc.selection;
var mainSel = 0;
checkTextOver ();

function checkTextOver () {
    for (a =0; a < sel.length; a++) {
        var selFirst = mydoc.selection[mainSel];
        if (mainSel < a) {
            var selSecond = mydoc.selection;   
            if (a < sel.length) {                //alert("selection mainSel is = " + mainSel + ...




.position = [xValue , yValue];
                    }
                }
            }
        }
    resetT...

function resetTextFrame () {
    if (mainSel <= sel.length) {
        mainSel = mainSel + 1;        // alert( " inside resetTextFrame mainTF = " + mainTF);
        checkTextOver();
        }
    }   //alert(mainSel);

the script goes through and evaluates every selected object to see if it is close on the y axis and if it is lined up on the x axis and if it is moves the second object slightly on the y axis.

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 Expert ,
Apr 06, 2013 Apr 06, 2013

Copy link to clipboard

Copied

LATEST

position retruns an (x,y) array, so you can do

x = sel.position[0];

y = sel.position[1];

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