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

Help adjusting this LAB value Swaps Script please.

Advocate ,
Dec 19, 2016 Dec 19, 2016

Copy link to clipboard

Copied

Hello i modified this script from Trevor to display L*a*b* values.  My question is how can i get this to only display 3 numbers after the decimal point?

Right now it displays like below.  It would be easier to read if it stopped 2 or 3 numbers after the decimal.

PANTONE 2718 C

L=56.078431372549 a=3 b=-48

    // Script by Trevor to make CMYK color Swabs http://forums.adobe.com/message/4890389#4890389

    // Altered for L*a*b* Values

    var il = app.scriptPreferences.userInteractionLevel;

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT; 

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Make Lab Swabs"); 

app.scriptPreferences.userInteractionLevel = il; 

    function main() 

    { 

        var swatchDoc, doc, swatchColors, l, newSwatch, newSwatchName, cv, ps, m, mtb, tb, ms, tf, ptf; 

        swatchDoc = app.activeDocument; 

setupDoc(); 

app.activeDocument = doc; 

        swatchColors = swatchDoc.swatches.everyItem().getElements();

        l = swatchColors.length; 

        while (l--) 

            { 

            if (swatchColors.name != "None" && swatchColors.name != "Registration" && swatchColors.name != "Paper") 

                {

newSwatch = doc.colors.add ({model: swatchColors.model, space: swatchColors.space, colorValue: swatchColors.colorValue}); 

newSwatch.space = ColorSpace.LAB;

                cv = newSwatch.colorValue; 

newSwatchName = "L="+cv[0]+ " a="+cv[1]+ " b="+cv[2]; 

newSwatch.name = (doc.swatches.itemByName(newSwatchName).isValid) ? newSwatch.name : newSwatchName; 

ps.insertionPoints[0].contents = "\r"+swatchColors.name+"\r"+newSwatch.name+"\r" 

ps.insertionPoints[0].rectangles.add({geometricBounds:[0, 0, "15mm", "45mm"], fillColor: newSwatch.name /*  appliedObjectStyle: myStyle */}); 

}; 

            } 

        ps.overflows ? addPages(tf): 0; 

        function setupDoc() 

            { 

                doc = app.documents.add({documentPreferences:{facingPages:0, pageOrientation: PageOrientation.PORTRAIT}}); 

                m = doc.pages[0].marginPreferences; 

                mtb = doc.pages[0].bounds; 

                tb = doc.pages[0].bounds; 

mtb[0]=mtb[2]-m.bottom; 

                ms = doc.masterSpreads[0].textFrames.add ({geometricBounds:mtb, textFramePreferences:{verticalJustification:VerticalJustification.CENTER_ALIGN}}); 

ms.parentStory.properties = ({digitsType: DigitsTypeOptions.ARABIC_DIGITS, hyphenation: 0, justification: Justification.CENTER_ALIGN, paragraphDirection: ParagraphDirectionOptions.LEFT_TO_RIGHT_DIRECTION, contents: SpecialCharacters.AUTO_PAGE_NUMBER}); 

                tb[0] += m.top; tb[1]+=m.left; tb[2]-=m.bottom; tb[3]-=m.right; 

                tf = doc.pages[0].textFrames.add({geometricBounds:tb}) 

                ps= tf.parentStory; 

                ps.properties = {digitsType: DigitsTypeOptions.ARABIC_DIGITS, hyphenation: 0, justification: Justification.LEFT_ALIGN, paragraphDirection: ParagraphDirectionOptions.LEFT_TO_RIGHT_DIRECTION, rightIndent: 2}; 

            } 

            function addPages(ptf) 

            { 

                np = doc.pages.add(); 

                ptf = np.textFrames.add({geometricBounds:tb, previousTextFrame: ptf}); 

                if (ps.overflows) addPages(ptf); 

            } 

    } 

Thanks in advance.

Chris

TOPICS
Scripting

Views

327

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

correct answers 1 Correct answer

Community Expert , Dec 19, 2016 Dec 19, 2016

Hi Kartik,

that doesn't work at all.

1. colorValue is an array of three numbers

2. Chris wants 3 digits after the decimal point

I would suggest rounding the numbers.

Line 22 could read:

newSwatchName =

    "L="  + Math.round(cv[0]*1000)/1000 +

    " a=" + Math.round(cv[1]*1000)/1000 +

    " b=" + Math.round(cv[2]*1000)/1000;

Regards,

Uwe

Votes

Translate

Translate
Guide ,
Dec 19, 2016 Dec 19, 2016

Copy link to clipboard

Copied

Change line 21 to

                cv = parseInt(newSwatch.colorValue);

or

                cv = Number(newSwatch.colorValue);  

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
Guide ,
Dec 19, 2016 Dec 19, 2016

Copy link to clipboard

Copied

                cv = parseFloat(newSwatch.colorValue);   

also do the same

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 ,
Dec 19, 2016 Dec 19, 2016

Copy link to clipboard

Copied

Hi Kartik,

that doesn't work at all.

1. colorValue is an array of three numbers

2. Chris wants 3 digits after the decimal point

I would suggest rounding the numbers.

Line 22 could read:

newSwatchName =

    "L="  + Math.round(cv[0]*1000)/1000 +

    " a=" + Math.round(cv[1]*1000)/1000 +

    " b=" + Math.round(cv[2]*1000)/1000;

Regards,

Uwe

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
Guide ,
Dec 20, 2016 Dec 20, 2016

Copy link to clipboard

Copied

Hi Uwe,

Thanks for the information. Learnt a new thing

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 ,
Dec 20, 2016 Dec 20, 2016

Copy link to clipboard

Copied

Inspect line 22 of the original code.

The index numbers in brackets cv[0], cv[1] and cv[2] point to an array with the value of colorValue.

Regards,
Uwe

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
Advocate ,
Dec 20, 2016 Dec 20, 2016

Copy link to clipboard

Copied

LATEST

Thank you very much.  Works perfectly

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