It's generally best to avoid using the selection if you can. Also, cut() does not take a parameter, it cuts whatever is currently selected.
Anyhow, instead of:
bodtex.insertionPoints.contents = app.paste()
You should use
bodtex.insertionPoints.contents = jobbar.contents;
For the page number you might use insertionPoints[-1].contents, if you want it at the end.
You misunderstand. I want the whole jobbar textFrame to be brought into the bodtex textframe. The whole textframe is the "contents". Please see the screenshot. Thank you.
Why do you think I misunderstand you?
jobbar.contents is all of the text of jobbar. And an insertionPoint
is a position that replaces no text. So the above example will
copy all of the text from jobbar and place at the beginning of
Did you try it?
What happened, if it did not work right?
Not just the words 'jobbar', but also the textframe (rectangle) around the words 'jobbar' should be included as well. The way you told me only works for the words, and I can copy that, but I failed with the fextframe(rectanglet). I hope it's clear this time. I am talking about an Object all the time I want to put it into a textframe.
Ah, you wish to create an Anchored Object (or an Inline Object).
See the instructions on p.89 of the CS5 Scripting Guide.
You'll need to create a new frame with bodtex.insertionPoints.textFrames.add() and then manipulate the properties. You may or may not have some success with the .properties property.
I see why you wanted to use the selection. It's still wrong, but it may be easier.
app.select(jobbar); app.cut(); app.select(bodtex.insertionPoints); app.paste();
But good scripts don't modify the selection. That should be reserved for interactive work.
Yeah, you got it this time.
I just can't come up with the "app.select(bodtex.insertionPoints);" . That's what I wanted. I need more practice.
Thank you so much.
Just wondering why a script should not modify the selection. I have scripts that run against text that is pasted into text frames from emails or other sources. The structure of the text is always the same, for example, a baseball box score. As the script moves through the box score, it assigns each line to a variable, does some cleanup, writes the variable back to that portion of the selection, applies a paragraph style and moves on. Is that a bad practice?
1 person found this helpful
Well, it means that someone can't select something, run your script, and then use their old selection. Sometimes that can be a big pain in the neck.
It also means that you cannot take two scripts that both make use of the selection and combine them together, one inside the other. Because the innermost one will trash the selection used by the outermost one.
I think, also, performance is usually slower.
Of course, if the script needs a way to interact with the user, the selection is perfectly reasonable. Such as script that turns all selected rectangles into daisies.
If your script is manipulating text, it's generally better that it be written to use texts and insertionPoints and words and lines and paragraphs.
On the other hand, it's not going likely to break suddenly just because you are using the selection, so it's probably not worth your effort to go rewrite all those scripts. But when you're starting from scratch, if you can, avoiding the selection is best.
Also, scripts that use the selection will not work under InDesign Server. That's not a consideration for most of us, but good to keep in mind.