• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Guides and there index

Engaged ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

I am trying to move guides around and i am running into several obstacles.

So first when you add a guide to the document it makes that guide [0] and changes all the indexes for all the guides.

Second if you change the location of a guide it also change the index of that guide.

I tried putting labels on the guides but ran into the problem of accessing them with pageItems.item. I couldn't do anything with the object

So how in the heck can I index these guides?

TOPICS
Scripting

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jun 27, 2019 Jun 27, 2019

Hi bagonterman,

As most InDesign DOM elements Guides have unique IDs (accessed from the id property.) That's the way you identify and recover them. Store the id number somewhere and use myDoc.guides.itemByID(<number>) to access the object.

By contrast, the index property is not stable because it reflects—at least in principle—the z-order of the component in some dynamic stack. (The rule that determines how index properties are changed depends on the nature of the collection, but we just have to re

...

Votes

Translate

Translate
Guide ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

Hi bagonterman,

As most InDesign DOM elements Guides have unique IDs (accessed from the id property.) That's the way you identify and recover them. Store the id number somewhere and use myDoc.guides.itemByID(<number>) to access the object.

By contrast, the index property is not stable because it reflects—at least in principle—the z-order of the component in some dynamic stack. (The rule that determines how index properties are changed depends on the nature of the collection, but we just have to remember that we cannot trust them for tracking an object.)

@+

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

Do you have suggestions on where to store this data?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

So I saved a JSON object in a guide label. But now I can't parse the object because we don't have access to JSON.parse. Do you have any ideas about how to do this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

Hi Bagonterman,

Persistent data storing is a totally different question which, I think, has been already discussed in various threads.

In short, if you just need session persistence use either a #targetengine directive or $.setenv/getenv. If you need application persistent storage, use app.insertLabel. Of course you also want to stringify and re-eval data, which is addressable from either a custom function of your own, or using existing JSON tools*.

* Mine is extendscript/JSON at master · indiscripts/extendscript · GitHub

@+

Marc

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

Fantastic! I got access to the object that way. So that ID does not change?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

Yes. I think that is correct they don't change. I added multiple guides and the id did not change. It returned the same location. Thank you for your reply Marc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 28, 2019 Jun 28, 2019

Copy link to clipboard

Copied

LATEST

guide14:298,guide15:299,guide1:300,guide2:301,guide3:302,guide4:303,guide5:304,guide6:305,guide7:306,guide8:307,guide9:308,guide10:309,guide11:310,guide12:311,guide13:312

This is my label inserted into the activeDocument like so. app.activeDocument.insertLabel('guides', guideList);

Then I am parsing it like this

function getGuide(guidesLabel, index){

            var guidesList=guidesLabel.split(",")

            return app.activeDocument.guides.itemByID(Number(guidesList[index].split(":")[1]))

}

Then I move the guides like this.

getGuide(guides,2).location=mark3.geometricBounds[1] - (mark3.geometricBounds[1] - mark3.geometricBounds[3]) / 2

                getGuide(guides,3).location=mark1.geometricBounds[3]

                getGuide(guides,4).location=mark1.geometricBounds[2]

                getGuide(guides,5).location=mark1.geometricBounds[2] + .75

                getGuide(guides,6).location=mark1.geometricBounds[3] - .75

                getGuide(guides,7).location=mark1.geometricBounds[2] - .75

                getGuide(guides,8).location=mark6.geometricBounds[1]

                getGuide(guides,9).location= mark6.geometricBounds[0]

                getGuide(guides,10).location=mark6.geometricBounds[0] - .75////set guide for spine text

                getGuide(guides,11).location=mark6.geometricBounds[1] + .75

                getGuide(guides,12).location=mark6.geometricBounds[0] + .75

                getGuide(guides,13).location=mark3.geometricBounds[1]

                getGuide(guides,14).location=mark3.geometricBounds[3]

                if (spineWidth >= .75) {

                    getGuide(guides,0).location=mark7.geometricBounds[1]

                    getGuide(guides,1).location=mark7.geometricBounds[3]

                    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines