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

CS3 to CC script conversion

New Here ,
Nov 23, 2017 Nov 23, 2017

Hi

I have been trying to convert an old cs3 script to CC with no luck. The script finds all the phone numbers in a document and changes the space between the number blocks from normal apces to be non breaking spaces. This is the original script. I have tried to convert it in CC but just ended up making a mess. Any help?

    var random = Math.random();

    var lstrNumber = parseInt((1000 - 1 + 1) * random + 1);

    app.activeDocument.characterStyles.add({name:"NonBreakingSpace_" + lstrNumber});

    app.findPreferences = null;

    app.changePreferences = null;

    app.findPreferences.findText = "^9 ^9";

    app.changePreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("NonBreakingSpace_" + lstrNumber);

    var aStyle = app.activeDocument.characterStyles.item("NonBreakingSpace_" + lstrNumber);

    var lobjFoundItems = app.activeDocument.search("^9 ^9",false, false, undefined, {},{appliedCharacterStyle:aStyle});

   

    if( lobjFoundItems != null )

    {

            var lstrMessage = "Occurances found: " + lobjFoundItems.length;                     

           

    }

    app.findPreferences = null;

    app.changePreferences = null;

    app.findPreferences.findText = " ";   

   

     app.findPreferences.appliedCharacterStyle = aStyle;

   

     app.changePreferences.changeText = "^s";

       

     var lobjReplacedItems = app.activeDocument.search(app.findPreferences.findText, false, false, app.changePreferences.changeText);

       

     app.activeDocument.characterStyles.item("NonBreakingSpace_" + lstrNumber).remove();

    lstrMessage = lstrMessage +  " Occurances changed: " + lobjReplacedItems.length;

    alert(lstrMessage);

TOPICS
Scripting
500
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
Engaged ,
Nov 29, 2017 Nov 29, 2017

Hi jingo,

there is no more "search" on the document. This can now be done with findTextPreferences:

var random = Math.random();

var lstrNumber = parseInt((1000 - 1 + 1) * random + 1);

app.activeDocument.characterStyles.add({name:"NonBreakingSpace_" + lstrNumber});

app.findTextPreferences = NothingEnum.nothing;

app.changeTextPreferences = NothingEnum.nothing;

app.changeTextPreferences.appliedCharacterStyle = app.activeDocument.characterStyles.item("NonBreakingSpace_" + lstrNumber);

var aStyle = app.activeDocument.characterStyles.item("NonBreakingSpace_" + lstrNumber);

app.findTextPreferences.findWhat = "^9 ^9";

app.changeTextPreferences.appliedCharacterStyle = aStyle;

app.activeDocument.changeText();

Thanks

Stefan

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
Community Expert ,
Nov 29, 2017 Nov 29, 2017
LATEST

The .search() function is pre-CS3. If that script worked in CS3, it was versioned. To get it to work in CC, (re)set the versioning, using

app.scriptPreferences.version = . . .

Not sure what the version string for CS2 is.

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