insertTextAsContent and apply characterStyle
Hallo!
I am working on importing an XML file into InDesign CC.
After a processing with XSL, I made some scripts with Javascript.
What I want to achieve adds a label to certain elements.
for example < item type = 'phone' > + 123 456 789 < / item >
in InDesign, it should look like
Phone: + 123 456 789
My Javascript
function AddPhoneLabel() {}
myIdName = "AddPhoneLabel";
var = myLabel "phone:";
myLabel.appliedCharacterStyle = "bold";
Correspond to the elements of the ingredients.
This.XPath = "//communication[@type = 'phone']";
This.Apply = function (myElement, myRuleProcessor) {}
{with (MyElement)}
insertTextAsContent (myLabel, XMLElementPosition.ELEMENT_START);
}
Returns false;
} }
}
insertTextAsContent uses a string, but I have no idea on getting a result.
Suspicion is most appreciated!
Boris
Hi borise78101190,
Try the code below.
function AddPhoneLabel(){ var myLabel = 'Phone: '; this.name = "AddPhoneLabel"; this.xpath = "//communication[@type = 'telephone']"; this.apply = function(myElement, myRuleProcessor){ with(myElement){ var myAttribute = myElement.xmlContent; myAttribute.insertionPoints[0].contents = String(myLabel); myAttribute.words[0].appliedCharacterStyle = app.activeDocument.characterStyles.item("bold"); } return true; } }
THX,
csm_phil
Tags: InDesign
Similar Questions
-
Search for a word in "()" and apply CharacterStyle
Sorry my bad English
I need your help
I can search in a parenthesis with------((.*)------)
ex: Hello Goodbye (World), must apply to a CharacterStyle '(World)' with CharacterStyle
hello (world) bye
similar script:
var active_doc = app.activeDocument; var search_string = /\((.*)\)/ig; var text_frames = active_doc.textFrames; var italicStyle = active_doc.characterStyles["italica"]; if (text_frames.length > 0) { for (var i = 0 ; i < text_frames.length; i++) { var this_text_frame = text_frames[i]; italicStyle.applyTo(this_text_frame.textRange); if (new_string != this_text_frame.contents) { this_text_frame.contents = new_string; } } }
Thanks, sorry my bad English I speak Spanish
var frames = app.activeDocument.textFrames; for (var j = 0; j < frames.length; j++){ var text = frames[j].textRange; var italicStyle = app.activeDocument.characterStyles["italica"]; var haystack = text.contents; var needle = /[\(]([^\)]*)[\)]/gi; var match; while(match = needle.exec(haystack)){ var start = needle.lastIndex - match[0].length; var end = match[0].length; for (var i = 0; i< end; i++){ italicStyle.applyTo(text.characters[i + start]); } } }
-
Find without small caps italic and apply cstyle
Hi all
I have small capitals (nested) line with italic text (see the screenshot), I tried to apply the italic "small caps" style of characters successfully. After that I will apply the cstyle "small caps" to the text of the CAP as small, but my script works does not, can you if you please correct it.
itals var = ["italic", "Light Italic", "LightItalic', 'Italic book', 'Cursive', 'Light Condensed Italic',"Book Condensed Italic","Ultra Condensed Italic","Ultra Italic","Condensed Italic", 'ThinItalic', 'BookItalic', 'LightItalic', 'BookItalic', 'UltraItalic']
SmallCaps = var ["small capitals and old figures", "55Roman small capitals and old figures", "smallCaps"];
Fix_All_SmallCaps_Italic()
function Fix_All_SmallCaps_Italic()
{
Try
{
var myCStyle7 = app.activeDocument.characterStyles.item("15_Small_Caps_Italic").name;
}
catch (MyError)
{
var myCStyle7 = app.activeDocument.characterStyles.add ({name: "15 small caps italic", capitalization: Capitalization.SMALL_CAPS, fontStyle: "Italic" "})
}
for (i = 0; i < itals.length; i ++)
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.fontStyle = itals [i];
app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;
app.changeTextPreferences.appliedCharacterStyle = "15 small caps italic";
app.activeDocument.changeText ();
}
}
~ exit (0);
Fix_All_SmallCaps();
function Fix_All_SmallCaps()
{
Try
{
var myCStyle6 = app.activeDocument.characterStyles.item("15_Small_Caps").name;
}
catch (MyError)
{
var myCStyle6 = app.activeDocument.characterStyles.add ({name: "15 small capitals", capitalization: Capitalization.SMALL_CAPS})
}
for (sc = 0; sc < smallCaps.length; sc ++)
{
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.fontStyle = smallCaps [sc];
app.changeTextPreferences.appliedCharacterStyle = "15 small capitals;
app.activeDocument.changeText ();
}
find the attribute and apply the character style
myDoc var = app.activeDocument;
mcstyle var = app.activeDocument.characterStyles.item("15_Small_Caps_Italic").name;
app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.capitalization = Capitalization.SMALL_CAPS;
app.changeTextPreferences.appliedCharacterStyle = "15 small capitals;
var myFind = myDoc.findText ();
for (var j = 0; j < myFind.length; j ++) {}
If (. appliedCharacterStyle.name myFind [j] == mcstyle) {}
Alert (myFind [j]. Happy)
continue;
}
ElseIf (. appliedCharacterStyle.name myFind [j]! = mcstyle) {}
app.activeDocument.changeText () ;}
}
}
Hello
1. If your charStyles only has names?
2. maybe disable this line:
app.findTextPreferences.fontStyle = itals [i]
so myFind table will match smallCaps all.
Now to browse and use the switch... case loop
I mean:
//... switch (myFind[j].fontStyle) { case "Italic": case "Light Italic": case "LightItalic": case "Book Italic": case "Coursive": myFind[j].appliedCharacterStyle = myCStyle7; break; default: myFind[j].appliedCharacterStyle = myCStyle6; break; } //...
Jarek
(Changed; switch (myFind [j] .fontStyle))
-
Somewhere along the line while trying to open a PDF, Microsoft Word has been selected. Now, whenever I try to open a pdf file it takes me to Microsoft Word where, of course, it will not open. How can I cancel the directive to Microsoft Word and apply Adobe Reader instead?
You can check out the action for Portable Document Format (PDF) in tools > Options > Applications
-
How to restore the ' OK and apply "buttons to change the DPI back to original size
How to restore the ' OK and apply "buttons to change the DPI back to original size
1. you can try just pressing the entry instead of the apply/OK key. It should work normally.
2 If #1 does not work, go to safe mode and the CIO adapt them again.
How to get in Mode safe:
Shut down your computer > turn it back on and immediately and repeatedly tab key F8 until you see a black and white screen. Use the up/down arrow and select Mode safe for the benefits of others looking for answers, please mark as answer suggestion if it solves your problem. -
Hello, help?
Can someone please tell me what port should I check and apply in the properties when you use a Deskstop PC running Windows XP on a HP photosmart C4280 printer?
When I checked the ports in the properties, none have been checked
Thank you
Poacherpete wrote: Hello, help? Can someone please tell me what port should I check and apply in the properties when you use a Deskstop PC running Windows XP on a HP photosmart C4280 printer? When I checked the ports in the properties, none have been checked. Thank you
Hello Poacherpete, I would download the latest version of the software for your printer for Windows XP that's found its
It is a link that contains information on how to set up your printer in Windows XP. It is a USB cable to the printer connection
-
Shows not any change in the color of the window when a relevant theme is chosen and applied. Why?
Hi John,
Thanks for posting your question in the Microsoft Community.
I understand that your computer shows no change in the color of the window, when a relevant theme is chosen and applied. Correct me if I'm wrong.
I imagine the inconvenience that you are experiencing. I will certainly help the question of fixing.
To help you suggest several steps to solve the problem, I would appreciate if you could answer the following question:
1. What is the brand and model of the computer?
2. have you made any recent hardware or exchange of software on your computer before the show?
3. you receive an error code or message?
4. How are you trying to change the theme?
5. are you using Windows themes to change the theme or any third-party software?
Please follow the methods and mark the question below:
Method 1:
I suggest you to refer to the link below to use the System File Checker tool (SFC) to troubleshoot missing or corrupted system files in Windows:
How to use the System File Checker tool to fix the system files missing or corrupted on Windows Vista or Windows 7
http://support.Microsoft.com/kb/929833
Method 2:
Try to create a new user account and check the issue by following the steps in the link below.
Create a user account:
http://Windows.Microsoft.com/en-in/Windows7/create-a-user-account
If everything works well in the new user account, then I suggest you to transfer data and settings to the fixed aid profile is corrupted from the link below.
Fix a corrupted user profile:
http://Windows.Microsoft.com/en-us/Windows7/fix-a-corrupted-user-profile
Your response is very important for us to ensure a proper resolution. Please get back to us to help you accordingly.
In the future if you fall on any question relating to Windows, please do not hesitate to post your request here on Microsoft Community, we will be more than happy to help you.
-
How to create and apply a vc in jdev 12.2.1?
Mr President
How to create and apply a vc in jdev 12.2.1?
I did like this, but do not know what my name of vc, it's VdetViewWhereCriteria.
My name of vc is
Concerning
In the AppModule, you must select the view criteria.
Open AppModule--> Data Model--> Select the VO (VdetView1)--> press the Edit button--> shuttle view criteria
as:
-
Hello!
I upgraded to the PS 2015.5 version and not the herramineta appears "perfect edge " appears instead " select and apply mask " . In this new space I can not use any of the tools panel on the left (fast selection tool , brush, etc. ) .
What may be because the problem ??
Thanks in advanceHi axe_juan,
Selection and masking of space replaced him refine edge - more information about it here: selection and masking part of a photo. Tutorials Photoshop Adobe CC
You are looking for, or can you elaborate a bit more on what your question is?
Concerning
Pete
-
Automatic failover with Transport and apply Lag fails with ORA-16798
Hello
I configured a physical database maximum Performance, accelerated failover mode standby. I set FastStartFailoverLagLimit to 3 hours (10800 seconds).If I understand the Oracle documentation, Fast-Start failover should work with Max Performance, as long the Transport timeout is whithin the FastStartFailoverLagLimit.
So I started a few scripts, generated some loading, so I have a Transport and apply the shift of 3-4 Minutes.
Then I killed pmon to cause an automatic failover.Failover failed with ORA-16798.
I know, there is Note 846087.1 , which describes the problem, but I thought that automatic failover should work in this configuration.
Is this a bug or am I wrong?Thank you very much in advance.
Configuration Data Guard standby:
-----------------------------------------------Role: STANDBY PHYSICS
State of destination: apply
Transport delay: 3 minutes 3 seconds (calculated two seconds ago)
Apply the Lag: 3 minutes 26 seconds (calculated 0 seconds ago)
Apply the rate: 23,52 MB/s
Real-time query: OFF
Occurrence (s):
...Properties:
...
LogXptMode = "async".
DelayMins = '0'
Binding = "optional."
MaxFailure = '0'
MaxConnections = '1'
ReopenSecs = "300"
NetTimeout = "15"
RedoCompression = "DISABLE."
...State of the database:
SUCCESSFast failover configuration:
-----------------------------------------------Fast-Start Failover: ENABLED
Threshold: 180 seconds
Target: < Targetname >
Observer: < servername >
Offset limit: 10800 seconds
Primary closure: TRUE
Auto-Rétablir: TRUE
Reconnection of the observer: (none)
Substitution of the observer: FALSE...
Messages of the DG - Log:
-----------------------------------------------
FAILOVER TO < DB >
Starting failover to the < DB > database
Notifying Oracle Clusterware to disassembly for the FAILOVER database
02/02/2015-13:38:04
Error running SQL = 604, sql = [ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FI
ORA-00604: an error has occurred at the SQL level 1 recursive
ORA-00283: cool cancelled due to errors
ORA-16171: RECOVER... FINISHING not allowed away for thr 1, seq 34-37
Failed to retrieve Terminal.
Database error resource SetState (16798)
02/02/2015-13:38:08
Command FAILOVER < DB > completed with error ORA-16798The FastStartFailoverLagLimit property specifies the amount of data, in seconds, during which the standby database target can
delay on the main database on the recovery plan applied. If again applied Eve point database notes that many
seconds of the primary database redo point generation, accelerated tipping is allowed.
Errors show a gap for sequences 34-37, which is not optimal for a fast failover.
Even if FastStartFailoverLagLimit is set to 3 hours, there is too much data loss for the standby site because newspapers are not available on the backup server and the Broker cannot activate the Pb of the day before.
I recommend to to lean on increase the bandwidth network.
Concerning
-
Find Greek and applied characters for Times new roman
Dear friend,
How to find characters 'Greeks' and applied to the new Roman style - regular in the Application. Please see my screenshot for your reference.
Please suggest a friend
Thanks in advance
Try this Grep (in my humble OPINION written by Martin Fischer)
To find:
[\x{0370}-\x{03FF}\x{1F00}-\x{1FFF}]+
Replace with:
'other' your character style
Have fun
-
GREP in Indesign. Research of two characters, and apply only in a style
Hello, I turn again to this community. It is possible through the GREP to find two characters and apply single style? That is, applied in one and ignoring the other. Is there a script? Thank you.
The trick is to use the 'positive advanced search' (this is the topic Match from the drop-down icon next to GREP find what):
f(?=\()
-
What computer privileges are required to install and apply the updates for Creative Apps clouds using Windows 7?
When you work for a company that controls the software installed on your computer, it is important to know if IT supports is necessary to install and apply the updates when updates are available.
It is important to know this information before you buy.
Thank you for your support.
~ Paul Miller
admin command is required for installation or any changes made to the software from your computer.
-
Help with a script that detects the content in a cell and apply the cell style to line
Hello
I am trying to add an article to my table formatting script that is a cell with the word 'Budget' (but this can be written as ' Budget:' or ' Budget: (E) "- but without the speech marks) and apply the cell Style - SponsorCells - to all the cells of the whole line. I currently have on what it will, but it does not work:
function checkWhichTable() { // ensure the user made a selection if (app.selection.length != 1) return null; var currentTable = app.selection[0]; if (currentTable.hasOwnProperty("baseline")) { currentTable = app.selection[0].parent; } while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column) currentTable = currentTable.parent; if (!(currentTable instanceof Table)) { // No table selected return null; } return currentTable; } app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Process Table"); function checkUserSelection () { var a_table = checkWhichTable(); if (a_table == null) { if (confirm("No table selected. Do you want to process *all* tables?") == false) return; allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements(); for (aTable=0; aTable<allTables.length; aTable++) { processTable (allTables[aTable]); } } else { processTable (a_table); } } function processTable(table) { // do something here! //Set 1st Row Height table.rows[0].height = "30mm"; //Find Text in Cell and apply Cell Style to Row var myCellText=['Budget', 'Budget:', 'Budget: (E)']; var myRegEx = new RegExp("^("+myCellText.join("|")+")$"); for (i=0; i<table.cells.length; i++) { if (table.cells[i].texts[0].contents.match(myRegEx)) table.cell[i].appliedCellStyle = "SponsorCells"; } //end - do something here! }
I can get the script to apply the cell style to "SponsorCells" for each cell that contain the word 'Budget' etc, but I need cell ever on this line to have the cell style applied. I tried to re-write line 56 which applies the style to a cell, but I can't seem to make it work. Any help would be great.
Separate on this issue, I would like to have a line of code similar to the 46 line, which sets the 1st height of lines, but I would like to say "If a cell has 'A cell Style' and then applies the value height 10 mm". If someone could result as a help of bonuses, things would be great double.
Thanks in advance!
But that could be painfully slow. To speed things up, follow these steps:
var cells = table.cells.everyItem().getElements(); for (var i=0; i
It is faster, because it creates an array of cells with a call to table.cells, which is several times faster than calling table.cells. And before assigning to line 12mm height is useful to check if it is already 12 mm. checking things in InDesign and do things only when it is necessary is much more effective than simply doing things even if they are not necessary.
-
Help with a script to search for text in a table cell and apply the cell style
Hello
I build the script which Jongware wrote in his post here http://indesignsecrets.com/tackling-tables-through-scripting.php - I am trying to create a variable in which I can add a number of different parts of the text, in this case it's different parts of the United Kingdom i.e. 'London', 'East', 'Scotland' etc. I just need the script to apply the cell Style - 'District Cell' - to any cell that contains text in the variable. Here's the script, if anyone can help I would be grateful.
function checkWhichTable() { // ensure the user made a selection if (app.selection.length != 1) return null; var currentTable = app.selection[0]; if (currentTable.hasOwnProperty("baseline")) { currentTable = app.selection[0].parent; } while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column) currentTable = currentTable.parent; if (!(currentTable instanceof Table)) { // No table selected return null; } return currentTable; } app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Process Table"); function checkUserSelection () { var a_table = checkWhichTable(); if (a_table == null) { if (confirm("No table selected. Do you want to process *all* tables?") == false) return; allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements(); for (aTable=0; aTable<allTables.length; aTable++) { processTable (allTables[aTable]); } } else { processTable (a_table); } } function processTable(table) { // do something here! //Find Text in Cell and apply Cell Style var textInCell=['London', 'Scotland', 'South West']; for (i=0; i<table.cells.length; i++) { if (table.cells[i].texts[0].contents==textInCell) table.cells[i].appliedCellStyle = "District Cell"; } }
Hello
Change this feature:
function processTable(table) { //Find Text (exactly as it is) in Cell and apply Cell Style var textInCell=['London', 'Scotland', 'South West'], mFound, cFound; app.findGrepPreferences = null; app.findGrepPreferences.findWhat = "^(" + cities.join("|") + ")$"; mFound = table.findGrep(); while( cFound = mFound.pop() ) cFound.parent.appliedCellStyle = "District Cell"; }
Jarek
Maybe you are looking for
-
haven't bought an Apple TV still, when initially setting up can you allows you to select your county and languages so where ever you move, you can use it with services available on site?
-
I have a HP laptop. I hibernated it ago about 4 days after the battery was empty. Then I put away. Yesterday, I put it on the charger. I tried to turn it on and it will not activate. The cord works and the computer is powered, but it will not feed. A
-
8600 pro Plus - choice of black or colour printing
Hello I can't find the button to select colour or black printing in my print options! How I choose a color print or black? Help, please. THX and regards Ralf
-
Something wrong with the screen?
Can anyone help me solve this problem, I don't know what I did exactly. http://www.Flickr.com/photos/87313151@N06/7993866299/in/photostream
-
Problems of graphics across several Adobe products on multiple machines
Has anyone else in the last few weeks have experienced a deterioration in the quality of graphics and display in (only) Adobe products on windows computers? This includes various powerful Nvidia graphics card with CUDA acceleration on portable compu