Quantcast
Channel: Adobe Community : Discussion List - Illustrator Scripting
Viewing all articles
Browse latest Browse all 3671

Need to remove some characters in the text in active document

$
0
0

Hi all,

Here I had made a script to write equations with superscript.

The input maybe

a^{2}+b^{2}=c^{2}

The Required output is

 

a2+b2=c2

The script I made is.

if(documents.length >0){  //if document is open          if(app.activeDocument.selection[0]){  //if a line is selected          var supBPosition=[];         var subBPosition=[];        var doc = app.activeDocument;  //getting the active document        var line = doc.pathItems[0];  //getting path items from the active document          var firstPoint = line.pathPoints[0].anchor; // [x, y]        var lastPoint = line.pathPoints[line.pathPoints.length - 1].anchor; // [x, y]                var eqValues = (prompt("Enter something ", "", "")); //getting the values to write        var eqValuesCopy=eqValues;        var startCharacterSize=0;        var ys=[];         var ns=[];        var nsDummy=[];        var yFlag=0;         var nFlag=0;        var plotGraph=1;        getPositions();           var finalContent=eqValues;        if(eqValues.indexOf("^")>0){                                     plotGraph= doc.textFrames.add();  //adding text            plotGraph.textRange.characterAttributes.size = 8;  //character size for text            plotGraph.textRange.characterAttributes.textFont = app.textFonts.getByName("Times-Roman"); //for changing the font to times-roman            plotGraph.textRange.justification = Justification.CENTER;  //for aligning the content to center            plotGraph.top = firstPoint[1];  //x coordinate for the new value            plotGraph.left = firstPoint[0];  //y coordinate for the new value                        plotGraph.contents=(finalContent);            var t = doc.textFrames[0];              for(var m=0;m<=ns.length;m++){                for(var plotGraphSup=ys[m];plotGraphSup<=ns[m];plotGraphSup++){                      thisChar = t.characters[plotGraphSup];  //writing base value                                   thisChar.characterAttributes.baselineShift = +3;  //making superscript                      thisChar.characterAttributes.size = 6;  //adjusting size of superscript                }                             }        }    }    function getPositions(){            for(var i=0;i<eqValuesCopy.length;i++){            if(eqValuesCopy[i]=="{"){                if(i!=0){                    validBCheck=eqValuesCopy[i-1]+eqValuesCopy[i];                    if(validBCheck!="/{"){                        ys.push(i);                    }                }            }            ysLength=ys.length;        }        for(var i=0;i<eqValuesCopy.length;i++){            nsLength=ns.length;            if(nsLength<ysLength){                if(eqValuesCopy[i]=="{"){                    var j=i;                    while(j<eqValuesCopy.length){                        j++;                        if(eqValuesCopy[j]=="}"){                            ns[nsLength]=j;                            break;                         }else if(eqValuesCopy[j]=="{"){                             nsLength++;                        }else{                                                     }                    }                      i=j;                }            }        }        for(var k=0;k<eqValuesCopy.length;k++){            if(eqValuesCopy[k]=="}"){                var h=k;                while(h<eqValuesCopy.length){                    h++;                    if(eqValuesCopy[h]=="{"){                        break;                    }else if(eqValuesCopy[h]=="}"){                         nsDummy.push(h);                        break;                    }else{                                             }                }            }        }        nsDummy.reverse();        for(var x=0;x<nsLength;x++){            if(ns[x]===undefined){                ns[x]=nsDummy[x];            }        }    }
}

 

 

Also I am getting an error in line number "32".

 

 

 

 

 

 

 

Moved from Illustrator to Illustrator Scripting by moderator

 

 

 

.


Viewing all articles
Browse latest Browse all 3671

Trending Articles



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