Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Moving text frame contents to new document (JS, CS2)

New Here ,
Jun 23, 2008 Jun 23, 2008
I suspect that this is very simple, but I am JS amateur and I just haven't quite been able to put it together.

In the most general terms, here is what I hope to do with a script:
Copy the contents of an active text frame in a working document
Open an existing template (ie. myTemplate.indt)
Insert the copied contents into a target text frame on the newly opened template

As a bonus, it would be awesome to autoflow (adding pages as necessary) the text in the new document.

I think that I have pieces of this working, but trying to learn and understand what each step needs to be. Thank you very, very much in advance for any help.

Cheers!
-Scott
TOPICS
Scripting
768
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 24, 2008 Jun 24, 2008
Hi scott,
As you suspect, it's really simple. However, I guess that what you are really trying to get may lead to a richer way of thinking. Could you tell us more on the whole project.
Anyway,
var doc = app.activeDocument;
var mysel = String(app.selection[0].contents); //Assuming that your selection is text.
// X is a string like /c/my documents...
//If you want to be able to pick a particular template,
//you can choose to set a var to var mytemplate = File.openDialog("choose a file");
var mytemplate = app.open(File(X));
var mytemplateframe = app.documents.item(mytemplatedocname).pages[0].textFrames.add({geometricBounds:[0,0,200,200]});
mytemplateframe.label = "textframe";
mytemplateframe.contents = mysel;
It needs to be completed regarding to owerflow. And textframes dimension are empiric, you can adjust that too.
hope it helps.
Loic
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 30, 2008 Jun 30, 2008
Thank you for your response Loic.

It is an important step in what I am grying to accomplish. How would I best do this while still maintaining the formatting of the contents?

I am going to try to set aside some time to respond with a little more detail regarding precisely what I am trying to accomplish. Much appreciated ...

-Scott
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jul 01, 2008 Jul 01, 2008
Hi Scott,
try this
var mytemplate = app.open(File(X));
//X is a string for the file i.e. /c/...

var mysel = String(app.selection[0].contents);
//Assuming that your selection is text.
app.copy();
app.activeDocument=mytemplate;
var mytemplateframe = doc2.textFrames.add({geometricBounds:[0,0,200,200]});
mytemplateframe.insertionPoints[0].select(SelectionOptions.REPLACE_WITH);
app.paste();

However, maybe the simpliest is to copy the parent textFrame then eventually set it for position and size.
Have you ever thought about xml ? It may handle well different inputs with styles etc. Could help you.
Loic
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 01, 2008 Jul 01, 2008
Hi Scott, Loic,

Just a note--in CS3, you can do this without copy/paste, and you can retain all formatting between the two documents. We do, every now and then, make things better between releases.:-)

Thanks,

Ole
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jul 01, 2008 Jul 01, 2008
LATEST
Hi Ole,
I am glad to hear it and sure about your wish to improve the soft version after version.
However could you tell us more about the non utility of "copy/paste" for this stuff ? Do you think about the duplicate() method ? Or something I should know :-)
Thanks a lot.
Loic
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines