This content has been marked as final. Show 4 replies
The InDesign CS2 Scripting Guide and Scripting Reference PDFs are on your InDesign CS2 installation CDs.
Many things in scripting did not change between CS2 and CS3--and there are more XML examples in the CS3 version of the Guide (though you should note that CS2 does not have the XML rules feature at all). You can find the InDesign CS3 Scripting Guide: VBScript at:
(you'll need to click the Scripting Resources tab to get to the relevant page)
The Markup.vbs example script (a fragment is shown on page 119 of the Guide; you can find the full script in the associated Zip archive of scripts) shows you the general approach to marking up page items or text. The basic form is:
Rem Where "myXMLElement" is a reference to an XML element
Rem and "myText" is a reference to a text object...
Here's a more complete script (VBScript form):
Rem An InDesign CS2/CS3 VBScript
Rem Use "InDesign.Application.CS2" to target CS2
Set myInDesign = CreateObject("InDesign.Application.CS3")
Rem mySetup function creates an example document.
Set myDocument = myInDesign.Documents.Add
Rem Create some paragraph styles.
Set myBodyText = myDocument.ParagraphStyles.Add
myBodyText.Name = "BodyText"
Set myHeading = myDocument.ParagraphStyles.Add
myHeading.Name = "Heading"
myHeading.PointSize = 24
Rem Add XML elements
Set myRootXMLElement = myDocument.XMLElements.Item(1)
Set myXMLTag = myDocument.XMLTags.Add("xml_element")
Set myXMLElementA = myRootXMLElement.XMLElements.Add(myXMLTag)
Rem Create a text frame
Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add
myTextFrame.GeometricBounds = myGetBounds(myDocument,myDocument.Pages.Item(1))
myString = "This is the first paragraph in a text frame." & vbCr
myString = myString & "This is the second paragraph in a text frame." & vbCr
myString = myString & "This is the third paragraph in a text frame." & vbCr
myString = myString & "This is the fourth paragraph in a text frame." & vbCr
myTextFrame.Contents = myString
Rem Use ApplyParagraphStyle in CS3.
Rem mySnippet shows how to use the XMLElement.Markup method.
Set myDocument = myInDesign.Documents.Item(1)
Rem Have to associate the Root XML element with the story
Rem before associating child elements.
Rem Now we can associate XML elements with individual paragraphs.
Set myXMLElement = myDocument.XMLElements.Item(1).XMLElements.Item(1)
Set myText = myDocument.Pages.Item(1).TextFrames.Item(1).Paragraphs.Item(1)
Rem Utility function for getting the bounds of the "live" area
Rem (the area inside the page margins) of a page.
Function myGetBounds(myDocument, myPage)
myPageWidth = myDocument.DocumentPreferences.PageWidth
myPageHeight = myDocument.DocumentPreferences.PageHeight
Rem Page.Side is a CS3 property. In CS2, use:
Rem If myPage.DocumentOffset Mod 2 = 0 Then
If myPage.Side = idPageSideOptions.idLeftHand Then
myX2 = myPage.MarginPreferences.Left
myX1 = myPage.MarginPreferences.Right
myX1 = myPage.MarginPreferences.Left
myX2 = myPage.MarginPreferences.Right
myY1 = myPage.MarginPreferences.Top
myX2 = myPageWidth - myX2
myY2 = myPageHeight - myPage.MarginPreferences.Bottom
myGetBounds = Array(myY1, myX1, myY2, myX2)
As to style information getting lost--it probably has to do with your Tag to Style/Style to Tag mapping. The above script demonstrates that it is possible to mark up text without losing the style.
You might also consider using tag to style or style to tag mapping after pasting the text from Word.
Hope this helps!
please URGENT.......Anyone send me....
If U can pls send to my mail id:firstname.lastname@example.org
1. I use 'autotag' to map styles to tags. This works fine.
2. Then I add additional elements using the 'markup' method to identify font, italic, bold, etc. (that have been applied unrelated to styles). This works fine in most cases.
However: When my additional elements are applied to a paragraph (or Text) that already has elements applied in the same position, which should result in nested elements, the previous elements are wiped out or replaced by an empty tag after the newly inserted element.
An example: A paragraph with a style named "dropcap" that is completely italic should export like this:
<dropcap><em>My paragraph is here.</em></dropcap>
But it looks like this:
<em>My paragraph is here.</em>
Can anyone help me with this particular problem?
For the record - <br /><br />I don't think it is related - should have posted as a new topic - sorry.<br /><br />And - what happens is that I am overwriting the starting tag of the original <dropcap> element, causing the close tag to become an empty element. <br /><br />XML Elements are actually an object character \uFEFF. There is another post somewhere about this. I followed the other post's suggestion and stepped through the text to be marked up, one character at a time, until I came to a true character (not \uFEFF). Then I back stepped from the end of the string in a similar fashion. I readjusted the character range and then used markup() to create the nested tag. Final call looks something like this:<br /><br />myFinds[i].characters.itemByRange(myFirst,myLast).markup(myNewElement);<br /><br />This almost works. <br /><br />It doesn't in one case that I know of - when there are multiple XML tags within the text to be marked up. This means that you are breaking XML tagging rules - starting tag is within the first element and ends within the last element. So InDesign breaks the nesting to make the XML well formed. I'll post something new on this one when I get a chance.