Saturday, October 18, 2008

 

CS4 Change

Now that CS4 is with us, it's time to start a list of changes (as opposed to out-and-out new features) that might affect existing scripts. The first one I ran into affected my WrapNudger product.

The TextWrapPreferences property previously known as textWrapType is now called textWrapMode. This change affected the function I use in WrapNudger to determine whether or not the selection has a text wrap. Here's the revised version of the function which shows how I made the script work with either CS3 (InDesign version 5) or CS4 (InDesign version 6):

function checkSelection() {
  
if (app.documents.length == 0 ||
        app.selection.length == 0) {
    alert(
"Please select an object with a text wrap."); return false;
  }
  
if (Number(app.version.split(".")[0]) > 5) {
    
if (app.selection.length == 1 &&
          (!(app.selection[0].hasOwnProperty(
"textWrapPreferences")) ||
              app.selection[0].textWrapPreferences.textWrapMode ==
TextWrapModes.none)) {      
      alert(
"Selected item must have a text wrap."); return false;
    }
  }
else {
    
if (app.selection.length == 1 &&
          (!(app.selection[0].hasOwnProperty(
"textWrapPreferences")) ||
              app.selection[0].textWrapPreferences.textWrapType ==
TextWrapTypes.none)) {      
      alert(
"Selected item must have a text wrap."); return false;
    }
  }
  
return true;
}

Comments:
nice post :)
 
hey can you please tell me the difference between indesign desktop ediditon & indesign server. also can you help me in converting indesign document into html pages using C#.
plaese reply at the id: er.priyankapareek@gmail.com
 
hey...
can you please help me giving a script that can merge n number of pdf into one pdf
 
Great
Does it work with Win?
 
Great
Does it work with Win?
 
Abbas,

JavaScript is cross-platform. Just about everything in this blog works equally well on Mac or Win. There are very few things that require you to even think about the platform -- most often, it comes up when working with files.

Dave
 
Keep on posting such stories. I love to read articles like that. BTW add some pics :)
SteaveTheMighty
 
Hi Dave,

always when i'm scripting Indesign with Javascript i stumble upon your blog. I have a question on compatibility between Mac and Windows. i Have this Problem:

I m loading an XML File via javascript into Indesign and have in my xml an element with the attribute href:"file:///relativePath/myimage.jpg"

here the real code:

< produktName >mein Produkt< / produktName >
< bilder >
< bild id="0" href=" file: /// files/82/207827_00_N_b6b25954.jpg" >
< /bilder >


and my script is like this:

var myImgFrame = myPage.rectangles.add({
geometricBounds: [(myY1), (myX1), (myY2), (myX2)]});

myImgFrame.place(File(myImages.xmlElements.item(j).xmlAttributes.item(1).value));

it works fine on a mac. But on a windows system i get the error message:

error Number: 48
Error String Cannot find the folder "c:\d:\myFolder\myFolder2\207827_00_N_b6b25954.jpg".

The Problem is not the partition. I tryd it with an absolute path and it worked. I can also take the images manually from the structure panel in indesign. But i can't place them by script. You have a quick fix for something like this?

Best Regards
fabian
 
Hi Fabian,

All I can suggest is that instead of directly placing you need to first process the file name that comes out of the attribute to get it into the right form.

It's not clear from your example just what's wrong with the string you're getting. The "c:\d:" doesn't look very good, but what it should be I presume you know. So, get it by using:

myFileName = File(myImages.xmlElements.item(j).xmlAttributes.item(1).value).fsName

then massage that into the form it should be and make a new file object from that name and place that.

Hope this helps.

Dave
 
Hi Dave,

fabian again. I already fixed the problem with these code pieces:

Check for operating system:
var myOS = $.os;
var myOSSubString = myOS.charAt(0);
var myOSBoolean;
if(myOSSubString=="w"||myOSSubString=="W"){
myOSBoolean= true;

}else{

myOSBoolean=false;

}


and then i used the String.substring() method for windows to get rid of the file:///

like this:

var myImgFrame = myPage.rectangles.add({
geometricBounds: [(myY1), (myX1), (myY2), (myX2)]
});

if(myOSBoolean==true){

// This is for Windows

var myHREFString = myImages.xmlElements.item(j).xmlAttributes.item(1).value;
var myHREFSubString = myHREFString.substring(8);
myImgFrame.place(File(myHREFSubString));

}else{

// This is for mac

myImgFrame.place(File(myImages.xmlElements.item(j).xmlAttributes.item(1).value));

}

Now it works on Windows and Mac.
If u have a nicer solution let me know.
And thany anyway if you are already on a solution:

Cheers

F
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?