Skip to main content
Known Participant
July 17, 2019
Question

Copy-paste elements from a AI document to specific coordinates

  • July 17, 2019
  • 1 reply
  • 944 views

Greetings everyone,

I've a quite complexe challenge and my only hope would be through a JavaScript.

I don't know Javascript yet and I'm trying to figure out how to do it.

I've got AI documents with various objects on it (text, images ...) and some of those images represent numbers (see the Yellow dots).

My challenge is to transform those dots (images) onto a text box, at the exact same place and filed with the name of the object (each object is named "01", "02" ...).

My guess is to use the coordinates of each dot's layer, save them as variables, paste a text boxfrom another document on the page and then assign the saved coordinates to this new text box. I've no clue for pasting the object name into this text box though ...

By the same time, I would need a script that can past the title of the document to a specific place on the document.

Any help from you guys would be greatly appreciated

Many thanks in advance

    This topic has been closed for replies.

    1 reply

    JonathanArias
    Legend
    July 18, 2019

    why would you do this from illustrator?

    Known Participant
    July 18, 2019

    Hi JonathanArias,

    I have to use Illustrator to export the final document in SVG.

    And using illustrator would be better to gain productivity (I have about 3000 document to do ...)

    In complement, I've worked on a Photoshop script that actually do what I'm looking for.

    I would be interested in having it working for Illustrator as well (with adaptations ...)

    The best would be to be able to establich a loop of treatment inside a specific layer set.

    Thank you in advance for your help !

    1. var doc = activeDocument
    2. var TextBox = doc.layerSets.Text
    3. //Management of the active Layer
    4. var dotLayerName = doc.activeLayer.name
    5. var dotLayer = doc.activeLayer
    6. // Function to create the text box
    7. createText("Arial-BoldMT", 29, 255,255,255, dotLayerName, 100, 50)
    8. activeDocument.activeLayer.name = dotLayerName
    9. activeDocument.activeLayer.textItem.justification = Justification.CENTER
    10.     function createText(fface, size, colR, colG, colB, content, tX, tY){
    11.      
    12.   // Add a new layer in the new document
    13.   var artLayerRef = app.activeDocument.artLayers.add()
    14.   // move the layer to the layer set Text
    15.   artLayerRef.move(TextBox, ElementPlacement.INSIDE)
    16.  
    17.   // Specify that the layer is a text layer
    18.   artLayerRef.kind = LayerKind.TEXT
    19.   //This section defines the color of the hello world text
    20.   textColor = new SolidColor();
    21.   textColor.rgb.red = colR;
    22.   textColor.rgb.green = colG;
    23.   textColor.rgb.blue = colB;
    24.   //Get a reference to the text item so that we can add the text and format it a bit
    25.   textItemRef = artLayerRef.textItem
    26.   textItemRef.font = fface;
    27.   textItemRef.contents = content;
    28.   textItemRef.color = textColor;
    29.   textItemRef.size = size
    30.   textItemRef.position = new Array(tX, tY) //pixels from the left, pixels from the top
    31.  
    32.   var dotLayerCenterX = (dotLayer.bounds[0] + dotLayer.bounds[2])/2; 
    33.   var dotLayerCenterY = (dotLayer.bounds[1] + dotLayer.bounds[3])/2; 
    34.   var textLayerCenterX = (artLayerRef.bounds[0] + artLayerRef.bounds[2])/2; 
    35.   var textLayerCenterY = (artLayerRef.bounds[1] + artLayerRef.bounds[3])/2;
    36. //move text layer 
    37. artLayerRef.translate(dotLayerCenterX-textLayerCenterX, dotLayerCenterY-textLayerCenterY)
    38. }
    JonathanArias
    Legend
    July 18, 2019

    i have used this in the past:

    https://blog.mikeswanson.com/ai2canvas

    but what i did what simpler than what you are looking to do.