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

Avoid overlap anchor object

Guest
Jan 03, 2017 Jan 03, 2017

Copy link to clipboard

Copied

we'd like to fix a validation in Script to identify the anchored objects which are overlapping while running the script, The below code is working for most of the cases but if i have more than five query in a para its not working. could anyone advise on this?

var myDoc = app.activeDocument;

myDoc.preflightOptions.preflightOff = true;

myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

myDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

myDoc.zeroPoint = [0,0];

var myAllNotesArray = myDoc.stories.everyItem().notes.everyItem().getElements(), myNotesBasealign , myPage, myNotes , myNotetextframe = []; 

var pageLeft = myDoc.pages[0].marginPreferences.right - 9;

var pageRight = myDoc.pages[0].marginPreferences.left - 9;

try{if (myDoc.paragraphStyles.item('AuthorQueries') == null) { var AuthorQueries = myDoc .paragraphStyles.add({name:'AuthorQueries', appliedFont:"Times LT Std", pointSize:6, leading:7});}} catch (e){    }

    authorQueryPlacement()

    checkstackOrder()

    spineRelative()

    avoidOversetspineRelative()

    function checkstackOrder()

    {

        if (myNotetextframe != null)

        {

            for (var i =0;i<myNotetextframe.length;i++)

            {

               for (var j =i+1;j<myNotetextframe.length;j++)

                    {         

                        if (touches(myNotetextframe, myNotetextframe) ==  true)

                        {

                        myNotetextframe.anchoredObjectSettings.spineRelative=false;

                        }

                    }            

                }

        }

       

     } // fn close

    function spineRelative()

    {

        if (myNotetextframe != null)

        {

            for (var i =0;i<myNotetextframe.length;i++)

            {            

                if (myNotetextframe.anchoredObjectSettings.spineRelative==false)

                {

                    for (var j =i+1;j<myNotetextframe.length;j++)

                    {

                        if (touches(myNotetextframe, myNotetextframe) ==  true)

                        {          

                                if (myNotetextframe.geometricBounds[2]  > myNotetextframe.geometricBounds[0]  )

                                {

                                        var diff = myNotetextframe.geometricBounds[2] - myNotetextframe.geometricBounds[0]                                        

                                        mydiff = (myNotetextframe.anchoredObjectSettings.anchorYoffset) + ( diff +12)

                                        myNotetextframe.anchoredObjectSettings.anchorYoffset = mydiff;

                                 }

                                break;

                         }                           

                     }  

                 }

             }

        }

     } // fn close

function touches(bounds1, bounds2) 

if (bounds1.geometricBounds[2] < bounds2.geometricBounds[0]) return false; 

if (bounds1.geometricBounds[0] > bounds2.geometricBounds[2]) return false; 

if (bounds1.geometricBounds[1] > bounds2.geometricBounds[3]) return false; 

if (bounds1.geometricBounds[3] < bounds2.geometricBounds[1]) return false; 

  return true; 

}  

function authorQueryPlacement()

{

    for(i=0; i<myAllNotesArray.length;i++)

    { 

     if (myAllNotesArray.texts[0] != '' )

     {

           myPage = myAllNotesArray.storyOffset.insertionPoints[0].parentTextFrames[0].parentPage.name;

           myNotes = myAllNotesArray.storyOffset.insertionPoints[0].textFrames.add({geometricBounds:[0,0,pageLeft,pageLeft]});  

           myNotes.anchoredObjectSettings.anchoredPosition=AnchorPosition.anchored;

           myNotes.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;

           myNotes.anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.capheight;

           myNotes.anchoredObjectSettings.anchorXoffset=+5.5

            myAllNotesArray.texts[0].duplicate(LocationOptions.AFTER,myNotes.parentStory.texts[0].insertionPoints[0]); 

           myNotes.paragraphs[0].applyParagraphStyle(myDoc.paragraphStyles.itemByName("AuthorQueries"));

           myNotes.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;

           myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;

           myNotes.anchoredObjectSettings.spineRelative=true;

           delEndEnterMark(myNotes)

           myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.OFF;

           myNotes.fit(FitOptions.FRAME_TO_CONTENT);   

           app.select(myNotes)

           frameHeight  = app.selection[0].geometricBounds[2] -  app.selection[0].geometricBounds[0]

           myNotes.anchoredObjectSettings.anchorYoffset=+ frameHeight;

           myNotetextframe.push(myNotes);

        }

    }

}

TOPICS
Scripting

Views

627

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
Guest
Jan 03, 2017 Jan 03, 2017

Copy link to clipboard

Copied

Any idea or logic to clear the anchor overlap?

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
LEGEND ,
Jan 04, 2017 Jan 04, 2017

Copy link to clipboard

Copied

Hi,

Can you send us a test file?

(^/)

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
Guest
Jan 04, 2017 Jan 04, 2017

Copy link to clipboard

Copied

Herewith i have attached file for your reference.

On Wed, Jan 4, 2017 at 6:11 PM, Obi-wan Kenobi <forums_noreply@adobe.com>

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
Guest
Jan 04, 2017 Jan 04, 2017

Copy link to clipboard

Copied

sent

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
LEGEND ,
Jan 04, 2017 Jan 04, 2017

Copy link to clipboard

Copied

Where?

Make a dropbox or wetransfer file!

(^/)

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
Guest
Jan 04, 2017 Jan 04, 2017

Copy link to clipboard

Copied

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
Guest
Jan 06, 2017 Jan 06, 2017

Copy link to clipboard

Copied

LATEST

Any suggestion

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
Guru ,
Jan 04, 2017 Jan 04, 2017

Copy link to clipboard

Copied

Hi Kenyank

1) When you post code please use the advanced editor (link on the top right of the reply box) so you can format your code and have is semi-readable.

To format it click on the >> next to the    Syntax Highlighting > Java or JavasScript

2) A screenshot or 2 can be very usefull

If you can send a link by https://wetransfer.com/ it would be good but it look's like they've got an outage right now.

Below is Your code formatted.

Sadly formatting it will not make it work so it still won't work but at least it will be a bit more inviting for people to look at.

var myDoc = app.activeDocument;

myDoc.preflightOptions.preflightOff = true;

myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

myDoc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

myDoc.zeroPoint = [0, 0];

var myAllNotesArray = myDoc.stories.everyItem().notes.everyItem().getElements(),

    myNotesBasealign, myPage, myNotes, myNotetextframe = [];

var pageLeft = myDoc.pages[0].marginPreferences.right - 9;

var pageRight = myDoc.pages[0].marginPreferences.left - 9;

try {

    if (myDoc.paragraphStyles.item('AuthorQueries') == null) {

        var AuthorQueries = myDoc.paragraphStyles.add({

            name: 'AuthorQueries',

            appliedFont: "Times LT Std",

            pointSize: 6,

            leading: 7

        });

    }

} catch (e) {}

authorQueryPlacement()

checkstackOrder()

spineRelative()

avoidOversetspineRelative()

function checkstackOrder() {

    if (myNotetextframe != null) {

        for (var i = 0; i < myNotetextframe.length; i++) {

            for (var j = i + 1; j < myNotetextframe.length; j++) {

                if (touches(myNotetextframe, myNotetextframe) == true) {

                    myNotetextframe.anchoredObjectSettings.spineRelative = false;

                }

            }

        }

    }

} // fn close

function spineRelative() {

    if (myNotetextframe != null) {

        for (var i = 0; i < myNotetextframe.length; i++) {

            if (myNotetextframe.anchoredObjectSettings.spineRelative == false) {

                for (var j = i + 1; j < myNotetextframe.length; j++) {

                    if (touches(myNotetextframe, myNotetextframe) == true) {

                        if (myNotetextframe.geometricBounds[2] > myNotetextframe.geometricBounds[0]) {

                            var diff = myNotetextframe.geometricBounds[2] - myNotetextframe.geometricBounds[0]

                            mydiff = (myNotetextframe.anchoredObjectSettings.anchorYoffset) + (diff + 12)

                            myNotetextframe.anchoredObjectSettings.anchorYoffset = mydiff;

                        }

                        break;

                    }

                }

            }

        }

    }

} // fn close

function touches(bounds1, bounds2) {

    if (bounds1.geometricBounds[2] < bounds2.geometricBounds[0]) return false;

    if (bounds1.geometricBounds[0] > bounds2.geometricBounds[2]) return false;

    if (bounds1.geometricBounds[1] > bounds2.geometricBounds[3]) return false;

    if (bounds1.geometricBounds[3] < bounds2.geometricBounds[1]) return false;

    return true;

}

function authorQueryPlacement() {

    for (i = 0; i < myAllNotesArray.length; i++) {

        if (myAllNotesArray.texts[0] != '') {

            myPage = myAllNotesArray.storyOffset.insertionPoints[0].parentTextFrames[0].parentPage.name;

            myNotes = myAllNotesArray.storyOffset.insertionPoints[0].textFrames.add({

                geometricBounds: [0, 0, pageLeft, pageLeft]

            });

            myNotes.anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored;

            myNotes.anchoredObjectSettings.horizontalReferencePoint = AnchoredRelativeTo.TEXT_FRAME;

            myNotes.anchoredObjectSettings.verticalReferencePoint = VerticallyRelativeTo.capheight;

            myNotes.anchoredObjectSettings.anchorXoffset = +5.5

            myAllNotesArray.texts[0].duplicate(LocationOptions.AFTER, myNotes.parentStory.texts[0].insertionPoints[0]);

            myNotes.paragraphs[0].applyParagraphStyle(myDoc.paragraphStyles.itemByName("AuthorQueries "));

            myNotes.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;

            myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;

            myNotes.anchoredObjectSettings.spineRelative = true;

            delEndEnterMark(myNotes)

            myNotes.textFramePreferences.autoSizingType = AutoSizingTypeEnum.OFF;

            myNotes.fit(FitOptions.FRAME_TO_CONTENT);

            app.select(myNotes)

            frameHeight = app.selection[0].geometricBounds[2] - app.selection[0].geometricBounds[0]

            myNotes.anchoredObjectSettings.anchorYoffset = +frameHeight;

            myNotetextframe.push(myNotes);

        }

    }

}

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