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

Find Anchored objects (reference point& position) script

Explorer ,
Mar 29, 2016 Mar 29, 2016

Copy link to clipboard

Copied

Hi all

are there anyway to find Anchored objects (reference point& position) inDesign and reverse their attributes or change them in all documents i opened but by script because sometimes when i try doing that by find and replace option files crash or replacement process doesn't get all wanted objects

ex:

i want to find Anchored objects with below attributes

1.png

and change them to:

2.png

Thanks all in advance

TOPICS
Scripting

Views

1.9K

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

Participant , Apr 04, 2016 Apr 04, 2016

Hi,

Try this code for Find and Change,

var myDocument = app.activeDocument;

app.findObjectPreferences = NothingEnum.nothing;

app.changeObjectPreferences = NothingEnum.nothing;

app.findObjectPreferences.anchoredPosition = AnchorPosition.ANCHORED;

app.findObjectPreferences.anchorPoint =  AnchorPoint.CENTER_ANCHOR;

app.findObjectPreferences.positionReferencePoint =AnchorPoint.RIGHT_CENTER_ANCHOR;

app.changeObjectPreferences.anchoredPosition = AnchorPosition.ANCHORED;

app.changeObjectPreferences.anchorPoint

...

Votes

Translate

Translate
Advisor ,
Mar 29, 2016 Mar 29, 2016

Copy link to clipboard

Copied

If it crashes by find-change, it's quite likely it will crash via scripting also.

What have you tried so far?

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 ,
Mar 29, 2016 Mar 29, 2016

Copy link to clipboard

Copied

Hi Vamitul, the F/R works for me! 

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
Explorer ,
Mar 29, 2016 Mar 29, 2016

Copy link to clipboard

Copied

unfortunately Vamitul i couldn't reach to any code do this, so i hope someone to help me badly about that and maybe script be more smoother F/R as i hope

and anyway if it crashes too i need to know the code for this finding process, it may help me on another things

Thanks

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
Community Expert ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

Vamitul wrote:

If it crashes by find-change, it's quite likely it will crash via scripting also.

What have you tried so far?

Hi Vamitul,

instead of using changeObject() we could use the slower method of inspecting anchored objects on text level.

Don't know if that will prevent a crash. Perhaps only if there is a bug with OBJECT Find/Change.

Here an example method for getting all anchored objects in all stories (but not in footnotes and tables, that would require more code) and test for some properties:

var anchoredObjectsArray = app.documents[0].stories.everyItem().texts.everyItem().pageItems.everyItem().getElements();

var anchoredObjectsArrayLength = anchoredObjectsArray.length;

for(var n=0;n<anchoredObjectsArrayLength;n++)

{

   

    var anchoredObjectSettings = anchoredObjectsArray.anchoredObjectSettings;

     if

     (

          anchoredObjectSettings.anchoredPosition == AnchorPosition.ANCHORED

          &&

          anchoredObjectSettings.anchorPoint == AnchorPoint.CENTER_ANCHOR

          &&

          anchoredObjectSettings.horizontalAlignment == HorizontalAlignment.RIGHT_ALIGN

          &&

          anchoredObjectSettings.verticalAlignment == VerticalAlignment.CENTER_ALIGN

     )

    

    {

         anchoredObjectSettings.horizontalAlignment = HorizontalAlignment.LEFT_ALIGN;

    }

};

Just a thought…

Uwe

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
Advisor ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

Hi Uwe,

In my experience, these types of crashes happen not because of the find/change method, but because indesign fails to compute/recompose a proper position for the new anchored setting. A simplified case would be when applying the new settings would cause the anchored object to leave the pasteboard. Of course that is just the most straightforward of the cases, other ones that should not cause crashes, yet they do involve textwrap settings (the new position pushes a different anchored object off the page etc), split-span columns applied to paragraphs, tables, footnotes etc.

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
Community Expert ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

Ah, well. Good points.
Especially the split-span columns cases. Using split-span columns is prone for crashes (to put it mildly).

But what amazes me is, that Muhammad was saying, that sometimes not all instances of a search can be found.

That could speak for a descrete bug with OBJECT Find/replace perhaps.

Without having access to the crashing InDesign document it's hard to recommend anything.

And if the document crashed once or many times before and was recovered, some objects could be already gone corrupt and cannot be repaired.

Let's wait until Muhammad comes back after testing the snippets.

Uwe

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
Explorer ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

Dear Laubender,


you are awesome really

Thanks  a lot for your marvelous code it really helps, but can i ask you for a small adjustment for it that i can't reach

i want it to change  from top right and center right

1.png

to top left and center left


2.png

Thanks in advance

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
Participant ,
Apr 04, 2016 Apr 04, 2016

Copy link to clipboard

Copied

Hi,

Try this code for Find and Change,

var myDocument = app.activeDocument;

app.findObjectPreferences = NothingEnum.nothing;

app.changeObjectPreferences = NothingEnum.nothing;

app.findObjectPreferences.anchoredPosition = AnchorPosition.ANCHORED;

app.findObjectPreferences.anchorPoint =  AnchorPoint.CENTER_ANCHOR;

app.findObjectPreferences.positionReferencePoint =AnchorPoint.RIGHT_CENTER_ANCHOR;

app.changeObjectPreferences.anchoredPosition = AnchorPosition.ANCHORED;

app.changeObjectPreferences.anchorPoint =  AnchorPoint.CENTER_ANCHOR;

app.changeObjectPreferences.positionReferencePoint =AnchorPoint.LEFT_CENTER_ANCHOR;

myDocument.changeObject();

app.findObjectPreferences = NothingEnum.nothing;

app.changeObjectPreferences = NothingEnum.nothing;

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
Explorer ,
Apr 05, 2016 Apr 05, 2016

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
Explorer ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

Thanks all  i have done it already now

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
Explorer ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

just one more question, is it possible to reverse the values whatever it is

if it is right  then goes left

and if it is left goes right

in case i want to flip anchored objects on file and i have many position cases ??

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
Community Expert ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

LATEST

Muhammad.eloc wrote:

 

Hi Muhammad,

I'd mark b91823603's answer #4 as the correct one.

Reasons:

1. Using that method is usually faster.

2. It will reach also anchored objects in tables and footnotes.

3. This answer was posted before my post.

Best,
Uwe

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