Thread View: adobe.scripting.indesign
12 messages
12 total messages
Started by Skempy
Fri, 02 Jan 2009 09:48
[JS CS3] Releasing Anchored Objects
Author: Skempy
Date: Fri, 02 Jan 2009 09:48
Date: Fri, 02 Jan 2009 09:48
22 lines
1323 bytes
1323 bytes
Hello,
The following script places a libray item as an anchored object...
var myDoc = app.documents[0];
var myFrame = app.documents[0].textFrames.item("myTarget");
var myInsertPoint=myFrame.parentStory.paragraphs.item(0).insertionPoints.item(0)
var myLibraryItem=app.libraries[0].assets[0]; myFrame=myLibraryItem.placeAsset(myInsertPoint);
with(myFrame[0].anchoredObjectSettings){
anchoredPosition = AnchorPosition.anchored;
anchorPoint = AnchorPoint.topLeftAnchor;
horizontalReferencePoint = AnchoredRelativeTo.anchorLocation;
horizontalAlignment = HorizontalAlignment.leftAlign;
anchorXoffset = 0;
anchorYoffset = 0;
}
How do I now release my anchored library item and then send it behind the text in the text frame "myTarget" ?
Thanks
Simon Kemp
Re: [JS CS3] Releasing Anchored Objects
Author: loic_aigon
Date: Fri, 02 Jan 2009 14:29
Date: Fri, 02 Jan 2009 14:29
7 lines
1221 bytes
1221 bytes
Hi, In the UI, it seems that you can't reorder a anchored object. It's like it's place over the text frame and there is nothing you can do about it. So, I would say that as a anchored object, no single line of code will reorder the item to be under the text frame myTarget. If you detach the anchored object, you can use the geometricBounds I guess to copy/paste and then move the object to the original position and under the textFrame myTarget. Problem is, it won't be anchored anymore. I don't know what is your final objective but you may get what you want using another approach than anchored object. Loic
Re: [JS CS3] Releasing Anchored Objects
Author: Skempy
Date: Fri, 02 Jan 2009 14:44
Date: Fri, 02 Jan 2009 14:44
11 lines
1084 bytes
1084 bytes
Loic, Thanks for the reply. I can get the Geometric Bounds of the anchored frame, duplicate it, use the Geometric Bounds to move the duplicate, send the duplicate to the back and remove the original anchored text frame. This does the job but I thought there may be a simpler way. You can "Release" the anchored frame in the UI but I can't find how to do this with javascript. I am aiming for a (vertical)gradient fill behind paragraph of text relative to the height of the paragraph. Simon
Re: [JS CS3] Releasing Anchored Objects
Author: loic_aigon
Date: Fri, 02 Jan 2009 15:29
Date: Fri, 02 Jan 2009 15:29
4 lines
848 bytes
848 bytes
That's what I suspected. You may use another approach which is converting text to table. Hence, you will have a cell that you will be able to custom (fill with gradient). This cell will behave like a anchored object. Have a look on this. Hear you soon Loic
Re: [JS CS3] Releasing Anchored Objects
Author: loic_aigon
Date: Fri, 02 Jan 2009 15:37
Date: Fri, 02 Jan 2009 15:37
1 lines
652 bytes
652 bytes
Only problem, it will be much less convenient if you edit text.
Re: [JS CS3] Releasing Anchored Objects
Author: Harbs
Date: Mon, 05 Jan 2009 11:34
Date: Mon, 05 Jan 2009 11:34
5 lines
797 bytes
797 bytes
textFrame.anchoredObjectSettings.releaseAnchoredObject () -- Harbs http://www.in-tools.com
Re: [JS CS3] Releasing Anchored Objects
Author: Dave_Saunders
Date: Mon, 05 Jan 2009 13:44
Date: Mon, 05 Jan 2009 13:44
7 lines
698 bytes
698 bytes
Harbs, Holy smoke. How long has that been hiding there!!!!! Thanks, Dave
Re: [JS CS3] Releasing Anchored Objects
Author: Skempy
Date: Mon, 05 Jan 2009 16:28
Date: Mon, 05 Jan 2009 16:28
17 lines
2297 bytes
2297 bytes
Thanks Harbs, this has made things simpler.
I have heard your name mentioned several times today in the InDesign Secrets podcast (and Dave's too).
I am almost there with the script (my scripting is clumsy but I can usually get things to work mainly with help from this forum.
My last problem is that I am re-applying geometric bounds to the released anchored object as it is still being referenced as myAnchoredFrame.
Is it possible to release ALL the anchored objects in one go? Or how do I dump the reference to myAnchoredFrame once it has been released?
var myTextFrame = app.documents[0].textFrames.item("myTarget");
var myParagraphs = myTextFrame.paragraphs
for (var i = 0; i <= myParagraphs.length-1; i++) { var nLines = myParagraphs.item(i).lines.length; var myAnchoredFrame = myTextFrame.paragraphs.item(i).insertionPoints.item(0).textFrames.add(); var myHeight = nLines*myParagraphs[i].leading*.353 myAnchoredFrame.geometricBounds = [0, 0, myHeight, (myTextFrame.geometricBounds[3]-myTextFrame.geometricBounds[1])]; myAnchoredFrame.fillColor = "Gradient"; myAnchoredFrame.gradientFillAngle = 90; myTextFrame.texts.item(0).recompose; with(myAnchoredFrame.anchoredObjectSettings){ anchoredPosition = AnchorPosition.anchored; anchorPoint = AnchorPoint.topLeftAnchor; horizontalReferencePoint = AnchoredRelativeTo.anchorLocation; horizontalAlignment = HorizontalAlignment.leftAlign; verticalReferencePoint = VerticallyRelativeTo.capheight; verticalAlignment = VerticalAlignment.topAlign; anchorXoffset = 0; anchorYoffset = -1; pinPosition = false } myAnchoredFrame.anchoredObjectSettings.releaseAnchoredObject () myAnchoredFrame.sendToBack(); }
Thanks again
Simon Kemp
Re: [JS CS3] Releasing Anchored Objects
Author: Harbs
Date: Mon, 05 Jan 2009 21:20
Date: Mon, 05 Jan 2009 21:20
16 lines
1181 bytes
1181 bytes
Hi Dave, I believe it was added in CS3. Glad to be of help! :) Simon, No you can't release all the frames at once. You need to loop through them all. What's the problem with your code. I didn't study it well, but you seem to get a new reference during each iteration of your loop. By the way, the "recompose" statement is doing nothing. You need to either write recompose(), or just take it out. It's not necessary for CS3. -- Harbs http://www.in-tools.com
Re: [JS CS3] Releasing Anchored Objects
Author: Skempy
Date: Mon, 05 Jan 2009 22:16
Date: Mon, 05 Jan 2009 22:16
21 lines
1510 bytes
1510 bytes
Harbs If I comment out the two lines myAnchoredFrame.anchoredObjectSettings.releaseAnchoredObject(); myAnchoredFrame.sendToBack(); Then gradient frames are placed correctly behind each paragraph of text within by labelled text frame. By un-commenting the two lines in order to release the anchored frames and send them behind the text the placement of the frames goes wrong. With four paragraphs the first gradient filled frame is placed correctly behind the first paragraph, the next two gradient filled frames are placed in the top lefthand corner of the page and the forth gradient filled frame is placed to the left of myTextFrame. My orginal script which makes duplicates of the anchored frames and then moves them into position works OK but I would really like to use the releaseAnchoredObject(); method. Any further help would be greatly appreciated. One last thing, is there a CS3 version of the Scripting Reference PDF? Thanks Simon.
Re: [JS CS3] Releasing Anchored Objects
Author: Harbs
Date: Tue, 06 Jan 2009 16:48
Date: Tue, 06 Jan 2009 16:48
14 lines
1153 bytes
1153 bytes
Hi Simon, Without debugging your script, I don't know off hand where things are going off the rails, but I'm always suspicious of "with" statements. You can try stepping through the script in the ESTK to see where things are going wrong. A simple way around your problem would be to build an array of your anchored frames as you go and then after creating them all you'd release them in a separate loop. -- Harbs http://www.in-tools.com
Re: [JS CS3] Releasing Anchored Objects
Author: Skempy
Date: Tue, 06 Jan 2009 17:01
Date: Tue, 06 Jan 2009 17:01
45 lines
2161 bytes
2161 bytes
Harbs
Many thanks for all your help.
Your array of anchored frames technique did the trick.
And I have learnt a few new things on the way.
The working script now looks like this...
var myTextFrame = app.documents[0].textFrames.item("myTarget");
var myParagraphs = myTextFrame.paragraphs
var myWidth = (myTextFrame.geometricBounds[3]-myTextFrame.geometricBounds[1])/2
var myAOs = new Array();
for (var i = 0; i <= myParagraphs.length-1; i++) {
var nLines = myParagraphs.item(i).lines.length;
var myHeight = nLines*myParagraphs[i].leading*.353
var myAnchoredFrame = myTextFrame.paragraphs.item(i).insertionPoints.item(0).textFrames.add();
myAnchoredFrame.geometricBounds = [0, 0, myHeight, myWidth];
with(myAnchoredFrame.anchoredObjectSettings){
anchoredPosition = AnchorPosition.anchored;
anchorPoint = AnchorPoint.topLeftAnchor;
horizontalReferencePoint = AnchoredRelativeTo.anchorLocation;
horizontalAlignment = HorizontalAlignment.leftAlign;
verticalReferencePoint = VerticallyRelativeTo.capheight;
verticalAlignment = VerticalAlignment.topAlign;
if (i%2 == 0)
{
anchorXoffset = 0
}
else
{
anchorXoffset = -myWidth
}
anchorYoffset = -1
pinPosition = false
myAOs[i] = myAnchoredFrame
}
} // Loop through paragraphs
for (var j = 0; j <=myAOs.length-1;j++){ myAOs[j].anchoredObjectSettings.releaseAnchoredObject () myAOs[j].sendToBack(); myAOs[j].fillColor = "Gradient"; myAOs[j].gradientFillAngle = 90; }
Thanks again
Simon.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads