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

creating temporary swatch

Engaged ,
Apr 28, 2017 Apr 28, 2017

Copy link to clipboard

Copied

Hello.

Refering to my post thread #2305722 I stil have a question.

After creating an array that contains color-parameters like color values and color names I want the user to l´select one of those colours via dropbox-dialog.

The selected color should be inserted directly in a colorgroup of the document. First check if the group exists, check if color allready exists.

My problem is, that the parser won´t do that because (I verified it) the color which was taken out from the array is not a color but an object! And one can´t put an object into a colorgroup obviously... How an object becomes a "real" color without adding it to the swatches before? I mean something like a "temporary color".

function createColour() {

   var n=0;

    start: while(true) {   

       

    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

   

    var colorName =[];

    for (i=0; i < colourArray.length; i++) {

    colorName.push(colourArray.name + "\r");

    }  

    //Dialogbox mit Farbauswahl erstellen

    var dlg = app.dialogs.add();

    dlg.name = "SF_Kapitelfarben für Tabellen";

    var dlgCol = dlg.dialogColumns.add();

    var sText = dlgCol.staticTexts.add();

    sText.staticLabel = "Bitte wählen Sie eine Farbe aus:";

    var dropDown = dlgCol.dropdowns.add();

    dropDown.stringList = colorName;

    var res = dlg.show();

    n++;

    if (res == false)

    continue start;

   

        myTempNewColour = colourArray[dropDown.selectedIndex];

   

    myNewColorKey = dropDown.selectedIndex;    

    break;

}

return myTempNewColour;

return myNewColorKey;

    dlg.destroy();

}

// ++++++++++ Funktion createColour() ENDE ++++++++++

function newColour() {

    // Prüfen, ob die Farbgruppe existiert

    var myTabColorGroup = myDoc.colorGroups.itemByName("SF_TAB_Farben");

   

    if(!myTabColorGroup.isValid){

        //alert("Farbgruppe ist nicht vorhanden");

        var myTabColorGroup = myDoc.colorGroups.add({name:"SF_TAB_Farben"}); 

        }

        alert(myColours.name);

        exit();

    if(myTabColorGroup.isValid){

        //alert("Farbgruppe ist vorhanden");

            var myColorToCheck = myColours.itemByName(colourArray[myNewColorKey].name); 

            

            // Wenn die Farbe nicht vorhanden ist ...

            if(!myColorToCheck.isValid){

               //Erstellt ein neues Farbfeld anhand der Eingabe und der vordefinierten Farben im colourArray

                tabellenFarbe = myColours.add(colourArray[myNewColorKey]);;

                myTabColorGroup.colorGroupSwatches.add({swatchItemRef:tabellenFarbe});

                

            // Wenn die Farbe (Eingabe) vorhanden ist ...

            if(myColorToCheck.isValid){

                //Holt sich die gewünschte Farbe aus den Dokumentenfarbpalette, anhand der Eingabe und der vordefinierten Farben im colourArray

                tabellenFarbe = myColours.itemByName(colourArray[myNewColorKey].name);      

                 //alert("Farbe ist bereits in der Farbpalette vorhanden: " + tabellenFarbe.name);

                }; 

                //alert("Die neue Farbe aus Ihrer Eingabe wurde hinzugefügt: " + colourArray[myNewColour].name);

                };

            // Einfärben :

            // 1. von jeder unterkante einer jeden Zelle

            myTable.cells.everyItem().bottomEdgeStrokeColor = tabellenFarbe;

            // 2. von jeder Oberkante einer jeden Zelle

            myTable.cells.everyItem().topEdgeStrokeColor  = tabellenFarbe;

            // 3. aller Zeichen in der erste Zeile

            myTable.rows.firstItem().cells.everyItem().characters.everyItem().fillColor = tabellenFarbe;   

        }

}

I hope my explanation of the problem is clear enough

TOPICS
Scripting

Views

255

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 ,
Apr 29, 2017 Apr 29, 2017

Copy link to clipboard

Copied

LATEST

Okay, after some time I have now come to my own solution.

function newColour() {

    // Prüfen, ob die Farbgruppe existiert

    var myTabColorGroup = myDoc.colorGroups.itemByName("SF_TAB_Farben");

    var tabellenFarbe;

   

    if(!myTabColorGroup.isValid){

        //alert("Farbgruppe ist nicht vorhanden");

        var myTabColorGroup = myDoc.colorGroups.add({name:"SF_TAB_Farben"}); 

        }

    if(myTabColorGroup.isValid){

        //alert("Farbgruppe ist vorhanden");

            var myColorToCheck = myColours.itemByName(colourArray[myNewColorKey].name); 

            // Wenn die Farbe nicht vorhanden ist ...

            switch(myColorToCheck.isValid){

                case false:

               //Erstellt ein neues Farbfeld anhand der Eingabe und der vordefinierten Farben im colourArray...

               //... und fügt sie in die Farbgruppe ein

                tabellenFarbe = myColours.add(colourArray[myNewColorKey]);

                myTabColorGroup.colorGroupSwatches.add({swatchItemRef:tabellenFarbe});

                break;

               

                // Wenn die Farbe (Eingabe) vorhanden ist ...

                case true:

               //Holt sich die gewünschte Farbe aus den Dokumentenfarbpalette, anhand der Eingabe und der vordefinierten Farben im colourArray

               tabellenFarbe = myColours.itemByName(colourArray[myNewColorKey].name);

               //Verschiebt die Farbe in die Farbgruppe

                myTabColorGroup.colorGroupSwatches.add({swatchItemRef:tabellenFarbe});

                break;

                }

            // Einfärben :

            // 1. von jeder unterkante einer jeden Zelle

            myTable.cells.everyItem().bottomEdgeStrokeColor = tabellenFarbe;

            // 2. von jeder Oberkante einer jeden Zelle

            myTable.cells.everyItem ().topEdgeStrokeColor  = tabellenFarbe;

            // 3. aller Zeichen in der erste Zeile

            myTable.rows.firstItem().cells.everyItem().characters.everyItem().fillColor = tabellenFarbe;   

        }

}

// ++++++++++ newColour() ENDE ++++++++++

These are the changes:

In line 04 I created the variable.

Up to line 15 I used switch- instead if-condition

in line 28 I moved the color to the colorgroup

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