We need to change some barcodes so the bars are .25" to the left of the text, and vertical align center. I am struggling with using “move” or “position” to get the bars and the text exactly where I want them. Any suggestions please??
Thank you!
tell application "Adobe Illustrator"
tell document 1
make layer with properties {name:"NumberLayer"}
make layer with properties {name:"BarLayer"}
set myText to every text frame
move myText to layer "NumberLayer"
set barCodes to every path item
move barCodes to layer "BarLayer"
set groupRef to make new group item
move every path item of layer "BarLayer" to end of groupRef
set selectedObjects to selection
try
if selectedObjects = myText then
move myText to position:{0, 64.8}
if selectedObjects = barCodes then
move barCodes to position: {88.3, 60.7}
end if
end if
end try
end tell
end tell
You just need to set the position of the object or objects in question:
tell application "Adobe Illustrator"
tell document 1
set theitem to item 1 of selection --a selection is a list so this gets the first item in the list only
set position of theitem to {(item 1 of position of item 1 of theitem) - 10, (item 2 of position of item 1 of theitem) - 25}
end tell
end tell
The above gets the fist item of a selection (if more than one selected, this is for simplicity) and moves the item a set amount based off of the position property of the item. One way that you could adapt this would be to make groups of both of the text and bar code and move them accordingly:
set position of textgroup {0, 64.8}
set position of barcodegroup {88.3, 60.7}
You cannot just do it to the items of the layers because it will set the upper left starting point for each of the items to the specified position. Another way would be to use the translate of the items of the layer:
translate every page item of layer "BarLayer" delta x 10 delta y 25
Here you could get the current position of the items by setting them as the selection and calculate the distance you need to move the items to get to the desired position.
I liked your second suggestion and that sounds like what I am ultimately trying to do. I need to specify where I want it things to be, not where I need them to move from. However, when I incorporate your suggestion into my script I am getting this error message: "A end of line can’t go after this “}”.
I think I’m not understanding something…
tell application "Adobe Illustrator"
tell document 1
make layer with properties {name:"NumberLayer"}
make layer with properties {name:"BarLayer"}
set myText to every text frame
move myText to layer "NumberLayer"
set barCodes to every path item
move barCodes to layer "BarLayer"
set groupRef to make new group item
move every path item of layer "BarLayer" to end of groupRef
move every text frame of layer "NumberLayer" to end of groupRef
set position of myText {0, 64.8}
set position of barCodes {88.3, 60.7}
end tell
end tell
The error on compiling is due to a missing “to” in your set position line. Try the following:
tell application "Adobe Illustrator"
tell document 1
make layer with properties {name:"NumberLayer"}
make layer with properties {name:"BarLayer"}
move every text frame to layer "NumberLayer"
move every path item to layer "BarLayer"
make new group item with properties {name:"Bar Code"}
move every path item of layer "BarLayer" to end of group item "Bar Code"
make new group item with properties {name:"Text"}
move every text frame of layer "NumberLayer" to end of group item "Text"
set position of group item "Bar Code" to {88.3, 60.7}
set position of group item "Text" to {0, 64.8}
end tell
end tell
Note that I named the groups as I made them to make it easier to call them and used the name to refer to the group when setting the position and adding items to the group.
Thank you for explaining that, I didn’t realize I needed to set my groups up that way and that makes sense.
I must confess tho that this quandry I posted is just a part of a big process. I have been hacking all the pieces together, and just got another error message at "move every text frame to layer “Number” " and the error says “Can’t get every text frame.”
Geez!! Why not?!?
-- Change page dimensions by copying and pasting
set olddelims to AppleScript's text item delimiters
tell application "Illustrator CS"
activate
set selectedItems to selection of document 1
if selectedItems = {} then
tell document 1
set selection to (every page item)
end tell
end if
copy
set newDoc to make new document at beginning with properties {height:112, width:112}
paste
close document 2 saving no
set AppleScript's text item delimiters to olddelims
-- ungroup barcode
set allPageItems to every page item of group item 1 of document 1
move allPageItems to beginning of layer 1 of document 1
-- delete the tiny scrap text made by Barcode program
delete (every character of every text frame of document 1 whose size is less than 5)
delete (every text frame of document 1 whose contents is "")
-- make new layers
set barLayer to make layer at document 1 with properties {name:"Bars"}
set textLayer to make layer at document 1 with properties {name:"Number"}
-- move text and bars to their respective layers
move every text frame to layer "Number"
move every path item to layer "Bars"
make new group item with properties {name:"Bar Code"}
move every path item of layer "Bars" to end of group item "Bar Code"
make new group item with properties {name:"Text"}
move every text frame of layer "Number" to end of group item "Text"
-- set positions of bars and text
set position of group item "Bar Code" to {88.3, 60.7}
set position of group item "Text" to {0, 64.8}
-- convert text to outlines
convert to paths (every text frame of document 1)
-- delete empty layer
set deleteLayer to "Layer 1"
delete (every layer of document 1 whose name starts with deleteLayer)
end tell