Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to move image from one page to another page using indesign javascript.

Explorer ,
Jul 10, 2015 Jul 10, 2015

hi ,

right now i can able to move image from one place to another place using geometricBounds.. within single page its working fine.

now i want to move the image from one page to another page using indesign javscript.

TOPICS
Scripting
3.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 10, 2015 Jul 10, 2015

Use move() method, you can specify page as a parameter

#target indesign

myDoc = app.activeDocument;

myImage = myDoc.allGraphics[0].parent;

myPage = myDoc.pages[2];

myImage.move(myPage);

Moves the image to page 3 of the document.

InDesign CS5.5 OSX 10.9

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 10, 2015 Jul 10, 2015

Try this,

app.selection[0].move(app.activeDocument.pages[1]);//this line will move the object to second page

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 10, 2015 Jul 10, 2015

thank u so much to both of them..both ideas are working fine.

thanks for the support.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 10, 2015 Jul 10, 2015

hi, here is my code.. im trying find the text and match that text with image name. if both are equal , that image will move to under that text .

if text and image are same page, its working fine .but if text and image are in different pages. its not working ..

ImageAlign();

function ImageAlign()

{

   

var doc = app.activeDocument;

var img = doc.allGraphics;

var finds,myText,myfind,start,end,myPage,imgPage;

app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

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

{

app.findTextPreferences.findWhat = img.itemLink.name;

finds = doc.findText();

       if (finds.length > 0)

      {

        myPage = finds[0].parentTextFrames[0].parentPage.name;

        imgPage = img.parentPage.name;

        myFrame = finds[0].parentTextFrames[0].geometricBounds;

        finds[0].parentTextFrames[0].textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP;

        myText = finds[0].createOutlines(false);

        gb= myText[0].geometricBounds;

        end = gb[0];

        start = myFrame[1];

        //alert(gb);

        //alert(start);

        //alert(end);

        myText[0].remove();

    }

    else {

        alert('Nothing has been found');

    }

//try

//{

   

if(img.itemLink.name == finds[0].contents)

    {

       

   if(myPage == imgPage)

   {

      

     img.parent.move([start, end+1.5]);

     img.textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP;

     img.textWrapPreferences.textWrapOffset = [0,1,1,0];

     // doc.textFrames[0].move([3,30]);

     // alert(img.geometricBounds);

     }

else

   {

     

     img.parent.move(doc.pages[myPage]);

     img.parent.move([start, end+1.5]);

     img.textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP;

     img.textWrapPreferences.textWrapOffset = [0,1,1,0];

   

     }

  }

//catch(e)

//{

  //alert('There is no match in this document');  

  //}

app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 10, 2015 Jul 10, 2015

Try this,

img.parent.move(doc.pages[Number(myPage)-1]);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 12, 2015 Jul 12, 2015

thank u so much . i used this code and its working fine,.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 16, 2015 Jul 16, 2015

now im getting error in that line. when i try to run this script in another document.

Snap 2015-07-16 at 16.31.35.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 16, 2015 Jul 16, 2015

Check what all your references are correct, check that there is a page, check there is a graphic frame and there is an image in it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 16, 2015 Jul 16, 2015

yeah i checked everything is there in my document.

image is there in page 2 and text references is there in page 5.

now image has to move to page 5. but im getting this error..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 16, 2015 Jul 16, 2015

Is it one image only does not work, or you only have one image to move? If it is the case, try to move it explicitly:

img.parent.move(doc.pages[4]);


Disable everything else - second move and text-wrap.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 16, 2015 Jul 16, 2015

Not sure if move will work for inline image. I would try to get the filepath, remove the image and place it again at the found[0] insertion point

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 16, 2015 Jul 16, 2015

now i found , in my document i have 15 pages but i have only one text frame and that text frame is extended to 15 pages ..

i think thats why im getting this error..now how to resolve this ..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 16, 2015 Jul 16, 2015

no i have 5 different images in my document.

here this program concept is , i have to move the images to its correct location.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 16, 2015 Jul 16, 2015

I see. You problem is this line:

myPage = finds[0].parentTextFrames[0].parentPage.name;


You need to get the page of your finds[0].


Check what you get for  parentPage above, it might be an array of all pages.


So if you add myPage = finds[0].parentTextFrames[0].parentPage[0].name; this might move your image to the first page.



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 17, 2015 Jul 17, 2015

This works for me (CS 5.5 OSX 10.9):

myPage = finds[0].parentTextFrames[0].parent.pages[0].name;



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 17, 2015 Jul 17, 2015

see this line gives the correct page number where the image name text is present.

myPage = finds[0].parentTextFrames[0].parentPage.name;


but i'm getting error in this line..


img.parent.move(doc.pages[Number(myPage)-1]); 




Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 17, 2015 Jul 17, 2015

i can move images inside the same page but if i want to move the page to some other page . it showing error in this line.

img.parent.move(doc.pages[Number(myPage)-1]);


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 17, 2015 Jul 17, 2015

Check if doc.pages[Number(myPage)-1] evaluates to a page.

I suspect that image parent is different, could you do alert(img.parent);?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 20, 2015 Jul 20, 2015

yeah,

i checked and alert(doc.pages[Number(myPage)-1]); it shows the correct page object.

i did alert(img.parent); and correctly it shows the rectangle object of that image.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 20, 2015 Jul 20, 2015

OK, try to add these two lines:

     img.parent.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;

     img.parent.anchoredObjectSettings.releaseAnchoredObject();

     img.parent.move(doc.pages[Number(myPage)-1]);

I suppose, the image you placed is anchored to the text. You need to release the parent rectangle before you move it.

Nicolai

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 20, 2015 Jul 20, 2015

yeah i add this two lines , but it showing error in this line..Snap 2015-07-20 at 17.56.10.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 20, 2015 Jul 20, 2015

You need to investigate the object.

What is  img.parent.anchoredObjectSettings.anchoredPosition ?

Is your image inline? Can you manually move it to a different page, different spread?

I checked the dom reference for CS6 and all it looks fine.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 29, 2015 Jul 29, 2015
LATEST

this below code , showing INLINE_POSITION ...

alert( img.parent.anchoredObjectSettings.anchoredPosition);

and its working ..but first time its releasing the anchoredposition of the image .

next time while i run this script .. it showing error like ..

"the property is not applicable in the current state...

because the anchoredposition is released ..

now i need a condition like,,

wheather the image is anchored or not...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines