Copy link to clipboard
Copied
Hello Friends,
I'm new in this forum and new in InDesign scripting.
I want to make a link between a textFrame on InDesign and InCopy.
I wrote this code:
// get the selected textFrame
var textFrame = app.selection[0];
// ICMA and ICML files
var assignmentFile = new File("~/Desktop/export.icma");
var incopyFile = new File("~/Desktop/export.icml");
// exporting the text to a ICML file
textFrame.texts[0].exportFile(ExportFormat.INCOPY_MARKUP, incopyFile);
// add assignments
var assignment = doc.assignments.add(assignmentFile, "Export", false, {name:"Export"});
//... ???
At this point, I don't know how to link the incopyFile with the assignmentFile
Could someone help me with this?
Does someone have a doc or tutorial about ICMA and ICML or integration between InDesign and InCopy?
Tks!
The funny thing is that I answered this question seven years ago here. Of course, I totally forgot about that and searching the forum for the assignment term, I was surprised to find my own answer.
Below is the updated code which I adjusted to make it work in the latest version: CC 2018. (Things in DOM changed a little since the original code was written). BTW it's always a good idea to mention the version you're on.
...var doc = app.activeDocument;
if (app.selection.length == 0 || app.selection[0].
Copy link to clipboard
Copied
The funny thing is that I answered this question seven years ago here. Of course, I totally forgot about that and searching the forum for the assignment term, I was surprised to find my own answer.
Below is the updated code which I adjusted to make it work in the latest version: CC 2018. (Things in DOM changed a little since the original code was written). BTW it's always a good idea to mention the version you're on.
var doc = app.activeDocument;
if (app.selection.length == 0 || app.selection[0].constructor.name != "TextFrame") exit();
var textFrame = app.selection[0];
var assignmentFile = new File("~/Desktop/Test.icma");
var incopyFile = new File("~/Desktop/Test.icml");
var assignment = doc.assignments.add(assignmentFile, undefined, false, {name: "Test"});
var unassignedContent = doc.assignments.item("Unassigned InCopy Content");
textFrame.texts[0].exportFile(ExportFormat.INCOPY_MARKUP, incopyFile);
unassignedContent.assignedStories[0].move(LocationOptions.AT_END, assignment);
assignment.update();
assignment.update();
The result
Another, guy lady -- below my post -- offers another solution (AppleScript).
He She says: "The problem with the code in ExtendScript has been solved for InDesign CC (and maybe for CS6)".
But I haven't tested his her solution.
— Kas
P.S. I just read the AppleScript and found out that it has nothing to do to the original question: it's for InCopy (not for InDesign) and it doesn't create a new assignment.
She mentions the blog: "For sample code, see my blog for June 25, 2013: www.yourscriptdoctor.com/blogs." But I can't find it, probably the date has changed.
Copy link to clipboard
Copied
Hello Friend,
Thank you for your answer, it works fine.
The problem was the name of the unassigned content item.
var unassignedContent = doc.assignments.item("Unassigned InCopy Content");
Unfortunately, my InDesign wasn’t in english. So this item was translated. =(
I was searching for her solution, but I can’t find it too.
Thanks =D
Copy link to clipboard
Copied
Unfortunately, my InDesign wasn’t in english. So this item was translated. =(
Try to use translateKeyString method:
var myTranslateKeyString = app.translateKeyString("Unassigned InCopy Content");
It translates a key string into localized form based on current application locale.
Search the forum for details. For instance, read this thread.
See also findKeyStrings method which returns the locale-independent string(s) from the internal string localization database that correspond to the specified string (in the current locale):
var myFoundKeyString = app.findKeyStrings("Unassigned InCopy Content");
Result:
$ID/UnassignedInCopy
$ID/Unassigned InCopy Content
— Kas
Copy link to clipboard
Copied
Nice!
Thanks.
It helps a lot. =D