Copy link to clipboard
Copied
Hi, is possible to apply a charter and paragraph style without writing it on a text frame?
I have a for loop that add text to var and I need to map it with styles, something like this:
var myText = '';
var content = {
'one': 'lorem ipsum',
'two': 'dolor sit amet',
'three' : 'consectetur adipiscing elit'
'four' : 'Mauris ut sem id nisi malesuada',
}
for(key in content){
if(key=='one'){
myText += content[key] //and map with character style styleONE
}else if(key == 'two'){
myText += content[key] //and map with character style styleTWO
}
....etc
}
var myTextFrame = app.selection[0].insertionPoints[0];
myTextFrame = myText;
So I would to create the var string already mapped with styles and then write it to a text Frame.
Actualy I'm doing this
var myTextFrame = app.selection[0].insertionPoints[0];
myTextFrame = ' ';
var content = {
'one': 'lorem ipsum',
'two': 'dolor sit amet',
'three' : 'consectetur adipiscing elit'
'four' : 'Mauris ut sem id nisi malesuada',
}
for(key in content){
if(key=='one'){
myTextFrame.parentStory.characters.item(-1).applyCharacterStyle(stileCarGiorno,true);
myTextFrame.parentStory.insertionPoints.item(-1).contents=thisDay['giorno'];
myTextFrame += content[key]
}else if(key == 'two'){
myTextFrame += content[key] //and map with character style styleTWO
}
....etc
}
Copy link to clipboard
Copied
Moving to InDesign Scripting forum
Copy link to clipboard
Copied
Excuse me, the post was published by mistake while I was still writing it. It's incomplete but now I can't modify it.
So I repeat and correct the question.
I have a for loop that add text to var and I need to map it with styles, something like this:
var myText = '';
var content = {
'one': 'lorem ipsum',
'two': 'dolor sit amet',
'three' : 'consectetur adipiscing elit'
'four' : 'Mauris ut sem id nisi malesuada',
}
for(key in content){
if(key=='one'){
myText += content[key] //and map with character style styleONE
}else if(key == 'two'){
myText += content[key] //and map with character style styleTWO
}
....etc
}
var myTextFrame = app.selection[0].insertionPoints[0];
myTextFrame = myText;
So I would to create the var string already mapped with styles and then write it to a text Frame.
Actualy I'm doing this
var myTextFrame = app.selection[0].insertionPoints[0];
myTextFrame = ' ';
var content = {
'one': 'lorem ipsum',
'two': 'dolor sit amet',
'three' : 'consectetur adipiscing elit'
'four' : 'Mauris ut sem id nisi malesuada',
}
for(key in content){
if(key=='one'){
myTextFrame.parentStory.characters.item(-1).applyCharacterStyle(styleONE,true);
myTextFrame.parentStory.insertionPoints.item(-1).contents=content[key];
}
....etc
}
I think it would be amazing if I could map text like html or xml
<charStyle class="one">lorem ipsum</charStyle>
<charStyle class="two">dolor sit amet</charStyle>
Is it possible?