Copy link to clipboard
Copied
tell application "Adobe InDesign CS5.5"
tell active document
make graphic line with properties {geometric bounds:{Watch2, Watch3, Watch4, Watch1}, flip:vertical, applied object style:"Crossout"}
end tell
end tell
Hi,
i need to write a script which draws a line before a selected text. So far, i have the x1/y1 + x2/y2 coordinates narrowed down (left it out in the code to keep the question simple), and this works fine by now.
But:
I need to draw the line just onto the selected text, e.g. the active textbox. When i do it this way (because im not so talented at scripting), the line gets created on page 1, but should alway land over the current textbox.
Can someone help me out?
While you guys are on it:
• A next question if this works out would be, how to "group" the line together with that textbox behind?
• And: The textbox could contain more items than one that get "crossed out", so all lines should group together. (Not that if I want to break a textbox with 5 lines, that i have 5 "housed" groups of lines)
Heres a picture for what I need theses lines:
Good morning,
here we go further
at the start having a group selected -> create a new page item -> using UI-Scripting to ungroup the group -> creating a new group storing all involved page items
...
tell application "Adobe InDesign CS5.5"
tell active document
--get selection = group
set currGroup to item 1 of selection
--get page of currGroup
set currPage to parent page of currGroup
--get Bounds ...
set currBounds to geometric bounds of currGroup
--c
Copy link to clipboard
Copied
Hi,
it's always the whole textframe to be crossed out¿
Try this:
tell application "Adobe InDesign CS5.5"
tell active document
set textFrame to item 1 of selection
set currPage to parent page of textFrame
set textFrameBounds to geometric bounds of textFrame
set theLine to make graphic line at currPage with properties {applied object style:"Crossout"}
set anchor of path point 1 of path 1 of theLine to {item 2 of textFrameBounds, item 3 of textFrameBounds}
set anchor of path point 2 of path 1 of theLine to {item 4 of textFrameBounds, item 1 of textFrameBounds}
make group with properties {group items:{textFrame, theLine}}
end tell
end tell
I don't understand :
• And: The textbox could contain more items than one that get "crossed out", so all lines should group together. (Not that if I want to break a textbox with 5 lines, that i have 5 "housed" groups of lines)
Hans-Gerd Claßen
P.S. Did you have a look in the AS-scripting guide¿
Copy link to clipboard
Copied
Thank you, ill will test this at work tomorrow.
Ill try to explain what i mean, but im not a native english speaker and my client is german too, but i will try:
I have a textbox with some words, old prices for products, that need to be crossed out. Usually ill take the linetool, and draw by hand a line over it, and group it with the box, to move around the two things together. Of course, a textbox could contain a small list of up to 10 words that need to be crossed out. To optimize my workflow, ive done a script to press with a shortcut, that draws that line over my selected text.
Now the grouping:
Ive done that for quark before, but now im a beginner to translate that to indesign. It worked like this: it drawed the line, then called the ,ungroup' command. The box and everything grouped with it stayed selected. Now i sat the new line to selected too, and grouped evything together back again.
Can i achieve something like this in ind?
Copy link to clipboard
Copied
Hi,
I'm not sure if you're talking about anchored textframes ... reading between the lines intends this which would make a difference ...
I wouldn't use graphic lines at all. Ever thought of a table containg one cell¿ (cell style -> diagonal line)
Hans-Gerd Claßen
Copy link to clipboard
Copied
Hi Hans,
nesting a table in a textbox to insert our text that need to be crossed out seems to be a bit to much of a workaround for me and my collegues, who just want to build the things like we used to do. Formating this cell to maintain the width of the price like 199,95 or 1,99 seem to be a hassle. So everyone does that with a line over the text.
While the line cannot be anchored in the textbox, because i assume the line cant be anchored infront of a price and then go "over" the following characters, our way to work is to group the line and the box together.
I tried your code, but set textFrame to item 1 of selection --> "1,99"
set currPage to parent page of textFrame --> "parent page of "1,99"" could not be read -1728
cant solve my issue. The selection is always just some text in a textbox, not the whole box. Maybe theres another way around to get the page of the selection in a textbox?
After all, to group theLine with the textbox which contains the selected text, i must somehow get the box selected again, know its name to adress it.
Copy link to clipboard
Copied
Hi,
if your selection is some text you should get the parent page by item 1 of targeting the parent text frames and then its parent page.
Sorry I'm on a PC today, so here's the javascript equivalent:
#target Indesign
//assuming some text as selection (word, character ...)
var currPage = app.selection[0].parentTextFrames[0].parentPage;
Ungroup / group:
If you ungroup a group the reference to the items of the group will change. so you've got to indentify each before ungrouping. This may be done by getting there ID, setting label, insert label, setting name ... then store them in a array and group again.
Copy link to clipboard
Copied
Is it possible to call menue-actions from the UI?
Then it would be possible to "ungroup" --> the objects stay selected.
Then i would add theLine to the selection. (don't know how, because "select theLine" would de-select everything else, so "set theLine selection to true" or something like that, if thats possible)
Then i would call the "group" action again.
Copy link to clipboard
Copied
Of course you can call menu actions:
//Gruppierung aufheben ausführen
app.menuActions.itemByID(118845).invoke();
and you can add a page item to a existing selection.
usage example:
app.select(app.activeDocument.graphicLines[0], SelectionOptions.ADD_TO)//some selection already exists ...
If you run into problems translating to AS I would have a look at the AppleScript scriptingguide - it's pretty good!
Hans-Gerd Claßen
Copy link to clipboard
Copied
Its a pity and im ashamed, but as a designer my only knowledge in scripting is based on disassembling samplescripts. I learned this and that, working with variables and a bit of the structure in AS. but the most errors i stumble upon i cant solve myself and have to ask for help. based on help like from you i conclude and learn a bit more.
I worked with the AppleScriptLanguageGuide.pdf, but i dont understand the deep structure and have a rocky road ahead, if things dont function as i exspect. i achieved a lot, but the most still is try and error.
And now you throw some JS in the ring and my chances of erroring to an running script tend to zero.
im sorry, but working with these JS snippets is too complicated for me now.
I apreciate your kind help, but i have to wait until you are on a mac – i cant work this out alone anymore.
Copy link to clipboard
Copied
Good morning,
here we go further
at the start having a group selected -> create a new page item -> using UI-Scripting to ungroup the group -> creating a new group storing all involved page items
tell application "Adobe InDesign CS5.5"
tell active document
--get selection = group
set currGroup to item 1 of selection
--get page of currGroup
set currPage to parent page of currGroup
--get Bounds ...
set currBounds to geometric bounds of currGroup
--create line
set theLine to make graphic line at currPage
set anchor of path point 1 of path 1 of theLine to {item 2 of currBounds, item 3 of currBounds}
set anchor of path point 2 of path 1 of theLine to {item 4 of currBounds, item 1 of currBounds}
--invoking the ungroup command has to be outside the document tellblock...
my unGroupCommand(currGroup)
--page items still selected, store them in a array
set currSel to selection
--add theLine to currSell
set end of currSel to theLine
--make new group
make group with properties {group items:currSel}
end tell
end tell
on unGroupCommand(aGroup)
tell application "Adobe InDesign CS5.5"
set ungroupMenuAction to menu action id 118845
invoke ungroupMenuAction
end tell
end unGroupCommand
How to get parent page of textselection:
tell application "Adobe InDesign CS5.5"
tell active document
--some text selected
set currSel to object reference of item 1 of selection --class of selection is always list
set parentTextFrame to item 1 of (parent text frames of currSel) --class of parent text frames is always list
set parentPage to parent page of parentTextFrame
end tell
end tell
stay strong, keep working on it!
Hans-Gerd Claßen
Copy link to clipboard
Copied
Well, you saved my day. It's not perfect, but it works as a version #1. But i thank you for your help. This at its state speeds up my workflow substantially.
I left the grouping stuff out, it doesent work and i have no time on my hands right now to figure out why.
I found out, that when I select text in a box, i cant set currGroup to item 1 of selection, because the result will be a text like "19,99". If i can target the group of that textbox, i can save it. Then i would draw the line like before, target that group or textbox, "try" the ungroup, add theLine to the selection (set currentSelection to selection; select {currentSelection,theLine}, than group back together. All I need is targeting the group, which I cant figure out 🙂
The next thing to solve would be:
If the textbox isnt on a page (like we use the workspace next to the pages to drop off boxes for later usage), the code (set theLine to make graphic line at parentPage with properties…) produces an error. Somehow i have to teach ind, to draw the line where the position of that textbox is, anywhere.
Copy link to clipboard
Copied
I found out, that when I select text in a box, i cant set currGroup to item 1 of selection, because the result will be a text like "19,99".
correct, that's why the line in the example was:
set currSel to object reference of item 1 of selection --class of selection is always list
As you may see, the functionality of a script requires exact known conditions ... sounds overly didactic, but shouldn't!
One last tipp: www.hilfdirselbst.ch -> we speak german
Copy link to clipboard
Copied
Hey Hans,
now im nearly happy.
But i found out that to adress the group the object reference had to be deeper down, coming from the texttool, you have to use the select-tool, and click beside the box, then on it, to have the group activated.
so i did…with menu-calls
i took the script on the website and generated my menu action ids, then i made more subroutines like yours.
i ended up with this, which works fine now:
-- this is my line, its fine…except when the textbox is off the page it doesnt work…but maybe you can help me out
set theLine to make graphic line at parentPage with properties {geometric bounds:{Watch2, Watch3, Watch4, Watch1}, flip:vertical, stroke color:"Strichfarbe", stroke weight:1}
-- now i called the tools
my tool() -- get the selection tool
try
my Container() -- if youve selected a box in a group, the Container-command selects the group outside. lets try this, in case its the first line for the box and theres no group yet
my unGroupCommand() -- now ungroup, everything inside that group is selected now
end try
set mystuff to object reference of selection as list -- save the objects to group them later
copy theLine to the beginning of mystuff -- add theline to the group
make group with properties {group items:mystuff} -- group it together
try
my Container() -- while after grouping the whole group is selected, i want to select the textbox again to save doubleclicks for further line-crossing
my texttool() -- set the tool to the last used after editing
end try
what do you think?
its a workaround, but it works…around 🙂
only thing to do is to draw the line while the textbox is somewhere else except on the page.
i would like to use hilfdirselbst.ch because im german (too?), but out brilliant IT dont want us designers to 'waste' time in the internet.
next time ill call them up "jürgen, kannst du mir das mal eben in applescript schreiben?"… they have no clue, at all!
Copy link to clipboard
Copied
... because im german (too?)...
that's the reason for my great english skills 😉
If your script works for you -> great!
only thing to do is to draw the line while the textbox is somewhere else except on the page.
well, a page item (which is not anchored) stored next to the page should have a spread as parent.
so, if you set ruler origin to RulerOrigin.SPREAD_ORIGIN you can create the line at the spread and use the bounds as usual
Have a good day !
Tschüss
Hans-Gerd Claßen
Copy link to clipboard
Copied
Panic!
While working with Ind and my (our) new script, I accidentailly did something in my doc (maybe by pressing a wrong shortcut), that causes the position of the line to drop!
On fresh documents its fine as usual. But everywhere in my current project, new textbox or old ones, the line is shifted below 😞
Do you have any clou? Maybe some baseline-grid stuff, i dont know and we dont use it.
Panic!
(Here the code for my positioning)
-- P1X
set X1 to horizontal offset of character 1 of selection
-- P1Y
set Y1 to baseline of first character in selection
-- P2Xoffset
set baselineSave to baseline of first character of selection
repeat with y from 1 to (count of characters in selection)
if baseline of character y of selection = baselineSave then
set CharsLineOne to CharsLineOne + 1
end if
end repeat
set X2 to end horizontal offset of character CharsLineOne of selection
-- P2Y
set Y2 to (baseline of character CharsLineOne of selection) - ((((point size of last character in line 1 of selection) * 0.35275) / 100) * 50)
Copy link to clipboard
Copied
Hi,
as seen in one of your first posts you flip the graphic line. Guess you didn't set the transform reference point by script and now changed it manually fron center to bottom ... just a suggestion
Hans-Gerd Clöaßen