Creating a color in InDesign Javascript (CC)

Hi all:

I use this code to try to create a color that can be used to fill a button:

function MakeButtonColor()

{

var TheColor;

var editable = app.activeDocument;

var MonErreur;

Try

{

TheColor = TheDocument.colors.item ("DPSButtonColor");

var ColorName = TheColor.name;

}

catch (MyError)

{

TheColor = TheDocument.colors.add ({name: "DPSButtonColor", colorSpace:ColorSpace.RGB, model:ColorModel.process,colorValue:[0,137,208]});})

}

var ButtonColor1 = TheColor;

Alert ("ButtonColor is" + ButtonColor1.name);

}

I am all that directly from the Scripting Guide with only a very few changes.

But I never see the two last executed statements.   I tried all sorts of things to make this work and it won't work.

Someone at - it ideas why this won't work and what I can do about it?

Hi JADarnell,

I just modified your code according to the directives of the Trevor mentioned lines. Try this!

MakeButtonColor()
function MakeButtonColor(){
   var TheColor;
   var TheDocument = app.activeDocument;
   var myError;
   try{
       TheColor = TheDocument.colors.itemByName("DPSButtonColor");
       var ColorName = TheColor.name;
       }
   catch(myError){
       TheColor = TheDocument.colors.add({name: "DPSButtonColor", space:ColorSpace.RGB, model:ColorModel.process,colorValue:[0,137,208]});
       }
   var ButtonColor1 = TheColor;
   alert("ButtonColor is " + ButtonColor1.name);
   }

THX,

csm_phil

Tags: InDesign

Similar Questions

  • Create the Excel using Indesign javascript file

    Hi all

    We can create csv file using indesign javascript. Is there a way to create excel file using indesign javascript?

    Thanks in advance

    Hi all

    It is a way to generate an Excel from an InDesign table by using a combination of jsx, vbs and applescript.

    Quite a long discussion on that Open with below is a better application of the suggestions here.

    // Exports SIMPLE tables to proper excel file single and double quotes in the table would have to be escaped on the Mac version
    // Does not take Unicode file names
    // with a bit of brain racking can be developed to deal with merged cells and nested tables
    // Pieced together by Trevor (wwww.creative-scripts.com coming soonish) based on the referenced sources
    // Sold AS IS https://forums.adobe.com/thread/1718021
    
    var doc = app.properties.activeDocument && app.activeDocument,
           myTable = myTable || getTable (doc);
    if (!myTable) {alert ("Take a break, needs a document with a table in it!"); exit();};
    var filePath = new File (Folder.temp + "/" + +new Date + ".xlsx"),
        osFilePath = filePath.fsName;
    if ($.os[0] === "M")  osFilePath =  osFilePath.replace(/(.)(\/)/g,"$1:").replace(/\//, "");
    
    exportTable (myTable, osFilePath);
    if (confirm ("Open new excel file")) filePath.execute(false);
     exit()
    function exportTable (myTable, filePath)
        {
            var  numberOfRows = myTable.rows.length,
                   rowNumber, columnNumber,
                   isMac = $.os[0] === "M",
                   rowContents = [],
                   setRange, openMark, closeMark;
    
            if (isMac)
                {
                    setRange = 'set value of range "A';
                    openMark = '" to {';
                    closeMark = '}';
                }
            else
                {
                    setRange = 'app.Range("A';
                    openMark = '") = Array(';
                    closeMark = ')';
                }
    
    for (var z = 0, rowNumber = 0; rowNumber < numberOfRows; rowNumber++) {
        var  numberOfColumns = myTable.rows[rowNumber].columns.length,
                toRange = GetExcelColumnName (numberOfColumns - 1),
                columnContents = [];
         for (columnNumber = 0; columnNumber < numberOfColumns; columnNumber++) {
             var cellContents = myTable.rows[rowNumber].cells.everyItem().contents;
             columnContents  = '"' + cellContents.join('", "') + '"';
         }
        rowContents[rowNumber] = setRange + ++z  + ":"  + toRange+ z + openMark  + columnContents + closeMark;
    }
    
    var tableData = rowContents.join("\n") + "\n";
    
                   if (isMac)
                        {
                            // Thanks Hans https://forums.adobe.com/message/5607799#5607799
                           var myAppleScript =
                            '''set excelRunning to isRunning("Microsoft Excel")
                               tell application "Microsoft Excel"
                               set theWorkbook to make new workbook
                               tell sheet (1) of theWorkbook'''
                               + tableData + '''
                               end tell
                               save workbook as theWorkbook filename "''' + filePath + '''"
                               close active workbook
                               if not excelRunning then tell application "Microsoft Excel" to quit
                               end tell
                               on isRunning(appName)
                                    tell application "System Events" to (name of processes) contains appName
                               end isRunning
                            ''';
                          app.doScript (myAppleScript, ScriptLanguage.APPLESCRIPT_LANGUAGE);
                        }
    
                    else
                        {
                            // Thanks Calos https://forums.adobe.com/message/5607799#5607799
                            // changed by me :-)
                             var vbscript =
                             '''Dim app
                                Set app = CreateObject("Excel.Application")
                                'take away the ' from the line below if you want to see excel do it's stuff
                                'app.visible = true
                                Dim newDoc, sheet
                                Set newDoc = app.Workbooks.Add()
                                Set sheet = newDoc.Worksheets(1)
                                '''
                                + tableData
                                + 'newDoc.SaveAs "' + filePath + '''"
                                app.Quit
                                Set newDoc = nothing
                                Set app = nothing
                              ''';
                            app.doScript (vbscript, ScriptLanguage.VISUAL_BASIC);
                        }
    
                }
    
    function GetExcelColumnName (columnNumber) {// 0 is A 25 is Z 26 is AA etc.
        // parsed from http://stackoverflow.com/questions/181596/how-to-convert-a-column-number-eg-127-into-an-excel-column-eg-aa
         var dividend = columnNumber + 1,
                columnName = "",
                modulo;
    
        while (dividend > 0)  {
            modulo = (dividend - 1) % 26;
            columnName = String.fromCharCode (65 + modulo) + columnName;
            dividend = Math.floor((dividend - modulo) / 26);
        }
        return columnName;
    }
    
    function getTable (doc) { // thanks Marc http://forums.adobe.com/message/6087322#6087322
        if (!doc) return false;
        app.findTextPreferences = null;
        app.findTextPreferences.findWhat = "\x16";
        var tables = doc.findText();
        if (tables.length) return tables[0].parentStory.tables[0];
        return false;
    };
    
  • create a color in a color group

    Hello

    I have create a color in the swatch Panel, that ok, I create a color Group (colorGroups js), ok for. But I want to create a color to color group and can't find a code for that js. Maybe I need to create a color and remove within a color group after?

    Can anyone help?

    Thant much.

    Hi, try this example.

    //@target "indesign-10"
    
    var doc = app.documents.add();
    var color_group = doc.colorGroups.add({name:"CG"});
    
    var ref_swatch = doc.colors.add({
      model: ColorModel.PROCESS,
      space: ColorSpace.CMYK,
      colorValue: [100,50,0,0],
      name: "ref_swatch"}
    );
    
    var color_group_swatch = color_group.colorGroupSwatches.add(ref_swatch);
    
    $.writeln([
      color_group_swatch.swatchItemRef.colorValue,
      color_group_swatch.swatchItemRef.name
    ]);
    
    // => [[100,50,0,0],"ref_swatch"]
    

    Thank you

    mg.

  • I need to create a PDF from InDesign file that people can change in Reader or Acrobat

    I need to create a PDF from InDesign file that people can change (for example, change a name of 'John' to 'Johnny') of Adobe Reader or Adobe Acrobat. I already looked at forms, but they do not keep your police, faces and sizes colors and just do everything is selected as a form of black text, 12pt, Times New Roman.

    Can anyone here help me?

    Vincent,

    If you use Acrobat pro, build your .pdf file, and then save it as (french version):

    ... so that everyone using Acrobat Reader (or Pro, of course) can change the file .pdf (with restrictions), add comments...

    If you want to try to 'protect' your .pdf file, you can try with this (in the menu 'Preferences' (french version)):

  • create a color picker

    Hello

    How could I create a color picker inserted in a window?

    Thank you

    Fred

    Hello

    I remember this one looked more complicated than it is.

    The color picker is not a real after effects user interface, but it's an OS user interface. Is not in the SDK of EI, but in the SDK of ExtendScript (JavaScript Tools Guide)

    $.colorPicker (name)

    name: the color to be shortlisted in the dialog, as an RGB hex (0xRRGGBB) value, or - 1 for the default value of the platform.

    Return number

    defaultColor var = 0xff0000;

    var color = $.colorPicker (defaultColor);

    This is!

  • Whenever I try to create a text box indesign automatically for me and place the text in the middle.

    Whenever I try to create a text box indesign automatically for me and place the text in the middle. I can get the text moves if I play with the object ' menu ' detected block options, but it does every time. "

    Hello, welcome to the forum of InDesign. I'm a different Steve.

    What version of InDesign are you using? What operating system do you use?

    Tell us exactly how you create your text box (frame).

    The easiest way is to choose the tool of Type (T). Click and drag an image where you want to go.

    But, if you place the text to another program like Microsoft Word, click file > Place. Select the file and click Open. Drag-and-drop placement of text cursor to position it on the page.

  • Create a form in Indesign: text endangered field borders

    I hope someone can help! I create many forms in Indesign. I have a problem with the field borders when it is exported to PDF format.

    I set up the form fields in the Indesign Document as a graphic frames with a keyline in black 0.5pt, these are integrated in the main text of the page. These are then converted to text fields through the palette of "buttons and forms. Export pdf as an interactive pdf file.

    When first I look at the pdf file in Acrobat (or drive), it's fine.

    Screen Shot 2016-02-09 at 16.04.03.png

    However, after typing in some examples of data some of the border disappears. I tried the form of compensation, but they are not always visible.

    Screen Shot 2016-02-09 at 16.04.26.png

    Zoom in and out does not work. I tried to align the rule with the inside/outside/Center of the frame, it makes no difference. I tried setting the fields as floating on the page, does not work. The only solution I found is to set the border to 1pt - but it makes the very heavy form. Is there a way around this, or is 1 pt line width minimum that will work in this type of document?

    If anyone has any bright ideas that would be wonderful! Thank you.

    Unfortunately, there's really nothing you can do to control the display of the border of the form fields with borders .5pt, I see the same results as you.

  • How is - what cut you a rectangle in 2 colors with a diagonal from top to bottom?  Once I draw a diagonal with the online tool I am at loss to create 2 color split?

    How is - what cut you a rectangle in 2 colors with a diagonal from top to bottom?  Once I draw a diagonal with the online tool I am at loss to create 2 color split?

    Rosemary,

    A simple way would be to:

    (1) give the rectangle a color, then Ctrl > Cmd + C + F;

    (2) use the direct Selection tool, and then deselect (click and empty space), then click on the opposite corner to the part where you want to keep the color, then press DELETE, then change the fill color to the other.

    Or, you can ClickDrag with the line tool along the diagonal line from corner to corner (guides are your friends), select it all and Pathfinder > divide, then select live from the triangle where you want to change the color and change.

  • I often struggle to create single quotes in Indesign :-(

    I often struggle to create single quotes in Indesign, I think that it is something simple that a pressing need to set, see attached, someone can advise?

    It is not a police problem.

    Screen Shot 2016-01-09 at 6.01.43 PM.png

    Form of apostrophe in InDesign is related to the language applied to your text - and quite rightly, because each language has its own preferences for quotation mark and apostrophe characters.

    It really seems that you type English, and yet you said InDesign that this text is in French.

  • I created a 22 page Indesign document and I am wanting to place it in muse as a book. How can I do this

    I created a 22 page Indesign document and I am wanting to place it in muse as a book. How can I do to do that.

    Its a simple 22-page document. Back to Earth with a yellow area single text on each page, such as a previous/next button on the bottom. I'm hoping to put it in muse on one page, instead of having to do an absurdly long page in muse. I want the next/previous buttons to work as well.

    Inside of InDesign, I have already selected "Digital Publishing", but am stuck now on what to do.

    I use Creative Cloud 2015 for Muse and InDesign.

    Any help will be appreciated. Once the Adobe online chat is open again, I will discuss with them, but by then, I expect to get help on the forum.

    You can try to use the composition for this where containers will include content and the triggers can include thumbnail images.

    Thank you

    Sanjit

  • Import a flat .psd or laminates gives different colors in InDesign

    I have a file .psd RGB, with sRGB profile. When it is placed in InDesign, the appearance of the colors as expected.

    When in Photoshop the background layer is double clicked (to make a layer), and the file is saved without any change.

    the colors in InDesign seem dull (as if there is some sort of current CMYK simulation).

    This happens with all the other images on the page where it is placed.

    On other pages, the flat file still looks raw and RGB - ish, but as soon as a layered file is added, the colors change.

    As soon as I delete the image in layers, colors go back to high heat. Sometimes in Print, Web, and Digital Publishing mode.

    I don't want any of this! (I use InDesign to make a presentation to the screen, and I like the look of the RGB image, but who are Cinema 4 d returns, I need a few institutions overlay)

    Any ideas on that?

    Thank you!

    Screen Shot 2015-04-15 at 08.58.37.pngScreen Shot 2015-04-15 at 08.59.11.png

    Edition > merger of transparencies space > Document RGB

  • Using a LinearGradient CSS to create a color - LookUpTable

    I have a list of the values of procentual and I want the entries in a table view according to the values in this list of colors. So I want to use the colors defined by a lineargradient inside the style sheet.

    So, I need something like this:
    1. define a styleclass with a linearGradient procetual in the style sheet
    2. put an invisible Ray on the stage with a sufficient size for the required color resolution (100px for the resolution of 1%)
    3. set the styleclass according to for the line
    4. read the line colors according to values procentual to color the entries in the table - see.

    How can I implement step 4? Or is there another possibility to create a color look up table from a css gradient?

    Unfortunately, your solutions do not include the lineargradient to read starting from the style sheet.

    You already know how to do that because you posted the css for the style sheet in this thread.

    Is it possible to create a non-Visual lineshape with the styleclass gradient and use the Pixelreader to get the colors according to the pixelposition him?

    Yes. Create a component, set the values for the default size on this subject, apply your style sheet to it, place it in a scene newly created, that you place on a stage, take a snapshot of the scene and use the pixel reader to search for a pixel in the desired location in the snapshot.

  • The most effective way to create this color wheel?

    I know there are several ways to create a color circle, but in this case, there is a slight difference (ie. feature white) between the hidden images.

    I was wondering how you guys approached this creation. Thank you. Much appreciated!

    shutterstock_85920403.jpg

    The white line can be created by using the rotation tool or the transform command. In both cases, the degrees of rotation is determined by dividing the number of strokes by 360 degrees. Rotation tool, you can make a duplicate order to repeat the rotation, make sure that your rotation a copy not the original.

    Then it's you if you want the line color to match the background, or use the path search tools to cut the railways making individual piece of the wheel. This can be handy if you want to move a piece of the wheel outwards and resize it perhaps until drew attention to it.

  • Text is pixelated in the Adobe Viewer when you create an application in indesign

    I am creating an app in indesign, I set the document in folio Builder and then view it on my iphone via Adobe Viewer.  The text I typed directly in indesign appears pixelated, as well as anything else, that I placed from photoshop.  In Indesign, I have undergone high quality display, took all the layers except the text layer, even saved the image in photoshop to PDF text and always placed in indesign, pixelated.

    Help please.

    What folio format you used in Panel of Folio Builder? What version of folio you used in Panel of Folio Builder? Make sure that the folio version is 25 or later version and PDF format for best results.

    What folio size you did it? If you read on an iPhone 4 or 5 make sure your folio size is the size in pixels to the right of the screen high resolution (960 x 640, given that we don't support iPhone 5 directly yet).

    Neil

  • InDesign Javascript *.pdf in counter

    Hi all

    I want to ask you if there is a way to count the pdf files in the directory via Indesign Javascript. Thanks for the tips.

    GetFiles allows you to gather all your PDF documents (with "*.") PDF' as argument). Then check how long the resulting table is.

Maybe you are looking for