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

Merging diagonal text together

New Here ,
May 22, 2014 May 22, 2014

Hi I'm trying to merge these groups of text together but i'm having trouble keeping the spaces after i merge it with my current code.

BEFORE

letters.PNG

AFTER

letters2.PNG

here is my current code

var textLayer = idoc.layers[0]

textLayer.name = "Text";

for (var i = 0; i < textLayer.groupItems.length; i++){

    var tempText = ""

   

    var anchor1 = textLayer.groupItems.textFrames[0].anchor

    var anchor2 = textLayer.groupItems.textFrames[1].anchor

   

    var TextOnAngle = IsTextOnAngle(anchor1[0],anchor1[1],anchor2[0],anchor2[1])

   

    var TextAngleDeg = TextAngle(anchor1[0],anchor1[1],anchor2[0],anchor2[1])

    for (var j = 0; j < textLayer.groupItems.textFrames.length; j++){

        if (j == 1){

            var newText = textLayer.groupItems.textFrames.duplicate(textLayer, ElementPlacement.INSIDE)

           

        }

        if (tempText == "") {

                tempText = textLayer.groupItems.textFrames.contents;

          } else {

                tempText = tempText + textLayer.groupItems.textFrames.contents;

               

                if(TextOnAngle){

                   

                    if(j+1 < textLayer.groupItems.textFrames.length){

                        var tempAnchor1 = textLayer.groupItems.textFrames.anchor

                        var tempAnchor2 = textLayer.groupItems.textFrames[j+1].anchor

                           

                        var CurrentAngle = TextAngle(tempAnchor1[0],tempAnchor1[1],tempAnchor2[0],tempAnchor2[1])

                           

                        if(!(CurrentAngle <= TextAngleDeg+5 && CurrentAngle >= TextAngleDeg-5)){

                           

                            //alert(CurrentAngle)

                                tempText = tempText + '\r'

                           

                        }

                    }

                }

           }

    };

    //var newText = textLayer.textFrames.add()

        newText.contents = tempText

};

textLayer.groupItems.removeAll()

//gets the angle of the text

function TextAngle(x1,y1,x2,y2){

    var xDiff = x1 - x2

    var yDiff = y1 - y2

    return Math.atan2(yDiff, xDiff) * (180 / Math.PI)

}

// works out if text is on an angle or not

function IsTextOnAngle(x1,y1,x2,y2){

    if((x1 >= x2-0.1 && x1 <= x2+0.1) || (y1 >= y2-0.1 && y1 <= y2+0.1)){

        return false

    }else{

        return true   

    }

}

//gets the angle of the text

function TextAngle(x1,y1,x2,y2){

    var xDiff = x1 - x2

    var yDiff = y1 - y2

    return Math.atan2(yDiff, xDiff) * (180 / Math.PI)

}

// works out if text is on an angle or not

function IsTextOnAngle(x1,y1,x2,y2){

    if((x1 >= x2-0.1 && x1 <= x2+0.1) || (y1 >= y2-0.1 && y1 <= y2+0.1)){

        return false

    }else{

        return true   

    }

}

}

if anyone has any ideas on how i can go about working out where to insert the spaces that would be great.

thanks in advance

TOPICS
Scripting
503
Translate
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

LEGEND , May 22, 2014 May 22, 2014

It may be easiest to rotate the text to horizontal, do the replacement of spaces and re-rotate the text. You could use a variable to store the rotation value.

Translate
Adobe
LEGEND ,
May 22, 2014 May 22, 2014

There are no spaces in your text right now. Notice there are no anchors indicated at the right side of the d and the 5 below it. The text is just being concatenated as is. What is generating the individual characters in the text now?

Translate
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 ,
May 22, 2014 May 22, 2014

thanks larry it is being produced by a CAD program printing to PDF, I did realize there where no actual spaces but i don't know how i could work out where to insert a new space, If its horizontal you can just see if the next letters anchor point is at the current anchor point plus the width of the letter and if not add another space. But I'm not sure how to go about it for diagonal Text

Translate
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
LEGEND ,
May 22, 2014 May 22, 2014

It may be easiest to rotate the text to horizontal, do the replacement of spaces and re-rotate the text. You could use a variable to store the rotation value.

Translate
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 ,
May 26, 2014 May 26, 2014
LATEST

thanks Larry that was the idea i needed

Translate
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