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

Positioning Inline images? [CS3 JS WIN]

New Here ,
Feb 13, 2009 Feb 13, 2009
I have an inline graphic in a line of text. I want to be able to automatically position it in the vertical center of the line, but i can't find anyway to do this in javascript. Ive tried geometric and visible bounds to no avail. Ive also tried looking for a way to change it in indesign, but it only seems to be possible by dragging it with the mouse. Any ideas?
TOPICS
Scripting
4.3K
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 ,
Feb 13, 2009 Feb 13, 2009
Use a move.

Something like this:

myGBs = myInline.geometricBounds;
myCenterY = (myGBs[2] + myGBs[0])/2;
myBaseline = myInline.parent.baseline;
myInline.move(undefined, [0, myBaseline - myCenterY);

Dave
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
Guest
Feb 13, 2009 Feb 13, 2009
Dave

I have a related problem. I'm not familiar with scripts but need one that would search a story and, e.g., replace the text "Pencil.tif" with a graphic file named Pencil.tif from a given folder.

Can you help with this?

Thanks,

Tom
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
Valorous Hero ,
Feb 13, 2009 Feb 13, 2009
>need one that would search a story and, e.g., replace the text "Pencil.tif" with a graphic file named Pencil.tif from a given folder.

I've found in my archive a script written by Peter Kahrel (I modified it a little). It finds text between two @ characters – e.g. @Pencil.tif@ – and replaces it with image that has the same name and is in the root folder of C drive.
// reset the Find/Change dialog

app.findGrepPreferences = app.changeGrepPreferences = null;
// formulate a grep search string
app.findGrepPreferences.findWhat = '@.+?@';
// find all occurrence, last one first
f = app.activeDocument.findGrep (true);
for (i = 0; i < f.length; i++)
{
// construct file name
name = f.contents.replace (/@/g, '');
// place the pdf
f.insertionPoints[0].place (File ('/c/' + name));
}
// delete all @??@ codes
app.activeDocument.changeGrep()
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
Guest
Feb 13, 2009 Feb 13, 2009
Kasyan

Forgot to mention I'm working in original CS version. Grep probably won't work?

Tom
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
Valorous Hero ,
Feb 13, 2009 Feb 13, 2009
>Grep probably won't work?

Certainly it won't – Grep is supported since CS3.
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
Guest
Feb 16, 2009 Feb 16, 2009
Time to upgrade?
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
LEGEND ,
Feb 16, 2009 Feb 16, 2009
You can get the same result in CS2, but it's a lot more convoluted.

The basic idea is to build an array of the exact file name strings. To
do this you use js RegEx to search the contents of every story. The
results of this match() will give you the strings you need. You then
iterate through your array and do a search() on your doc to do the
replacements.

I think Peter's book on scripting InDesign has examples of this method.

--
Harbs
http://www.in-tools.com
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
Community Expert ,
Feb 17, 2009 Feb 17, 2009
The good old days, eh, Harbs? Here's a CS2 version. It skips footnotes (because you can't do this kind of thing in footnotes in CS2) and tables.

Peter

#target indesign


picture_dir = '/d/'
app.findPreferences = app.changePreferences = null;
myStories = app.activeDocument.stories;
for (i = 0; i < myStories.length; i++)
{
picnames = myStories.contents.match (/@.+?@/g);
if (picnames != null)
{
for (j = 0; j < picnames.length; j++)
{
found = app.activeDocument.search (picnames,false,false);
for (k = found.length-1; k > -1; k--)
{
try
{
filename = found.contents.replace (/@/g, "");
found.insertionPoints[-1].place (File (picture_dir + filename));
found.remove();
}
catch(_){}
}
}
}
}
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
LEGEND ,
Feb 17, 2009 Feb 17, 2009
Peter Kahrel wrote:
> The good old days, eh, Harbs?

Yeah. 😉 My problem is, that I still need to support CS2, so I'm still
stuck using these backwards methods on occasion. :(

--
Harbs
http://www.in-tools.com
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
New Here ,
Feb 18, 2009 Feb 18, 2009
Took a little messing around with my current situation (its not always centered - sometimes a little off) but the move worked perfectly!

Thank you Dave
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
Guest
Mar 23, 2009 Mar 23, 2009
Kasyan Servetsky

I've upgraded to CS4 and need a script to replace "filename.tif" with a photo of the same name inline.

Do you have a script that will work in InDesign CS4?

Thanks,
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
Valorous Hero ,
Mar 23, 2009 Mar 23, 2009
I don’t have CS4 version at my disposal right now, so I can’t check if this script works with it. But even if it doesn’t, placing the script into ‘Version 5.0 Scripts’ folder should make it compatible with CS4.

Kasyan
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
Guest
Mar 23, 2009 Mar 23, 2009
Kasyan

Where would I find this "version 5.0 scripts" folder? It doesn't appear in the InDesign/Scripts folder.
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 ,
Mar 23, 2009 Mar 23, 2009
You make it. And the capitalization of the name is vital. It must be named:

Version 5.0 Scripts

not "version 5.0 scripts" as you wrote.

Dave
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
Valorous Hero ,
Mar 23, 2009 Mar 23, 2009
Create it yourself – it isn't installed by default.
The exact path should be:
Adobe InDesign CS4\Scripts\Scripts Panel\Version 5.0 Scripts
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
Guest
Mar 23, 2009 Mar 23, 2009
Okay I did as you suggested, but get this error message:
Windows Scripting Error!
Error Number: 1024
Error String: Expected Statement

File: C\Program Files\Adobe\Adobe InDesign CS4\Scripts\Scripts Panel\Version 5.0 Scripts\InlinePix.vbs
Line: 1
Source://reset the Find/Change dialog
Interpreter: CS3 (5.0)

Any help?
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
Valorous Hero ,
Mar 24, 2009 Mar 24, 2009
This script is written in JavaScript(jsx extension), but you saved it as VBscript (vbs extension). So no wonder that it doesn't work.
Copy code, start ExtendScript Toolkit, create a new file, paste the code and save the file.
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
Guest
Mar 24, 2009 Mar 24, 2009
I had saved it as a jsx after going thru the ExtendScript. It just sits there and does nothing apparent.

Sorry, but I'm a dummy with scripts.
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
Valorous Hero ,
Mar 24, 2009 Mar 24, 2009
Aha, I see! The script (post 3) expects that the files to be placed are stored in the root folder of C drive. So you should change the line 12 to where you store your files e.g. suppose folder called ‘Images’ on your Desktop:
f.insertionPoints[0].place (File ('~/Desktop/Images/' + 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
Valorous Hero ,
Mar 24, 2009 Mar 24, 2009
Or, as an option, the script can ask you to choose the folder:
if(app.documents.length != 0){

var myFolder = Folder.selectDialog ('Choose a folder with images');
if(myFolder != null){
// reset the Find/Change dialog
app.findGrepPreferences = app.changeGrepPreferences = null;
// formulate a grep search string
app.findGrepPreferences.findWhat = '@.+?@';
// find all occurrence, last one first
f = app.activeDocument.findGrep (true);
for (i = 0; i < f.length; i++)
{
// construct file name
name = f.contents.replace (/@/g, '');
// place the pdf
f.insertionPoints[0].place (myFolder.fsName + '/' + name);
}
// delete all @??@ codes
app.activeDocument.changeGrep()
}
}
else{
alert('Please open a document and try again.');
}
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
Engaged ,
Nov 06, 2016 Nov 06, 2016

Dear Kasyan,

I have problem,

In my document there is more than 100 images name, when I run your script I got an error because in my directory some images is different location/path.

Regards,

Sumit

-Sumit
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
Valorous Hero ,
Nov 07, 2016 Nov 07, 2016

I just tested the script (I posted in post 20) in InDesign 2015.4 and it works for me in the same way as it worked in CS3.

Before

11-7-2016 6-59-33 PM.png

After

11-7-2016 7-00-04 PM.png

This script doesn't care about the existing images and their locations. It only places new images using the names of files found in between a pair of '@' characters and the selected folder for images.

— Kas

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
Engaged ,
Nov 07, 2016 Nov 07, 2016

Dear Kasyan,

Thank you for quick response.

Your script is great!

My problem is, if some images are not found in selected directory then pop up error massage and stop executing next.

Below is my scenario,  but my document contains more than 100 image names and in my directory there is less than 100 images found then stop executing script.

I hope you understand my problem, my english is not good.

Screen Shot 2016-11-08 at 7.17.25 am.pngScreen Shot 2016-11-08 at 7.17.41 am.pngScreen Shot 2016-11-08 at 7.20.02 am.png

Thanks,

Sumit

-Sumit
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
LEGEND ,
Nov 07, 2016 Nov 07, 2016

This should do it:

if(app.documents.length != 0){

  var myFolder = Folder.selectDialog ('Choose a folder with images');

  if(myFolder != null){

      // reset the Find/Change dialog

      app.findGrepPreferences = app.changeGrepPreferences = null;

      // formulate a grep search string

      app.findGrepPreferences.findWhat = '@.+?@';

      // find all occurrence, last one first

      var f = app.activeDocument.findGrep (true);

      var missedFiles = [];

      for (var i = 0; i < f.length; i++){

         // construct file name

         name = f.contents.replace (/@/g, '');

         // place the pdf

         try{

           f.insertionPoints[0].place (myFolder.fsName + '/' + name);

         }catch(err){

          missedFiles.push(name);

         }

        }

      // delete all @??@ codes

      app.activeDocument.changeGrep();

      if(missedFiles.length){

        alert("The following files could not be found: " + missedFiles.join(", "));

      }

  }

}

else{

   alert('Please open a document and try again.');

}

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