🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #9605

Re: Release anchored objects of a story

#9605
From: Martin Fischer*
Date: Fri, 21 Jul 2006 23:13
77 lines
3542 bytes
Dave and Ole,

I have tested your approaches and have got different output.

Here is the example code with Daves apporach:

 
// releaseAnchored_Dave.jsx

Object.prototype.releaseAnchored = function()  
{ 
	if (this.parent.constructor.name != "Character") throw "Object is neither anchored nor inline" 
	this.select(SelectionOptions.replaceWith); 
	this.parent.parentStory.recompose(); 
	var myBounds = this.geometricBounds; 
	app.cut(); 
	app.paste(); 
	var newBounds = app.selection[0].geometricBounds; 
	app.selection[0].move(undefined,[myBounds[1] - newBounds[1], myBounds[0] - newBounds[0]]); 
	return app.selection[0] 
}

var myObjects = app.selection[0].parentStory.pageItems; 
//var myObjects = app.selection[0].parentStory.allPageItems;

for (var oneObject = myObjects.length-1; oneObject >= 0; oneObject--) 
{ 
	myObjects[oneObject].releaseAnchored(); 
} 




And this is an example for Oles approach:

 
// releaseAnchored_Ole.jsx

var myObjects = app.selection[0].parentStory.allPageItems;

for (var oneObject = myObjects.length-1; oneObject >= 0; oneObject--) 
{ 
	releaseAnchored(myObjects[oneObject]); 
}

function releaseAnchored(theObject) 
{ 
	var theProps = theObject.properties; 
	var thePage = getPage(theObject).documentOffset-1; 
	theObject.remove(); 
	var theFrame = app.documents[0].pages[thePage].textFrames.add(); 
	theFrame.properties = theProps; 
}

function getPage(anObject)  
{  
	if ((anObject.constructor.name == "Page") || (anObject.constructor.name == "Spread"))   
		return anObject;   
	if ( anObject.constructor.name == "Character")   
		return getPage(anObject.parentTextFrames[0]);   
	return getPage(anObject.parent);   
} 




With Dave's approach you can decide to use (1) allPageItems or (2) pageItems whether you wish to take effect (1) to anchored objects in anchored objects of a textframe or (2) only to anchored objects (and let anchored objects of anchored object stay anchored.

With Ole's approach you have to pay attention to the anchored objects in anchored objects. If you only use pageItems you risk to loose anchored objects in anchored objects. But using allPageItems you can release nested objects too.

Although there is another difference in the output of Dave's and Ole's approach: the properties of the object of the anchored object are kept at with the properties of the object style (the appearance after running the script is the same as before).
But with Ole's approach I could watch a displacement: Vertical justification of the object style is align top. But after running the script, vertical justification of the text frame has been align top.

Maybe one has to apply the applied object style once more to clear the overrides. But where do they come from?

Thanks to both, Dave and Ole
Martin
Technical Details
Message-ID: <3bc0fe9c.12@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news1.google.com!news.germany.com!multikabel.net!feed20.multikabel.net!news2.euro.net!syros.belnet.be!news.belnet.be!news.stben.net!webcrossing
References: <3bc0fe9c.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,26971fcf4ed8261a
X-Google-Attributes: gidf939a,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Martin Fischer*" <martin.fischer@online.de>
Newsgroups: adobe.scripting.indesign
Subject: Re: Release anchored objects of a story
Message-ID: <3bc0fe9c.12@webcrossing.la2eafNXanI>
Date: Fri, 21 Jul 2006 16:13:49 -0700
References: <3bc0fe9c.-1@webcrossing.la2eafNXanI>
Lines: 88
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news1.google.com!news.germany.com!multikabel.net!feed20.multikabel.net!news2.euro.net!syros.belnet.be!news.belnet.be!news.stben.net!webcrossing