If you taget 'an' item in a document, it depends on the order of creation. No need to do that, though, as you can *specifically* first target a page and then any item on it. But in the case of multiple items per page, you still have to have *something* to go on. Position, for example, or color, or label, or contents. You need to interrogate all likely objects for the attribute of choice before you can know for sure you got the one you wanted.
As for you XML question: is this Visual Basic? If it is (next time you'd want to mention that), it's very easy. VB starts counting its objects at index 1, and so XML item #1 is the item called <code>. Since this is the root object, there are no other elements in the same hierarchy; all of the others are descendants ('child nodes') of that first node.
Thank you so much for your reply, although I am apparently still missing something. And yes I am using VB.
So in the case of specifically first targeting a page, then an item, How do I interrogate the likely objects on the page? If there is a heirarchy, then I would think that I would be able to get to the first textframe created on a page by using its index value like so: myInDesign.Pages.Item(1), and the second frame create with this: myInDesign.Pages.Item(2). Or when I create a textframe in my script, do I need to specifically give it a tag in order to target it?
On the XML side, so if index 1 is <code>, what is the index of <part_number>, or am I completely wrong in how I am thinking about that. I know I should be able to use XPath and the glue code somehow, but I cannot find any examples of how to do it or what it is supposed to look like. Is there a way to use an xpath with a something like myTextFrame.PlaceXML?
Update: So jongware, I just came across your Object Model page. I think it will be extremely useful after I get some understanding, but right now it is just confusing me more. So using that as guide, If I wanted to grab one "device" node and put it into a text frame, could I use something like this: myDocument.XMLElements.Item(1) item("device") This obviously isn't correct since I keep getting errors. Can you give me an example of how this should look?
The first XMLElement -- the root -- contains all other elements as its children, like this:
and each of them may contain items of its own:
Jongware - that was extremly helpful and exactly what I needed for the XML. I was able to write out nodes in newly created pages and textframes, so thank you very much.
Would it be possible to also give me a few examples for my first question, regarding pages and text frames. If it is similar to the XML I am assuming it would be something like this...
myInDesign.Pages.Item(1).TextFrame.Item(1) - target first frame created on first page
myInDesign.Pages.Item(1).TextFrame.Item(2) - target second frame created on first page
myInDesign.Pages.Item(2).TextFrame.Item(1) - target first frame created on second page
If the above is not correct, then I guess i am still not clear of what "Item" is refering to. So to go back to my original post...
Does "Item" in myInDesign.Documents.Item(1) refer to a page in the document, or the document itself?
Does "Item" myInDesign.Pages.Item(1) refer to a page, or a textframe on the page?
Update: ok I think I answered this after playing around with things today. So I think the short answer is that ITEM refers to whatever preceeds it, so myInDesign.Pages.Item(1) refers to pages, and TextFrame.Item(1) refers to textframes.
I still have to figure out how it orders things though. I tried creating two frames on a page then replacing the content in the second one I created with TextFrames.Item(2), but it replace the content in the first one I created instead.
1 person found this helpful
You are correct in both your update remarks. "Item" is used on a collection of (uh) items to get a handle to a single one. (Your textframes example is probably reading "myInDesign.Pages.Item(1).TextFrames.Item(1)" in your code, plural, because otherwise it will not work.)
You cannot reliably use indexing items "directly"! You cannot expect, in general, that if you have 2 text frames on a page, Item(1) is the top one and Item(2) the bottom one; or, Item(1) is the first one created and Item(2) the second one. (Usually it is, but InDesign may move the indices around at will.)
If you have two text frames and you want to change the contents in one of them, you need to justify your choice. That is, if one of the text frames has a solid border of 1 pt wide, and the other one has a border of 2 pts wide, then you can decide "I want to change the one that has a 1 pt border". To do so you would examine the text frames on your page (bogus VB follows, since I don't "do" VB):
If myInDesign.Pages.Item(1).StrokeWeight = 1 Then
myInDesign.Pages.Item(1).Contents = "Hello World"
(There are more elegant ways to do this; it depends on what you attempt to do, how many text frames there may be, etc. etc.)
Thank you again, I really appreciate the time you have given me.
That definitely gives me a direction to go in and things to try.