Gibt es eine Möglichkeit ein Absatzformat in der Palette anzuwählen per Script?
Ich habe mir aus verschiedenen Quellen ein JavaScript zusammmengestellt um beliebige InDesign-Dokumente mit Bildunterschriften mit einem festgelegten Standard vollautomatisch zu versehen.
Es wird eine neue Ebene angelegt, diese wird ausgewählt und es wird ein Absatzformat angelegt.
Aber beim erstellen der Bildnamen wählt InDesign immer das "Default"-Absatzformat.
Wie gebe ich an das bei "add a text frame...“ das Absatzformat Bildnamen benutzt wird?
Ich bin Anfänger in diesen Dingen.
Das Script folgt hier:
var curDoc = app.activeDocument;
var tgt = app.activeDocument.allGraphics;
// prüft, ob die Ebene 'Beschriftung' da ist, falls nicht, wird sie angelegt
if (!curDoc.layers.itemByName("Beschriftungen").isValid) {
var lay = curDoc.layers.add({name: "Beschriftungen", layerColor: UIColors.MAGENTA});
// die Ebene nach oben verschieben
lay.move(LocationOptions.BEFORE, curDoc.layers[0]);
}
// prüft, ob das Absatzformat 'Bildnamen' da ist, falls nicht, wird es angelegt
if (!curDoc.paragraphStyles.itemByName("Bildnamen").isValid) {
NewParaStyle = curDoc.paragraphStyles.add();
with ( NewParaStyle ) { name= "Bildnamen";
appliedFont = app.fonts.item("Rotis Sans Serif Pro Cyrillic");
fontStyle = "ExtraBold";
pointSize = 7.0;
leading = "6.5";
fillColor = "C=15 M=100 Y=100 K=0";
tracking = 0;
horizontalScale = 60;
};
}
// TextFrame add ([layer: Layer][, at: LocationOptions=LocationOptions.UNKNOWN][, reference: varies][, withProperties: Object])
var myDocument = app.documents.item (0);
// var mypage = myDocument.pages.item (0);
var myTextFrame = myDocument.textFrames.add();
myTextFrame.contents = "Dies ist ein Beispieltext.";
// TextBox add (layer: Beschriftungen, at: LocationOptions=LocationOptions.UNKNOWN, withProperties: applyParagraphStyle(Bildnamen))
// void applyParagraphStyle (Bildnamen)
// applyParagraphStyle(Bildnamen)
for(var i=0;i<tgt.length;i++){
//Narrow the scope to all graphics on pages only:
if(tgt.parentPage != null){
//What to do with graphics, that are pasted directly from none-InDesign files:
//the caption will read "Undefined"
try{
var myName = tgt.itemLink.name;
}catch(e){var myName = "Undefined"};
//targets the page of the graphic:
var myPage = tgt.parentPage;
//adds a text frame to the page of the graphic:
var myCaption = myPage.textFrames.add();
myCaption.textFramePreferences.verticalJustification = VerticalJustification.TOP_ALIGN;
// myCaption.textPreferences.appliedParagraphStyle = "Bildnamen";
myCaption.contents = myName;
myCaption.paragraphs[0].justification = Justification.CENTER_ALIGN;
//Why visible bounds and not geometric bounds?
var bnds = tgt.parent.visibleBounds;
myCaption.visibleBounds = [bnds[2]+12, bnds[1], bnds[2]+0.1, bnds[3]];
myCaption.fit(FitOptions.FRAME_TO_CONTENT);
};
};