hilfdirselbst.ch
Facebook Twitter gamper-media

Forenindex » Programme » Print/Bildbearbeitung » Adobe InDesign Skriptwerkstatt » Dropdown Dialog mit den UI-Farben

 



Kai Rübsamen  M  p
Beiträge: 3189

15. Okt 2009, 21:00

Beitrag #1 von 13
Bewertung:

(4966 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Hallo!

Ich würde gerne einen Dialog erstellen in dem der User die UIColors auswählen kann. Das Problem ist, das der Dialog eine stringList erwartet, meine UIColors aber lieber eine Number sein wollen.

Daher geht folgendes nicht:

Code
doc = app.activeDocument; 
myColors = [UIColors.TEAL, UIColors.ORANGE,UIColors.RED];
d = app.dialogs.add({name:"Auswählen der Ebenenfarbe"});
d.dialogColumns.add().staticTexts.add({staticLabel:"Farbe:"});

dd = d.dialogColumns.add().dropdowns.add({stringList:myColors});


Ich dachte man könnte viell. die Number in einen String umwandeln aber ein Test mit
Code
var a = String (myColors); 
a = UIColors.TEAL
a.constructor.name

ergibt immer noch Number?

> Wie muss ich das Script schreiben damit der User Teal, Orange, Red auswählen kann, intern aber mit den Angaben in myColors weitergearbeitet werden kann?

Gruß Kai
_______________________

MacPro 2x2,66 GHZ, 3 GB | 10.5.8 | CS 5 (7.0.4) u. CS 5.5 (7.5.3) u. CS6

ruebiarts.de
– Ein Blog vom Designer für Designer

Das nächste Treffen der InDesign-User Group Rhein/Main findet im August statt.
Jetzt als Mitglied anmelden, um die automatische Einladung zu erhalten!
Top

Kai Rübsamen  M  p
Beiträge: 3189

15. Okt 2009, 21:18

Beitrag #2 von 13
Beitrag ID: #411421

Bewertung:

(4960 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


So, Hans hat mir erklärt das ich zwei Listen erstellen muss:

1. die Liste die die Namen enthält die ich im Dialog auswählen lasse
2. die Liste mit der das Script weiterarbeiten kann

Demnach hab ich jetzt mal folgendes zusammengeschustert:

Code
doc = app.documents[0]; 
dialogNames = ["Türkis", "Orange", "Rot"];

d = app.dialogs.add({name:"Wähle eine Ebenenfarbe"});
// fügt eine Dialogspalte hinzu
d.dialogColumns.add().staticTexts.add({staticLabel:"Ebenenfarbe:"});

// fügt eine weitere Dialogspalte hinzu
dd = d.dialogColumns.add().dropdowns.add({stringList:dialogNames});

// zeigt die Dialogbox
myResult = d.show();

if (myResult == true){
var index = dd.selectedIndex;
d.destroy();
} else {
d.destroy();exit();
}

oldLayer = doc.activeLayer;
newLayer = doc.activeLayer.duplicate();
newLayer.name = "Neu";
colorValues = [UIColors.TEAL, UIColors.ORANGE, UIColors.RED];
newLayer.layerColor = colorValues[index];
oldLayer.visible = false;


Ist das umständlich oder macht man das so?

Gruß Kai
_______________________

MacPro 2x2,66 GHZ, 3 GB | 10.5.8 | CS 5 (7.0.4) u. CS 5.5 (7.5.3) u. CS6

ruebiarts.de
– Ein Blog vom Designer für Designer

Das nächste Treffen der InDesign-User Group Rhein/Main findet im August statt.
Jetzt als Mitglied anmelden, um die automatische Einladung zu erhalten!

als Antwort auf: [#411417]

(Dieser Beitrag wurde von Kai Rübsamen am 15. Okt 2009, 21:26 geändert)
Top

Gerald Singelmann  M  p
Beiträge: 5823

15. Okt 2009, 23:11

Beitrag #3 von 13
Beitrag ID: #411426

Bewertung:

(4933 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Der Ansatz ist genau richtig. Einige Details gefallen mir nicht.
Code
var doc = app.documents[0];  
var dialogNames = ["Türkis", "Orange", "Rot"];
var colorValues = [UIColors.TEAL, UIColors.ORANGE, UIColors.RED];

var d = app.dialogs.add({name:"Wähle eine Ebenenfarbe"});
// fügt eine Dialogspalte hinzu
d.dialogColumns.add().staticTexts.add({staticLabel:"Ebenenfarbe:"});

// fügt eine weitere Dialogspalte hinzu
var dd = d.dialogColumns.add().dropdowns.add({stringList:dialogNames});

// zeigt die Dialogbox
var myResult = d.show();

if (myResult == true){
var index = dd.selectedIndex;
d.destroy();
} else {
d.destroy();
exit();
}

var oldLayer = doc.activeLayer;
var newLayer = doc.activeLayer.duplicate();
newLayer.name = "Neu";
newLayer.layerColor = colorValues[index];
oldLayer.visible = false;


Gewöhn dir besser nicht an, Variablen ohn "var" einzuführen.
Wenn du zwei parallele Listen verwendet, deklariere sie am besten auch nebeneinander, damit klar ist, was da zusammenhängt.

Falls du keine Lust hast zu tippen, hier die volle Liste:
Code
var myColors = [UIColors.LIGHT_BLUE, UIColors.RED, UIColors.GREEN, UIColors.BLUE, UIColors.MAGENTA, UIColors.GRAY, UIColors.BLACK, UIColors.ORANGE, UIColors.DARK_GREEN, UIColors.TEAL, UIColors.TAN, UIColors.BROWN, UIColors.VIOLET, UIColors.GOLD, UIColors.DARK_BLUE, UIColors.PINK, UIColors.LAVENDER, UIColors.BRICK_RED, UIColors.OLIVE_GREEN, UIColors.PEACH, UIColors.BURGUNDY, UIColors.GRASS_GREEN, UIColors.OCHRE, UIColors.PURPLE, UIColors.LIGHT_GRAY, UIColors.CHARCOAL, UIColors.GRID_BLUE, UIColors.GRID_ORANGE, UIColors.FIESTA, UIColors.LIGHT_OLIVE, UIColors.LIPSTICK, UIColors.CUTE_TEAL, UIColors.SULPHUR, UIColors.GRID_GREEN, UIColors.WHITE]; 


Mit freundlichem Gruß
Gerald Singelmann

--------------------------
Alles rund um InDesign und Automatisierung für Profis
http://www.cuppascript.com

als Antwort auf: [#411421] Top

Kai Rübsamen  M  p
Beiträge: 3189

16. Okt 2009, 07:48

Beitrag #4 von 13
Beitrag ID: #411431

Bewertung:

(4904 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Danke für´s drübersehen und kommentieren. Das mit den Listen leuchtet mir ein.

Zitat Gewöhn dir besser nicht an, Variablen ohn "var" einzuführen.

Ohne jetzt hier eine Grundsatzdiskussion führen zu wollen:
Peter Kahrel hat mir erklärt das das Einführen von Variablen außerhalb von Funktionen mit "var" nicht notwendig ist.

Da ich noch an meinem Schreibstil feile, lasse ich seit zwei Wochen das "var" außerhalb von Funktionen sowie generell Sachen wie "myDoc", "myLayer" weg.

"myResult" habe ich verwendet weil dieses Beispiel mein erster Dialog war und es mir so doch klarer wurde.

edit: Hans hatte mir den Wink mit den zwei Listen schon vor längerer Zeit gegeben. Irgendwie hatte ich es aber auf diesem Weg bis gestern nicht hinbekommen und doch noch auf eine Lösung in einer Liste gehoffft.

Gruß Kai
_______________________

MacPro 2x2,66 GHZ, 3 GB | 10.5.8 | CS 5 (7.0.4) u. CS 5.5 (7.5.3) u. CS6

ruebiarts.de
– Ein Blog vom Designer für Designer

Das nächste Treffen der InDesign-User Group Rhein/Main findet im August statt.
Jetzt als Mitglied anmelden, um die automatische Einladung zu erhalten!

als Antwort auf: [#411426]

(Dieser Beitrag wurde von Kai Rübsamen am 16. Okt 2009, 08:06 geändert)
Top

Martin Fischer  M  p
Beiträge: 9694

16. Okt 2009, 09:25

Beitrag #5 von 13
Beitrag ID: #411449

Bewertung:

(4875 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


> Peter Kahrel hat mir erklärt, daß das Einführen von Variablen außerhalb von Funktionen
> mit "var" nicht notwendig ist.

Die Aussage von Peter überrascht mich.
Selbst wenn es nicht nötig ist, ist es so übersichtlicher.

Da halte ich es eher mit Gerald.
Wenn man var grundsätzlich verwendet, dann vergisst man es nicht, wenn's mal tatsächlich nötig ist. ;-)

Schadet's?


Martin Fischer

Skripte für InDesign im Skriptarchiv von HilfDirSelbst.ch

als Antwort auf: [#411431] Top

Gerald Singelmann  M  p
Beiträge: 5823

16. Okt 2009, 09:39

Beitrag #6 von 13
Beitrag ID: #411457

Bewertung:

(4873 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Zitat Ohne jetzt hier eine Grundsatzdiskussion führen zu wollen:

Nö, dazu sind wir auch alle nicht Informatiker genug.

Mir passier es nur sehr häufig, wenn ich eine Skizze erst mal global geschrieben habe, dass ich den Code nachträglich in eine Funktion schiebe.
Außerdem hilft es bei der Lesbarkeit, wenn ich weiß, wo eine Variable eingeführt wurde.

Aber each to his own.

Mit freundlichem Gruß
Gerald Singelmann

--------------------------
Alles rund um InDesign und Automatisierung für Profis
http://www.cuppascript.com

als Antwort auf: [#411431] Top

Kai Rübsamen  M  p
Beiträge: 3189

16. Okt 2009, 09:42

Beitrag #7 von 13
Beitrag ID: #411458

Bewertung:

(4870 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Zitat Schadet's?

Nein.

Ich habe gestern ein Script von Marc Autret mit dieser Schreibweise gesehen:
var p, pItems = app.activeDocument.allPageItems;

Das fand ich bei wenigen Variablen auch recht übersichtlich.

edit: Gero mit der Lesbarkeit hapert es in der Tat in meiner Variante oder es ist einfach nur eine Frage der Gewöhnung ...

Gruß Kai
_______________________

MacPro 2x2,66 GHZ, 3 GB | 10.5.8 | CS 5 (7.0.4) u. CS 5.5 (7.5.3) u. CS6

ruebiarts.de
– Ein Blog vom Designer für Designer

Das nächste Treffen der InDesign-User Group Rhein/Main findet im August statt.
Jetzt als Mitglied anmelden, um die automatische Einladung zu erhalten!

als Antwort auf: [#411449]

(Dieser Beitrag wurde von Kai Rübsamen am 16. Okt 2009, 09:44 geändert)
Top

Uwe Laubender p
Beiträge: 1968

16. Okt 2009, 11:01

Beitrag #8 von 13
Beitrag ID: #411466

Bewertung:

(4848 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Hallo, zusammen!
var oder nicht var, das ist hier die Frage.

Wenn ich in die JavaScript-Core-Dokumentation reinschaue, dann steht dort unter der Abteilung "delete" Folgendes:

Zitat delete

The delete operator deletes an object, an object's property, or an element at a specified index in an array.

delete y // returns false (cannot delete if declared with var)

Da ich bisher noch nicht im Zusammenhang mit Variablen mit "delete" gearbeitet habe, hier ein kleiner Test:
Code
var myDoc = app.activeDocument; 
var myContents = myDoc.textFrames[0].contents = "Text";
delete myContents;

//Ergebnis: false

Ohne var das Ganze:
Code
myContens = myDoc.textFrames[0].contents = "Text"; 

//Die Variable wird entsorgt, kann also später ohne Gefahr noch einmal neu definiert werden:
delete myContents;

//Ergebnis: true

Wir sollten das bei der Deklaration von Variablen im Hinterkopf behalten.
*****
Mit herzlichem Gruß,
Uwe Laubender

als Antwort auf: [#411458] Top

Peter Kahrel p
Beiträge: 147

16. Okt 2009, 14:04

Beitrag #9 von 13
Beitrag ID: #411526

Bewertung: ||

(4818 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


The first thing that comes to mind in these lines:

var doc = app.documents[0];
var dialogNames = ["Türkis", "Orange", "Rot"];
var colorValues = [UIColors.TEAL, UIColors.ORANGE, UIColors.RED];

is that doc, dialogNames, and coloValues are not variables, but constants. So it would seem better to decalre as such:

const doc = app.documents[0];
const dialogNames = ["Türkis", "Orange", "Rot"];
const colorValues = [UIColors.TEAL, UIColors.ORANGE, UIColors.RED];

The advantage of using const is that constants cannot be redefined, protecting the contents of the defined constants.

As to the readability of variable names, if you want to distinguish them from InDesign's properties and methods, then why use the same naming convention of space-less title case with initial lower case (as in dialogNames)? I would make sure that my variables are easily recognisable as my own. For example, for variable and function names I've been using dialog_names: underscores for spaces, no capitals. No confusion.

Regards,

Peter

als Antwort auf: [#411466] Top

Hans Haesler  M  p
Beiträge: 3882

17. Okt 2009, 10:34

Beitrag #10 von 13
Beitrag ID: #411571

Bewertung:

(4780 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Hi Peter,

with due respect, but ...

Die Deklaration als Konstante schützt nur den Array als Ganzes: Dessen Name kann nicht benutzt werden, um ihm direkt einen anderen Inhalt zuzuweisen.

Aber: Die einzelnen Elemente können verändert werden. Und mit 'push()' oder 'pop()' auch deren Anzahl. Und auf diesem Umweg ebenfalls der Inhalt.

Code
const dialogNames = ["Türkis", "Orange", "Rot"];  
alert (dialogNames[2]);
dialogNames[2] = dialogNames[2] + "e";
alert (dialogNames[2]);

const colorValues = [UIColors.TEAL, UIColors.ORANGE, UIColors.RED];
alert (colorValues[2]);
colorValues[2] = colorValues[2] + 69640;
cv3 = colorValues.pop();
alert (cv3);
alert (colorValues.length);

Damit das RED nicht in SULPHUR geändert werden kann, müssten die Werte einzeln deklariert werden:

Code
const Türkis = UIColors.TEAL; 
const Orange = UIColors.ORANGE;
const Rot = UIColors.RED;
alert (Rot);

Rot = Rot + 69640;
alert (Rot);

Best regards, Hans

als Antwort auf: [#411526] Top

Peter Kahrel p
Beiträge: 147

17. Okt 2009, 10:44

Beitrag #11 von 13
Beitrag ID: #411575

Bewertung:

(4777 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Hello Hans,

Well, I had assumed that those two arrays weren't going to change. If they are going to change, then you're quite right, they should indeed not be declared as constants.

Regards,

Peter

als Antwort auf: [#411571] Top

Hans Haesler  M  p
Beiträge: 3882

17. Okt 2009, 11:18

Beitrag #12 von 13
Beitrag ID: #411578

Bewertung:

(4766 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Hello Peter,

your assumption is correct: those arrays are not supposed to be changed.

I just wanted to demonstrate that an array, which is declared as a constant, can be redefined quite easily.

Best regards, Hans

als Antwort auf: [#411575] Top

Peter Kahrel p
Beiträge: 147

17. Okt 2009, 12:20

Beitrag #13 von 13
Beitrag ID: #411582

Bewertung:

(4758 mal gelesen)
URL zum Beitrag

Beitrag als Lesezeichen

Dropdown Dialog mit den UI-Farben


Ah -- I see what you mean now. Of course. The advantage of using const is still that (in this case) the names of the arrays cannot be accidentally used for something else. But you're right that const doesn't lock the contents of array constants in the way that it does string and number constants.

Thanks,

Peter

als Antwort auf: [#411578] Top


Forenindex » Programme » Print/Bildbearbeitung » Adobe InDesign Skriptwerkstatt » Dropdown Dialog mit den UI-Farben


^