Skip to main content
M.Hasanin
Inspiring
July 25, 2020
解決済み

Release anchored objects that have paragraph and/or Object style

  • July 25, 2020
  • 返信数 2.
  • 2109 ビュー

Dear Pros,

I Want to release anchored objects that have specific paragraph and/or Object style in all document? 

can this is be done? or shall i have script? do you know script doing this?

Best Regards

Mohammad

このトピックへの返信は締め切られました。
解決に役立った回答 brian_p_dts

Thank you very much for your reply, i tried it and no errors but not working!

//Unanchored all Anchored Objects at Once
//Check if a Document is Open
if (app.documents.length == 0) {
	alert ("No document is open.", "Caution");
	exit();
}

//Working in the Current Active Document
var myDoc = app.activeDocument;  
  
// to use to process entire document  
var myItems = myDoc.allPageItems;  

//Creating Founded Objects Array
var foundObjects = Array();  
  for(var i = 0; i < myItems.length; i++){  
  if(myItems[i].parent instanceof Character){foundObjects.push(myItems[i]);}  
}  

//Check if Anchored Objects not Found
	if ( myItems.length == 0 )
	{
		alert("No Anchored items found in this document!.", "Stop" );
		exit();
	}

//UnAnchored Process Started at Array Created
if(foundObjects.length > 0){  
   for(var i = 0; i < foundObjects.length; i++){  
    if (foundObjects[i].appliedObjectStyle == "ObjStyle") {  
    foundObjects[i].anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored;
    var AnchoredObject = foundObjects[i].anchoredObjectSettings.releaseAnchoredObject();
  }  
}
}

//Check if the Program is Done
if (AnchoredObject < 0) {
	alert ("all Objects Done.", "Stop");
	exit();
}

Sorry it should be if foundObjects[i].appliedObjectStyle.name == "ObjStyle"

 

Or, 

if (foundObjects [i].appliedObjectStyle == myDoc.objectStyles.itemByName("ObjStyle")

返信数 2

brian_p_dts
Community Expert
Community Expert
July 25, 2020

It can be done through script using the releaseAnchoredObject method from an object's anchoredObjectSettings. 

Some pseudocode: 

if (pageItem.condition is met) {

    pageItem.anchoredObjectSettings.releaseAnchoredObject();

}

M.Hasanin
M.Hasanin作成者
Inspiring
July 25, 2020

Actually i have some experience in scripting, i wrote this script in the begining of the year to release all the anchored objects in the documents but i have a little experience in how to connecting the Styles with variables, here is the code if you can help to modify it to match object style - i will be thankful :

//Unanchored all Anchored Objects at Once
//Developed By : Mohammad Ibrahim
// 11-2-2020

//Check if a Document is Open
if (app.documents.length == 0) {
alert (“No document is open.”, “Caution”);
exit();
}

//Working in the Current Active Document
var myDoc = app.activeDocument;

// to use to process entire document
var myItems = myDoc.allPageItems;
// to use to process just current page
//var myItems = app.activeWindow.activePage.allPageItems;

//Creating Founded Objects Array
var foundObjects = Array();
for(var i = 0; i < myItems.length; i++){
if(myItems[i].parent instanceof Character){foundObjects.push(myItems[i]);}
}

//Check if Anchored Objects not Found
if ( myItems.length == 0 )
{
alert(“No Anchored items found in this document!.”, “Stop” );
exit();
}

//UnAnchored Process Started at Array Created
if(foundObjects.length > 0){
for(var i = 0; i < foundObjects.length; i++){
foundObjects[i].anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored;
var AnchoredObject = foundObjects[i].anchoredObjectSettings.releaseAnchoredObject();
}
}

//Check if the Program is Done
if (AnchoredObject < 0) {
alert (“all Objects Done.”, “Stop”);
exit();
}
Mohammad Hasanin
Steve Werner
Community Expert
Community Expert
July 25, 2020

Yes, it sounds like it would need to be scripted (it's not a built-in feature). No, not being a scripter, nor ever needing this feature, I don't know if anyone has developed it.

M.Hasanin
M.Hasanin作成者
Inspiring
July 25, 2020

Thank you very much

Mohammad Hasanin