CreativePro Forum
Join our community of graphic designers, publishers, and production artists from around the world. Our members-only forum is a great place to discuss challenges and find solutions!
- You must be logged in to reply to this topic.Login
Auto Link image inline in running text
Tagged: auto place, images, inline image, script
- This topic has 7 replies, 4 voices, and was last updated 7 years ago by
Anonymous.
-
AuthorPosts
-
-
October 15, 2018 at 5:15 am #110948
Anonymous
InactiveHi Experts,
I need a script which needs automatically place as inline image wherever specific text as XX.eps, XX.ai, etc. I have exactly environment as below link.
https://www.nikkimgroup.com.au/features/placing-artwork
Anyone can help on this topic. I am in need a script due to 250+ links in a file.
Thanks in advance.
Amit -
October 15, 2018 at 6:14 am #110950
Raphael Freeman
Participant// ASSUMES: UP TO 3 PARAGRAPHS OF INSTRUCTIONS
// PARA STYLE NAME IDENTIFIES CONTENTS
// name of folder has to be images
// pstyles, picture, caption text, picture line
//need to create an object styles called picture, caption frame, picture grouped
// fix copy caption
//use script ALT-R to resizevar bSpreadOrigin=true; // sets ruler/origin to SPREAD — if false then PAGE origin
var targetDPI = 300;
var myRawFilename=””;
var myFrameWidth=70; // DEFAULT FRAME WIDTH MILLIMETERS
var myCaptionGap=6;// POINTS
var myCaption=””;
var hasCaption=false;
var myGroup=[];
var myFileNamePara=null;
var myCaptionPara=null;var pageSizeAdjust=.9961;
MainImportImage();
//importImage();function MainImportImage(){
dsr=app.activeWindow.viewDisplaySetting;
app.activeWindow.viewDisplaySetting= ViewDisplaySettings.OPTIMIZED;app.doScript(importImage, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “Import Picture”);
//importImage();app.activeWindow.viewDisplaySetting=dsr;
}function importImage(){
if(bSpreadOrigin == true){
app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
app.activeDocument.zeroPoint = [ 0,0 ];
}
else{
app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
app.activeDocument.zeroPoint = [ 0,0 ];
}
myOldUnits=app.scriptPreferences.measurementUnit;app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
var pictureFolder=”images”; // SUBFOLDER OF DOCUMENT FOLDERmyDoc=app.activeDocument;
var myParas = [];
myParas[1]=app.selection[0].paragraphs[0];
myParas[2]=myParas[1].parentStory.paragraphs.nextItem(myParas[1]);
// myParas[3]=myParas[1].parentStory.paragraphs.nextItem(myParas[2]);//
// CHECK FOR STYLES – CREATE IF MISSING
//
if(app.activeDocument.paragraphStyles.item(“picture”).isValid == false){
os=app.activeDocument.paragraphStyles.add();
os.name=”picture”;
//os.leading = “12pt”;
//os.pointSize=”9pt”;
//os.appliedFont=”Minion Pro”;
}
if(app.activeDocument.paragraphStyles.item(“caption text”).isValid == false){
os=app.activeDocument.paragraphStyles.add();
os.name=”caption text”;
}
if(app.activeDocument.paragraphStyles.item(“picture line”).isValid == false){
os=app.activeDocument.paragraphStyles.add();
os.name=”picture line”;
os.leading = “0”;
os.pointSize=”12pt”;
os.appliedFont=”Arno Pro”;
}if(app.activeDocument.objectStyles.item(“picture”).isValid == false){
os=app.activeDocument.objectStyles.add();
os.name=”picture”;
}if(app.activeDocument.objectStyles.item(“caption frame”).isValid == false){
os=app.activeDocument.objectStyles.add();
os.name=”caption frame”;
}
if(app.activeDocument.objectStyles.item(“picture grouped”).isValid == false){
os=app.activeDocument.objectStyles.add();
os.name=”picture grouped”;
}if(app.activeDocument.objectStyles.item(“RTIWpicture”).isValid == false){
os=app.activeDocument.objectStyles.item(“picture”).duplicate();
os.name=”RTIWpicture”;
}
if(app.activeDocument.objectStyles.item(“RTIWcaption frame”).isValid == false){
os=app.activeDocument.objectStyles.item(“caption frame”).duplicate();
os.name=”RTIWcaption frame”;
}
if(app.activeDocument.objectStyles.item(“RTIWpicture grouped”).isValid == false){
os=app.activeDocument.objectStyles.item(“picture grouped”).duplicate();
os.name=”RTIWpicture grouped”;
}// END CHECK
// Can we make the default stroke to be nothing for the ostyles: picture,
// caption frame and picture group?
// os=app.activeDocument.objectStyles.item(“RTIWpicture”);
// os.enableStroke=true;
// os=app.activeDocument.objectStyles.item(“RTIWcaption frame”);
// os.enableStroke=false;
// os=app.activeDocument.objectStyles.item(“RTIWpicture grouped”);
// os.enableStroke=false;// yes
p=myParas[1];
psName=p.appliedParagraphStyle.name;
if (psName==”picture”) {myRawFilename=p.contents;}
p=myParas[2];
psName=p.appliedParagraphStyle.name;
if (psName==”caption text”) { myCaption=p;hasCaption=true;}
// if (psName==”width”) myFrameWidth=p.contents;//alert(myRawFilename+”====”+hasCaption+”===”+myCaption.contents);return;
myPictureAnchor=myParas[1].insertionPoints[0];
currentPage=app.activeWindow.activePage;var myImageFrame = currentPage.textFrames.add();
myImageFrame.appliedObjectStyle=app.activeDocument.objectStyles.item(“RTIWpicture”);var myBounds = myImageFrame.geometricBounds;
myArray = [0, 150, 32, 150+myFrameWidth];
myImageFrame.geometricBounds = myArray;// alert(“resized”);
imgPath=myDoc.filePath+”/”+pictureFolder+”/”+myRawFilename;
picPath=fixPath(imgPath);f=new File(picPath);
try{
myImageFrame.place (f);
}
catch(e){
alert(“problem with image “+f.name+”. Does it exist?”);return;
}myImageFrame.fit(FitOptions.PROPORTIONALLY);
myImageFrame.fit(FitOptions.FRAME_TO_CONTENT);
resizeToDPI(myImageFrame);myGroup.push(myImageFrame);
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
if(hasCaption) {
var myCaptionFrame=currentPage.textFrames.add();
myImageBounds = myImageFrame.geometricBounds;
myCapArray = [myImageBounds[2]+myCaptionGap, myImageBounds[1], myImageBounds[2]+myCaptionGap+100, myImageBounds[3]];
myCaptionFrame.geometricBounds = myCapArray;
myCaption.duplicate(LocationOptions.AFTER,myCaptionFrame.parentStory.insertionPoints[-1]);
//myCaptionFrame.contents=myCaption;
myCaptionFrame.appliedObjectStyle=app.activeDocument.objectStyles.item(“RTIWcaption frame”);
myCaptionFrame.paragraphs[0].appliedParagraphStyle=app.activeDocument.paragraphStyles.item(“caption text”);
capBot=myCaptionFrame.lines[-1].baseline+3;
myCapArray = [myImageBounds[2]+myCaptionGap, myImageBounds[1], capBot, myImageBounds[3]];
myCaptionFrame.geometricBounds = myCapArray;s=myCaptionFrame.lines[-1];
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = “r”;
app.changeGrepPreferences.changeTo= “”;
x = s.changeGrep();// fit it
myCaptionFrame.fit(FitOptions.FRAME_TO_CONTENT);// GROUP THEM…
myGroup.push(myCaptionFrame);
g=currentPage.groups.add(myGroup);
g.appliedObjectStyle=app.activeDocument.objectStyles.item(“RTIWpicture grouped”);
}
else{
var myCaptionFrame=currentPage.textFrames.add();
myImageBounds = myImageFrame.geometricBounds;myCapArray = [myImageBounds[2]-3, myImageBounds[1], myImageBounds[2], myImageBounds[3]];
myCaptionFrame.geometricBounds = myCapArray;
myCaptionFrame.appliedObjectStyle=app.activeDocument.objectStyles.item(“RTIWcaption frame”);
myGroup.push(myCaptionFrame);g=currentPage.groups.add(myGroup);
g.appliedObjectStyle=app.activeDocument.objectStyles.item(“RTIWpicture grouped”);
}// MARCH 6 2017 MOVED FROM ABOVE TO HERE
p=myParas[2];
psName=p.appliedParagraphStyle.name;
if (psName==”caption text”) { myParas[2].remove();}
p=myParas[1];
psName=p.appliedParagraphStyle.name;
if (psName==”picture”) {
l=p.lines[0].length;
for(i=0;i<l-1;i++){p.characters[i].contents=” “;}
}myParas[1].appliedParagraphStyle=app.activeDocument.paragraphStyles.item(“picture line”);
// RECHECK G THAT IT FITS PAGE VERTICALLY — RESIZE v2 IF NOT — March 22 2018
checkSize(g);// ANCHOR GROUP INTO TEXT
app.select(g);try{
app.copy();
app.select(myPictureAnchor);
app.paste();
app.select(g);
app.cut()
}
catch(e){
alert(“Error ” + e);
}
//g.anchoredObjectSettings.insertAnchoredObject(myPictureAnchor);// DELETE CAP LINE IF EXISTS
// delete spaces
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat=” +(?=\r)”;app.changeGrepPreferences.changeTo = “”;
myParas[1].changeGrep();app.scriptPreferences.measurementUnit=myOldUnits;
}
function fixPath(str){
//Z:ooks\freemanest Folder\Pictures
var pos = str.indexOf(“/”);
if(pos==0){
ns=str.substr(1);
d=ns.substr(0,1);
p=ns.substr(2);
newpath=d+”:”+p;
np=newpath.replace(/%20/g,” “);
newpath=np.replace(“\r”,””);return newpath;
}
str1=str.replace(/%20/g,” “);
str=str1.replace(“\r”,””);
return str;
}function resizeToDPI(myImageF){
var myPage = app.activeWindow.activePage;
var myMargins = myPage.marginPreferences;gb= [myPage.bounds[0]+myMargins.top,myPage.bounds[1]+myMargins.left,myPage.bounds[2]-myMargins.bottom,myPage.bounds[3]-myMargins.right];
conTopPage = gb[0];
conBottomPage = gb[2];
conLeftPage = gb[1];
conRightPage = gb[3];
conPageWidth=conRightPage-conLeftPage;
conPageHeight=conBottomPage-conTopPage;//~ gpH=myGroup.geometricBounds[2]-myGroup.geometricBounds[0];
//~ gpW=myGroup.geometricBounds[3]-myGroup.geometricBounds[1];
gpH=myImageF.geometricBounds[2]-myImageF.geometricBounds[0];
gpW=myImageF.geometricBounds[3]-myImageF.geometricBounds[1];//alert(GetLiveBounds (app.activeWindow.activePage));
gpHWRatio=gpH/gpW;
growValue=conPageWidth/gpW;
if((gpH*growValue)>conPageHeight){
growValue=conPageHeight/gpH;
}myWidth=gpW*growValue;
if(myImageF!=null)
{
gb=myImageF.geometricBounds;
oldWidth=gb[3]-gb[1];ratioW=myWidth/oldWidth;
oldHeight=gb[2]-gb[0];
newHeight=oldHeight*ratioW;
gb[3]=gb[1]+myWidth;
gb[2]=gb[0]+newHeight;
myImageF.geometricBounds=gb;myImageF.fit(FitOptions.PROPORTIONALLY);
myImageF.fit(FitOptions.CONTENT_TO_FRAME);//myImageF.fit(FitOptions.FRAME_TO_CONTENT);
// CHECK EFFECTIVE DPI
myImage=myImageF.allGraphics[0];
try{
if(myImage.effectivePpi[0]<targetDPI){
newScale=100*myImage.actualPpi[0]/targetDPI;
myImage.horizontalScale=myImage.verticalScale=newScale;
myImageF.fit(FitOptions.FRAME_TO_CONTENT);
}
}
catch(e){
myImageF.fit(FitOptions.PROPORTIONALLY);
myImageF.fit(FitOptions.FRAME_TO_CONTENT);
www=myImageF.geometricBounds[3]-myImageF.geometricBounds[1];gb=myImageF.geometricBounds;
gb[3]=gb[1]+conPageWidth;
gb[2]=gb[0]+((gb[2]-gb[0])*(conPageWidth/www));
myImageF.geometricBounds=gb;
newScale=100*conPageWidth/www;
myImage.horizontalScale=myImage.verticalScale=newScale;
myImageF.fit(FitOptions.PROPORTIONALLY);
myImageF.fit(FitOptions.CONTENT_TO_FRAME);
}
}}
function checkSize(picGroup){
var myPage = app.activeWindow.activePage;
var myMargins = myPage.marginPreferences;
myImageF=picGroup.rectangles[0];
myCapF=picGroup.textFrames[0];
myImage=myImageF.allGraphics[0];
groupHeight=picGroup.geometricBounds[2]-picGroup.geometricBounds[0];
//alert(picGroup.geometricBounds[3]-picGroup.geometricBounds[1]);return;gb= [myPage.bounds[0]+myMargins.top,myPage.bounds[1]+myMargins.left,myPage.bounds[2]-myMargins.bottom,myPage.bounds[3]-myMargins.right];
conTopPage = gb[0];
conBottomPage = gb[2];
conLeftPage = gb[1];
conRightPage = gb[3];
conPageWidth=conRightPage-conLeftPage;
conPageHeight=conBottomPage-conTopPage;
conPageHeight*=pageSizeAdjust;//ADJUSTif(groupHeight<conPageHeight){return;}
newScaleValue=(conPageHeight/groupHeight);
myImage.horizontalScale*=newScaleValue;
myImage.verticalScale*=newScaleValue;
myImageF.fit(FitOptions.FRAME_TO_CONTENT);
if(hasCaption){
cgb=myCapF.geometricBounds;
cgb[1]=myImageF.geometricBounds[1];
cgb[3]=myImageF.geometricBounds[3];h=cgb[2]-cgb[0];
cgb[0]=myImageF.geometricBounds[2]+myCaptionGap;
cgb[2]=cgb[0]+h+20;
myCapF.geometricBounds=cgb;
cgb[2]=myCapF.lines[-1].baseline+1;
myCapF.geometricBounds=cgb;
}
else{
myImageBounds=myImageF.geometricBounds;
cgb=myCapF.geometricBounds;
myCapArray = [myImageBounds[2]-3, myImageBounds[1], myImageBounds[2], myImageBounds[3]];
myCapF.geometricBounds = myCapArray;
}
groupHeight=picGroup.geometricBounds[2]-picGroup.geometricBounds[0];
if(groupHeight<conPageHeight){return;}groupHeight=picGroup.geometricBounds[2]-picGroup.geometricBounds[0];
newScaleValue=(conPageHeight/groupHeight);myImage.horizontalScale*=newScaleValue;
myImage.verticalScale*=newScaleValue;
myImageF.fit(FitOptions.FRAME_TO_CONTENT);
if(hasCaption){
cgb=myCapF.geometricBounds;
cgb[1]=myImageF.geometricBounds[1];
cgb[3]=myImageF.geometricBounds[3];h=cgb[2]-cgb[0];
cgb[0]=myImageF.geometricBounds[2]+myCaptionGap;
cgb[2]=cgb[0]+h+20;
myCapF.geometricBounds=cgb;
cgb[2]=myCapF.lines[-1].baseline+1;
myCapF.geometricBounds=cgb;
}
else{
myImageBounds=myImageF.geometricBounds;
cgb=myCapF.geometricBounds;
myCapArray = [myImageBounds[2]-3, myImageBounds[1], myImageBounds[2], myImageBounds[3]];
myCapF.geometricBounds = myCapArray;
}
groupHeight=picGroup.geometricBounds[2]-picGroup.geometricBounds[0];
if(groupHeight<conPageHeight){alert(“problem VFitting”);return;}}
function GetLiveBounds (page) {//gets the bounds within page margins
app.scriptPreferences.measurementUnit = MeasurementUnits.MILLIMETERS;
var bounds = page.bounds;
// alert(bounds);
return [
page.marginPreferences.top,
page.side == PageSideOptions.leftHand ? bounds[1] + page.marginPreferences.right : bounds[1] + page.marginPreferences.left,
bounds[2] – page.marginPreferences.bottom,
page.side == PageSideOptions.leftHand ? bounds[3] – page.marginPreferences.left : bounds[3] – page.marginPreferences.right
]
}//end function getLiveBounds-
October 16, 2018 at 1:58 am #110960
Anonymous
InactiveHi Raphael,
Thanks for your reply but I didn’t get this codes, I will run this script in InDesign but it didn’t happen.
So, could you please help me out here.
Amit
-
-
October 15, 2018 at 12:06 pm #110956
Michel Allio for FRIdNGE
Participant??? …
-
October 17, 2018 at 1:32 am #110973
Anonymous
InactiveHello everyone,
Is there helper to help me here of this topic because I am in dilemma with this issue for 3-4 days.
Please response asap.
Thanks, Amit
-
October 18, 2018 at 3:46 am #110982
Vallo Kivimaa
Member-
October 24, 2018 at 1:43 am #111108
Anonymous
InactiveThanks Vallo for your response.
But there are .ini file where needs to put all the image reference text (like a syntax for each image) in this file which is not possible due to huge quantities of images.
If there will be only text entries without any syntax that would be great.
Please experts response on this.
Thanks, Amit
-
-
November 20, 2018 at 5:37 am #111688
Anonymous
InactiveHi,
I got the solution from the another site that is really awesome script but nobody can help here except above guys.
Thanks
-
-
AuthorPosts
- You must be logged in to reply to this topic.
