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
and change them to:
Thanks all in advance
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
...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?
Copy link to clipboard
Copied
Hi Vamitul, the F/R works for me!
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
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
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.
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
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
to top left and center left
Thanks in advance
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;
Copy link to clipboard
Copied
Thanks b91823603 too your code is helping too really
Copy link to clipboard
Copied
Thanks all i have done it already now
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 ??
Copy link to clipboard
Copied
Muhammad.eloc wrote:
Thanks b91823603 too your code is helping too really
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