Skip to main content
danielg98770948
Known Participant
April 5, 2019
Answered

releaseAnchoredObject() not a function????

  • April 5, 2019
  • 2 replies
  • 1667 views

I have a document with an in-line anchored image. 

I have the following code:

myPicture.anchoredObjectSettings.releaseAnchoredObject();   //myPicture is an [object Rectangle]

I get the following error:

myPicture.anchoredObjectSettings.releaseAnchoredObject is not a function

ANy ideas why this isn't working?

This topic has been closed for replies.
Correct answer Laubender

app.scriptPerferences.version = 14.0

I have gotten releaseAnchoredObject() to work in some code I copied from online, but I'm still having trouble implementing it in the program I'm trying to write.

Why does the first section of code work, but the second does not?

   

var sList = app.activeDocument.stories[0];

//var sList = app.activeDocument.stories.everyItem().getElements();

        var imageCollection = sList.splineItems;

        for (var i = imageCollection.length - 1; i >= 0; i--)

        {

             myItem = imageCollection;

            myItem.anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored; 

             myItem.anchoredObjectSettings.releaseAnchoredObject();   

          }  //ends for i loop

imageCollection = app.activeDocument.stories.everyItem().splineItems;

myItem = imageCollection[0];

myItem.anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored; 

myItem.anchoredObjectSettings.releaseAnchoredObject(); 

I have tried changing the first chunk of code to the block below, but it doesn't work

var sList = app.activeDocument.stories.everyItem();

        var imageCollection = sList.splineItems;

        for (var i = imageCollection.length - 1; i >= 0; i--)

        {

             myItem = imageCollection;

            myItem.anchoredObjectSettings.anchoredPosition = AnchorPosition.anchored; 

             myItem.anchoredObjectSettings.releaseAnchoredObject();   

          }  //ends for i loop

So I think it is a problem with the way I'm trying to use everyItem()

Also I don't know what line 9 in the first block of code (the one that works) is doing, but the code won't work without it.

Thank you for any help you can offer!


danielg98770948  wrote

…Also I don't know what line 9 in the first block of code (the one that works) is doing, but the code won't work without it.

Since you cannot release anchored objects that are inline or above line anchored this line of code is changing anchoredPosition from that to anchored. Then, and only then, releaseAnchoredObject() will work.

Regards,
Uwe

2 replies

Community Expert
April 6, 2019

Hi Daniel,

are you sure, that variable myPicture contains the graphic frame holding the image ?

That myPicture.parent is a character ?

Regards,

Uwe

danielg98770948
Known Participant
April 8, 2019

myPicture.constructor.name results in "Rectangle"

myPicture.parent.constructor.name results in "Array"

In the InDesign document, I have paragraphs of text followed by 1 or more paragraphs with 1 image followed by caption text.  So, for example I might have a paragraph of text followed by another paragraph with an in-line image and some caption text, then another paragraph with an in-line image and some caption text, and then a third.

I'm trying to unanchor the image, group it with a caption text box and then anchor the group to the end of the paragraph before the series of images.  Any ideas?

Here's the code I'm working with so far:  (everything works up until the releaseAnchoredObject line near the end)

//add the indexOf method

if (typeof Array.prototype.indexOf != "function") { 

    Array.prototype.indexOf = function (el) { 

        for(var i = 0; i < this.length; i++) if(el === this) return i; 

        return -1; 

        } 

imageCollection = app.activeDocument.stories.everyItem().rectangles;

imageInsertionPoints = imageCollection.everyItem().parent;

var imageIndexes =[];

for (i=0;i<imageInsertionPoints.length;i++)

{

imageIndexes.push(imageInsertionPoints.paragraphs[0].index);

}

paragraphIndexes = app.activeDocument.stories.everyItem().paragraphs.everyItem().index;

var imageParagraphIndexes = [];

//find the imageIndexes in the paragraphIndexes array and save their indexes

for (i=0; i<imageIndexes.length; i++)

{

imageParagraphIndexes.push(paragraphIndexes.indexOf(imageIndexes));

}

//create a imageGroupSize array where the length is the number of image groups and each element is the number of images in the group

imageGroupCounter=1;

indexDiff = 0;

var imageGroupSizes = [];

for (i=0;i<imageParagraphIndexes.length-1;i++)

{

indexDiff = imageParagraphIndexes[i+1]-imageParagraphIndexes;

    if (indexDiff == 1)

{

imageGroupCounter++;

     }

else

{

        imageGroupSizes.push(imageGroupCounter);

        imageGroupCounter=1;

}

}

imageGroupSizes.push(imageGroupCounter);

imageIndex = 0;

var myCaption;

for (i=0;i<imageGroupSizes.length;i++)  //for each image group

{

for (j=0;j<imageGroupSizes;j++)  //for each image in the image group

{

captionContent = (app.activeDocument.stories.everyItem().paragraphs[imageParagraphIndexes[imageIndex+j]].contents[0].slice(1)); //grab the caption text  <<-This line has problems

//set up the caption

myPicture = imageCollection[imageIndex+j];

gb = myPicture.geometricBounds[0];

      myCaption = app.activeDocument.textFrames.add();  

  myCaption.properties = 

  {

  geometricBounds : [gb[2],gb[1],gb[2]+2,gb[3]],

  strokeWidth : 0,

  fillColor : "None", 

  contents : captionContent

  }; 

myPicture.parent[0].anchoredObjectSettings.releaseAnchoredObject(); //<--this line doesn't work

// myPicture.parent.groups.add([myPicture, myCaption])

// anchor the group at the end of the paragraph before the image group

  // delete the caption text from the paragraph

// delete the paragraph that originally contained the image and caption text

}

imageIndex+=j;

}

Community Expert
April 6, 2019

Releasing inline or above line objects does not work, check the UI menu for release would be disabled for such objects. Nevertheless i don't get a function not defined error even in this case. Could you tell which version of scripting DOM are you using, it might be a case that version of DOM does not have this api.

-Manan

-Manan
danielg98770948
Known Participant
April 8, 2019

How can I tell what version of the DOM I am using?

Community Expert
April 8, 2019

danielg98770948  wrote

How can I tell what version of the DOM I am using?

Hi Daniel,

see into:

Adobe InDesign CS6 (8.0) Object Model JS: ScriptPreference

app.scriptPreferences.version

Regards,
Uwe