- Using 18.5 (react project)
- Simple document setup.
- 2 objects
- a textframe named “outsideTextFrame” with some text “asdf”
- a textframe named “insideTextFrame” with some text “1234” that is placed after the text. (i pasted that text frame in so its an anchored (or is it called inline) object.
I just want to programmatically move insideTextFrame object out of the outside text frame (and back with another function)
I should be able to do this in the console right?
const { app } = require("indesign");
const doc = app.activeDocument
const outsideTextFrame = doc.allPageItems[0]
const insideTextFrame = outsideTextFrame.allPageItems[0]
insideTextFrame.anchoredObjectSettings.releaseAnchoredObject()
Upon reviewing this further i think i’ve been thinking of this wrong. Basically what i want to do is pluck a text frame out of my document make some changes to it and paste it somewhere else… felt like copy/paste was the wrong way to go as i don’t have access to the object while its in the buffer but this is prob not the way to do it either.
i ended up using copy paste and insertion points.
Two problems. releaseAnchoredObject() works only on anchored frames, not on inline/above line ones. Since you start with an inline you’ll have to convert it to an anchored object:
insideTextFrame.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
Secondly, releaseAnchoredObject() doesn’t return anything. So you’ll have to get some handle on the object, release it, then find it again. You can do that by getting the object’s id before you release it, then release it, and finally get a reference to the object using the recorded id.
I marked it solved before i tried it. Still having issues.
As you can see i’m doing all of this in console to keep it simple. still having issues.
const { app } = require("indesign");
const doc = app.activeDocument
const outsideTextFrame = doc.allPageItems[0]
const insideTextFrame = outsideTextFrame.allPageItems[0]
undefined
insideTextFrame.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED
(index):1 Uncaught ReferenceError: AnchorPosition is not defined
at <anonymous>:1:59
You have to declare all enumerations that you use – forgot about that. Change the first line to
const { app, AnchorPosition } = require("indesign");
That should do it.
1 Like
Dang… That did move it out of the frame visually but its still nested in the outside frames hierarchy.
![2024-01-21_14-03-32](https://global.discourse-cdn.com/business4/uploads/xdplugins/original/2X/a/a4fc82080afff9a645bfe6d5d5f6a8f11c2d151e.jpeg)
If its not obvious i’m trying to figure out how to avoid copy pasting as i don’t want to use the the users clipboard.
i’m an idiot. a forgot my original “releaseAchoredObject()” that you were responding to. For anyone else that comes upon this… here’s my final code.
const { app, AnchorPosition } = require("indesign");
const doc = app.activeDocument
const outsideTextFrame = doc.pageItems.itemByName("outsideTextFrame");
const insideTextFrame = outsideTextFrame.allPageItems[0]
insideTextFrame.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED
insideTextFrame.anchoredObjectSettings.releaseAnchoredObject()
This also may help someone trying to move textframes that are inline… i’m sure it can be cleaner but thought i’d drop it here since i spent WAY to long on this
const { app, AnchorPosition } = require("indesign");
const doc = app.activeDocument
const outsideTextFrame = doc.textFrames.itemByName("outsideTextFrame");
const outsideTextFrame2 = doc.textFrames.itemByName("outsideTextFrame2");
const insideTextFrame = doc.textFrames.itemByName("insideTextFrame");
const insideTextFrameItem = outsideTextFrame.allPageItems[0];
const myInsertionPoint = outsideTextFrame2.insertionPoints.item(0);
// Do the things
insideTextFrameItem.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
insideTextFrameItem.anchoredObjectSettings.releaseAnchoredObject();
doc.allPageItems[0];
// Put it into another text frame
insideTextFrame.anchoredObjectSettings.insertAnchoredObject(myInsertionPoint, AnchorPosition.INLINE_POSITION);
doc.allPageItems[0];