7 Replies Latest reply on Dec 20, 2016 4:55 AM by cbishop01

    Help adjusting this LAB value Swaps Script please.

    cbishop01 Level 2

      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[l].name != "None" && swatchColors[l].name != "Registration" && swatchColors[l].name != "Paper")  
                      { 
       newSwatch = doc.colors.add ({model: swatchColors[l].model, space: swatchColors[l].space, colorValue: swatchColors[l].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[l].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