Skip to main content
Mac_06
Inspiring
January 14, 2010
Answered

[JS][CS3]how to get refrence for source file

  • January 14, 2010
  • 1 reply
  • 1022 views

Hi All

I am new and learning javascript Gradually Could any one help on this as i do have a code for load style but don't know how to get refrence for "source file" and "targetDoc"

targetDoc.importStyles(charImport, sourceFile, clashPolicy);
targetDoc.importStyles(paraImport, sourceFile, clashPolicy);

Can any one figure it out

Many Thanks

This topic has been closed for replies.
Correct answer interesting_Flower157F

I'm not sure what you are trying to achieve, could you please elaborate?

Do you want to load all the styles from one document into all 100 documents, or do you want all the styles from the 100 documents into 1 document or what is the goal?

The following will let you choose a folder of files, open each of the files in it and import the styles from source document. It is not a complete script, make sure to test and modify before running on anything else than test files :-)

var MyFolderWithFiles = Folder.selectDialog ("Choose a folder");
var sourceFile = File.openDialog("Choose the styles source");

var myFiles = MyFolderWithFiles.getFiles("*.indd");

for(i = 0; i < myFiles.length; i++) {
    theFile = myFiles;
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
    var targetDoc = app.open(theFile, true);
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
    targetDoc.importStyles(ImportFormat.CHARACTER_STYLES_FORMAT, sourceFile, GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    targetDoc.importStyles(ImportFormat.PARAGRAPH_STYLES_FORMAT, sourceFile, GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    targetDoc.close(SaveOptions.YES);
}

--

Thomas B. Nielsen

http://www.lund-co.dk

1 reply

interesting_Flower157F
Inspiring
January 14, 2010

Untested, but should get you going:

var targetDoc = app.activeDocument; // the current active document
var myFile = File.openDialog("Choose a File"); // a file from the file system

targetDoc.importStyles(charImport, sourceFile, clashPolicy);
targetDoc.importStyles(paraImport, sourceFile, clashPolicy);

--

Thomas B. Nielsen

http://www.lund-co.dk

Mac_06
Mac_06Author
Inspiring
January 14, 2010

Thanks Thomas for quick responce, but could you clearify that "myFile" would be a "sourceFile" and as i have over 100 files to load the styles so how could i use this refrence as a loop.

interesting_Flower157F
Inspiring
January 14, 2010

I'm not sure what you are trying to achieve, could you please elaborate?

Do you want to load all the styles from one document into all 100 documents, or do you want all the styles from the 100 documents into 1 document or what is the goal?

The following will let you choose a folder of files, open each of the files in it and import the styles from source document. It is not a complete script, make sure to test and modify before running on anything else than test files :-)

var MyFolderWithFiles = Folder.selectDialog ("Choose a folder");
var sourceFile = File.openDialog("Choose the styles source");

var myFiles = MyFolderWithFiles.getFiles("*.indd");

for(i = 0; i < myFiles.length; i++) {
    theFile = myFiles;
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
    var targetDoc = app.open(theFile, true);
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
    targetDoc.importStyles(ImportFormat.CHARACTER_STYLES_FORMAT, sourceFile, GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    targetDoc.importStyles(ImportFormat.PARAGRAPH_STYLES_FORMAT, sourceFile, GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
    targetDoc.close(SaveOptions.YES);
}

--

Thomas B. Nielsen

http://www.lund-co.dk