ExtendScript Illustrator - Change color of text one character at a time.

I'm trying to write code for ExtendScript ToolKit to target Illustrator. I've been writing in JavaScript, but am open to switching to AppleScript if needed. The goal of the code is to change the characters in a text box one by one to the color of the image behind that letter. The end goal is to have the color of the text create the image.
Basically, I select a character. And lets say that character is at 720x648 (in pixels) in a 24x36 in image. Then I detect the color in the image layer at that location. Then turn the selected character to that color.
I have encountered two problems, finding a way to have the script detect the color of the picture at a given location (ideally in pixels) and then change that one character to that color.
So far my code is this, with a color hard coded in for testing purposes since I haven't figured out the detection part yet.
if ( app.documents.length > 0 ) {
var doc = app.activeDocument;
//get text from textbox
var numChars = 0;
textArtRange = doc.textFrames[0].contents;
numChars += textArtRange.length;
//loop through to select characters one at a time
for (x=0; x<numChars; x++){
     var selectChar=textArtRange.charAt(x)
     doc.characterStyles.removeAll();
     var charStyle=doc.characterStyles.add("NewOne");
     var charAttr=charStyle.characterAttributes;
     var detectedColor = new RGBColor();   //ideally the detected color would go here. But for now it is hard coded.
         detectedColor.red = 242;
         detectedColor.green = 51;
         detectedColor.blue = 51;
     charAttr.fillColor = detectedColor;
     charStyle.applyTo(selectChar); // I got an error here: "Object expected".
}//end for loop
To detect the color, I tried using the following code, but it only works in Photoshop and even there I can't find a way to store that color the way I need to.
app.activeDocument.colorSamplers.removeAll();
var pixelLoc = [UnitValue(16) , UnitValue(16)];
var myColorSampler = app.activeDocument.colorSamplers.add(pixelLoc);
I have put in so many hours into this and just want to rip my hair out. Any help or guidance anyone can give would be SO appreciated! Thanks in advance!!!

finding a way to have the script detect the color of the picture at a given location (ideally in pixels)
there's no native command to do this in illustrator,
I tried using the following code, but it only works in Photoshop.....
unless you get extremely lucky (working with matching Object names) photoshop code won't work in Illustrator.
a possible workaround, clip your text to your image, rasterize it, trace it, you might end up with a solid color per character, where you could read their color.

Similar Messages

  • How to read from a text file one character at a time?

    Hello
    I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
    can anyone help me?
    Lavi 

    lava wrote:
    I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
    can anyone help me?
    Some additional comments:
    You really don't want to read any file one character at a time, because it is highly inefficient. More typically, you read the entire file into memory with one operation (or at least a large chunk, if the file is gigantic) and then do the rest of the operations in memory.  One easy way to analyze it one byte at a time would be to use "string to byte array" and then autoindex into a FOR loop, for example.
    Of course you could also read the file directly as a U8 array instead of a string.
    Message Edited by altenbach on 06-10-2008 08:57 AM
    LabVIEW Champion . Do more with less code and in less time .

  • How do you change color of text in a sapscript?

    Hi All,
    How do you change color of text in a sapscript?
    Thanks in advance,
    sathish

    Hi,
    It is is not possible in script.
      just check out this weblog
    they have already discussed about color in sapscript.
    Re: SAPSCRIPTS IN COLOR
    Regards
    Kiran

  • How to change color of text is value is equal to 0

    how to change color of text or background if value is equal to 0

    HI,
    In Template Builder,Insert the conditional region,there you select the column and give condition is equal to 0 and in advanced enter the following code
    <?if:XMLfield=0?><xsl:attribute xdofo:ctx="block" name="background-color">red</xsl:attribute><?end if?>
    try this it works.
    Regards
    Uday

  • I want to programmtically change the font of one cell at a time in a LabVIEW table

    I want to programmtically change the font of one cell at a time in a LabVIEW table. How would I do this. I know it is possible to change an individual cells font properties on the front panel but I want to do it via the diagram (code).

    You are able to change each cell's background and foreground (text) color, but it seems the ability to specify font information with properties is lacking in both 6.1 and 7.0.
    Daniel L. Press
    PrimeTest Corp.
    www.primetest.com

  • Reading a string one character at a time

    Hi,
    I'm hoping you use SmallBasic for year 10 exam students at my school.  But, I have found a problem I cannot solve.
    I need to be able to read one character at a time from a string (txt file) and convert each char to its ACSII code.
    How do to I read one char at a time from a string to enable processing?
    Thanks for your help.
    Baz 

    Here is an over the top solution that will display the Hex value of the character codes of every character in the file.
    TextWindow.Write("Enter full file name: ")
    filnam = TextWindow.Read()
    contents = File.ReadContents(filnam) 'read the entire file
    TextWindow.Clear()
    TextWindow.WriteLine("File Name: " + filnam)
    TextWindow.WriteLine("Offset: 0")
    col = 0
    row = 5
    TextWindow.CursorLeft = col
    TextWindow.CursorTop = row
    For i= 1 To Text.GetLength(contents)
    ch = Text.GetSubText(contents, i,1)
    chVal = Text.GetCharacterCode(ch)
    ConvertToHex()
    TextWindow.CursorLeft = col
    If chVal < 32 Then
    TextWindow.Write(".")
    Else
    TextWindow.Write(ch)
    EndIf
    TextWindow.CursorLeft = 20 + 2 + (col * 3)
    TextWindow.Write(Text.GetSubText(hexstr,1,2))
    col = col + 1
    If col = 8 Then
    col = col + 1
    EndIf
    If col > 16 Then
    col = 0
    row = row + 1
    If row > 20 then
    TextWindow.CursorTop = 23
    TextWindow.CursorLeft = 25
    TextWindow.Write("< < < Press ENTER to Continue > > >")
    TextWindow.Read()
    TextWindow.Clear()
    TextWindow.WriteLine("File Name: " + filnam)
    TextWindow.WriteLine("Offset: " + i)
    row = 5
    EndIf
    TextWindow.CursorTop = row
    EndIf
    EndFor
    TextWindow.WriteLine("")
    TextWindow.WriteLine("")
    Sub ConvertToHex
    HexValue[0] = "0"
    HexValue[1] = "1"
    HexValue[2] = "2"
    HexValue[3] = "3"
    HexValue[4] = "4"
    HexValue[5] = "5"
    HexValue[6] = "6"
    HexValue[7] = "7"
    HexValue[8] = "8"
    HexValue[9] = "9"
    HexValue[11] = "A"
    HexValue[12] = "B"
    HexValue[13] = "C"
    HexValue[14] = "D"
    HexValue[15] = "E"
    val = chVal
    hexstr = "h" 'Need to force Small basic to concatenate rather than add
    While val > 0
    hexPos = Math.Remainder(val, 16)
    hexstr = HexValue[hexPos] + hexstr
    val = Math.Floor(val / 16)
    EndWhile
    For hi = Text.GetLength(hexstr) To 2
    hexstr = "0" + hexstr
    EndFor
    EndSub
    Enjoy!

  • How do I display font one character at a time?

    Right now the way I present my font is it all appears
    instanenous. I don't know if this is even possible or not, but I
    would like to find a way to have the font be displayed one
    character at a time over the course of a variable amount of
    seconds. For example, some of you might recognize this font
    presentation from the game "Phoenix Wright" for the Nintendo DS:
    Click
    here
    for example.
    That is the font effect I'm trying to capture - where the
    font is presented in a character by character fashion. Now
    obviously I could achieve this by putting a new letter on every
    frame, but let's be realistic - that's not the logical way to do
    it. Does anyone know the code/options involved in making this font
    display stylization logically possible? Bonus points if you know
    how to make the characters mouths move with the sychronized font
    and then stop once the text stops =).

    Place a dynamic textfield on your stage and label it myText.
    In frame one place the following code,to increase the write
    speed lower the value of 100 in the setinterval call:
    myText.text="";
    var dText="My text I want to display";
    var dTmr=setInterval(ShowNextChar,100,0);
    var cPos=0;
    stop();
    function ShowNextChar()
    myText.text=myText.text+dText.substr(cPos,1);
    cPos++;
    if (cPos==dText.length) clearInterval(dTmr);
    }

  • Loading the laserjet pro 200 color m251 nw one sheet at a time?

    How are you supposed to load the laserjet pro 200 color m251 nw one sheet at a time?

    Hi Choffman,
    Thank you for visiting the HP Support Forums! To get your issue more exposure I would suggest posting it in the commercial forums since this is a commercial product. You can do this at http://h30499.www3.hp.com/hpeb/
    I hope this helps!
    HevnLgh
    I work on behalf of HP
    Please click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to the left of the reply button to say “Thanks” for helping!

  • How do I get the arrow keys to move one character at a time in the address bar or search box?

    I can no longer get the arrow keys to advance or retard "one character at a time" in the address bar, the search box, or on any form in Firefox. This feature works in other browsers without a problem. The "Home" and "End" keys do not work either. How do I fix this behavior?

    How do I configure the AX to connect to the hub's wireless network? It will only scan one base station Airport Express at a time in the Airport Utility. I think what I am trying to do is use the hub as a router to the two AX's. Is there a specific way to set this up?
    To set up the AX to join a wireless network as a "Wireless Client," using the AirPort Utility, either connect to the AX's wireless network or temporarily connect your computer directly (using an Ethernet cable) to the Ethernet port of the AX, and then, try these settings:
    Launch the AirPort Utility.
    Select the AX.
    If not already connected to the AX's wireless network, go ahead and switch to it when prompted.
    AirPort Utility > Select the AX > Manual Setup > AirPort > Wireless
    Wireless Mode: Join a wireless network
    Network Name: <type in the network name/SSID of the wireless network that you want to join or select it from the pop-up menu>
    Wireless Security: None OR, if you are using security on your wireless network:
    Wireless Security: <Select the appropriate level of security for the existing wireless network: WPA/WPA2 Personal | WPA2 Personal>
    Password: <enter your wireless network security password>
    Verify Password: <re-enter the same security password>
    Click Update to write the new settings to the AX.

  • Reading one character at a time

    Hello
    How can i read one character at a time from standard input (System.in) ?
    I have tried to use
    ir=new InputStreamReader(System.in)
    ir.read().
    But this method blocks until it gets a return key pressed before going forward
    Any other solution?

    public static char readChar() {
    int ch;
    char r = '\0';
    boolean done = false;
    while (!done) {
    try {
    ch = System.in.read();
    r = (char) ch;
    if (r == '\r') {
    System.out.println("Not a character. Please try again!");
    System.in.skip(1);
    done = false;
    } else {
    System.in.skip(2);
    done = true;
    } catch (java.io.IOException e) {
    done = true;
    return r;
    Try this as an method and then use it..
    This code will read will be in response untill you hit the return key but will take only the first character....

  • Left arrow key does not go back one character at a time

    on my key pad, I cannot backup "over" characters one space at a time  I am not looking to DELETE, merly to backup one character at a time.  I know I can use the function key along with the arrow key for word at a time jump.  I can jump one character to the right by pushing that key but I cannot do that with my left arrow key.  slight annoyance, but I swear it worked before. . .

    The arrow to open the tab history of the Back and Forward buttons has been removed in Firefox 4 and later.
    Use one of these methods to open the tab history list:
    * Right click on the Back or Forward button
    * Hold down the left mouse button on the enabled Back or Forward button until the list opens
    You can look at this extension:
    * Backward Forward History Dropdown: https://addons.mozilla.org/firefox/addon/backforedrop/

  • Problem --serial port reading one character at a time

    Hi Friend,
    I reading the serial port  one character at a time ,  i specified it in the "serial bytes to read" option in serial port read examples.
    The problem is ----------i can able to read  the data.
    but only the first character is reading again and again...and "reading string indicator" in the serial port example shows only the first character sent ..only for a single time.since i am reading continously ----aleast the first character should display as many times i running the program
    (i am running the vi by run continous option..........)..
    please help me ....how to read the character one by one.....
    regards
    rajasekar

    Hi jason...
    I can able to read the serial port by 1 byte or 2 byte or 4 byte as i can specify it in the serial port read bytes option..(in visa serial read)..
    I need to acquire 4 bytes of data and pass it to the Math-script node..and save these 4bytes of data in array (1 row and 4 column)..
    And split this array(just like array-indexing.vi) and processing it each each column separately....
    or suggest some method to achieve my task.....please.
    one more thing the math-script node is placed in a while loop.....in order to read sequence of bytes continously.......
    regards
    rajasekar

  • Can only text one person at a time??

    I can't believe Apple designed the iPhone so you can only text one person at a time. Major blunder on their part. I really hope they correct this with a software update very soon........
    What does everyone else think?

    Hola RKpod,
    Welcome to the forums!
    This has been a feature that has had a lot of discussion here. For now, the only thing that we could do is request it via the proper channels:
    http://www.apple.com/feedback/iphone.html

  • Typeface changes automatically when changing color on text within a bullet

    Something very weird is happening when I change the color of the typeface within a bullet. As soon as I click on the new color in the Colors palette, the typeface changes to another typeface (one that doesn't even show up in the Fonts palette, so I don't even know what it is). I went back to make sure the slide master had the correct typeface, which it does, and I have the typeface installed on my computer.
    This does NOT happen when I select the entire bullet, just when I select text WITHIN the bullet.
    Any idea what might be causing this?
    Many thanks for any help you might provide.
    Margaret

    Is there a character style applied to the table or text in the table. I had many issues with this over-riding my paragraph style.

  • PS file in illustrator changes color when I move it??

    When I open a ps file in illustrator some objects change color when I move them and are displayed correctly in preview and Photoshop, why and how do I fix this?
    Also the object seems to be duplicated. It should have the same and only the colors of the scale bar. In another file the image part is correct and the scale bar is incorrect.
    Should look like this:

    It is an odd problem. The "good" screen shot is from opening the PS file in mac's preview. As it is, I use several tools in illustrator to get the final image where I need it to be; several layers and what not. I have tired 5, 5.1, and 6 with the same problem. Again I have a different problem when I use a different figure:
    As you can see just the opposite problem is the case. The map part is good while the color scale if off. Both parts are made in the same way and more or less in the same sequence, I don't think it is purely a problem at birth and other software can "see" it correctly, so I don't think it is a hardware problem.  

Maybe you are looking for

  • Creating a pdf that contains forms

    I am trying to create a pdf that combines three pdfs and several forms that I created in LiveCycle Designer ES 8.2. I have enabled using Reader to complete the forms so that they can be saved once completed. My problem is that when I try to combine f

  • Clean Re-install of iTunes?

    Can I re-install iTunes without losing all my songs? iTunes just isn't working... Want to have my iPod back.

  • How can I migrate data from SQL Server 6,5 to Oracle 8?

    We have a web site based on Microsoft SQL Server 6.5.Now we plan to migrate the database to Oracle 8. We have redesigned the tables structure and created tables under Oracle 8, so we only need to migrate data from SQL Server. We've exported data from

  • Progress Tracker

    Hi Experts, I have a form with lot of fields spanning across multiple pages - in order to make the form user friendly and enable the user to keep track of their form filling activity, I want to add a progress tracker which will track the percentage o

  • Webdynpro ABAP- Reference Links- Articals are not opening

    hi all in SDN-Webdynpro abap Webdynpro ABAP->Reference Links->Articals are not opening any another way to open all these articals?? thank u krishna.