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

CS3 to CC script conversion

New Here ,
Nov 23, 2017 Nov 23, 2017

Copy link to clipboard

Copied

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

Views

441

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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