Forum Replies Created
-
AuthorPosts
-
Robert Ploch
MemberHi Masood,
1. I’m affraid, I don’t understend your previous post about centering inline grapgics. Would you eplain it more precise ?
2. try this code to process all the inline graphics in all the texts in active document:if ( app.documents.length > 0 ) {
var mySelections = app.activeDocument.stories.everyItem().texts[0].splineItems.everyItem().getElements(); // this is an array of anchored items of the story in seleccted textFrame
alert ( “There are/is ” + mySelections.length + ‘ anchored elements in the document.’ );
main( mySelections );
}
function main( sel ){
var i = sel.length;
while ( i– ) {
try { var myObject = sel[i];
myObject.fit(FitOptions.contentToFrame);
myObject.fit(FitOptions.proportionally);
myObject.fit(FitOptions.centerContent);
myObject.fit(FitOptions.frameToContent);
} catch ( err ) {}
}
}best regards
r.Robert Ploch
MemberHello Jelle,
If you have prepared template (e.g. A3) full of graphic frames in certain grid this piece of code will put choosen file into all the frames. If orientation of choosen file won’t conform shape of the graphic frame, script will rottate imported file.
I’ve tested it shortly on Indd files – template A3 and A5. The script should work regardless of format if formats will conform eachother
best
RobertPS. If you will have problems with copying and pasting code to ExtendScript toolkit write my your e-mail, so I’ll send you a script file.
var toPlace = File.openDialog (‘Select file to place.’, ‘*.*’, false);
if ( !toPlace ) { exit(); }place ( toPlace );
function place ( file ) {
app.activeWindow.transformReferencePoint = AnchorPoint.CENTER_ANCHOR;
var f = app.activeDocument.rectangles, i = f.length;
while ( i– ) {
try { f[i].graphics[0].remove(); } catch (err) {}
with ( f[i] ) {
place ( file ),
clearTransformations(),
clearFrameFittingOptions(),
fit( FitOptions.CENTER_CONTENT )
}if ( ( ( f[i].geometricBounds[3]-f[i].geometricBounds[1] ) < ( f[i].graphics[0].geometricBounds[3]-f[i].graphics[0].geometricBounds[1] ) ) ||
( ( f[i].geometricBounds[2]-f[i].geometricBounds[0] ) < ( f[i].graphics[0].geometricBounds[2]-f[i].graphics[0].geometricBounds[0] ) ) ) {
f[i].graphics[0].rotationAngle = 90;
}
}
}September 30, 2019 at 11:13 am in reply to: Image Fitting options on Anchored Graphic Frames #14324009Robert Ploch
MemberHello again :)
try this little work snippet of code. I hope I’ve undersood your idea :)
I’ve changed a little your code in case of potential errors and/or further actions ( e.g. deleting anchored elements )if ( !app.selection[0] || app.selection[0].constructor.name != ‘TextFrame’ ) { alert ( ‘There is no TEXT FRAME selected !Select a textFrame contaning text please :)’); exit() }
var mySelections = app.selection[0].parentStory.splineItems.everyItem().getElements(); // this is an array of anchored items of the story in seleccted textFramealert ( “There are/is ” + mySelections.length + ‘ anchored elements in the frame.’ );
main();
function main(){
var sel = mySelections, i = sel.length;
while ( i– ) {
var myObject = sel[i];
myObject.fit(FitOptions.contentToFrame);
myObject.fit(FitOptions.proportionally);
myObject.fit(FitOptions.centerContent);
myObject.fit(FitOptions.frameToContent);
}
}best
m.September 27, 2019 at 3:45 pm in reply to: Apply [Unconditional] condition to Conditional Text #14324027Robert Ploch
MemberHi Masood,
try this, it work for me :)
var s = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements(), i = s.length;
while ( i– ) {
s[i].applyConditions( [], true );
}best regards
m.Robert Ploch
MemberHello again Rick,
there is a modified and improoved, more elegant version of the script :-)
I hope it will work fine for you …
The changes are:
1. script returns only styles if they have baseOn style
2. if there are no baseOn styles in character styles, script opens only one paged document
3. I put the original numbers of the styles in source documentIf you will have still problems with the script write your e-mail, so I will send you a file.
regards
m.#target indesign-14
if ( !app.documents.length ) { alert ( “Open document, please !” ); exit(); }
var ps = app.activeDocument.allParagraphStyles, cs = app.activeDocument.allCharacterStyles, parstyles = [], charstyles = [];
processStyles ( ps, 2, parstyles );
processStyles ( cs, 1, charstyles );if ( parstyles.length > 0 && charstyles.length == 0 ) {
var doc = app.documents.add();
addTitleStyle (); addSubTitleStyle();
with ( doc.documentPreferences ) { pagesPerDocument = 1; }
var p = doc.pages[0];
with ( p.marginPreferences ) { top = 10; left = 10; bottom = 10; right = 10; }
p.textFrames.add( { geometricBounds : [ p.marginPreferences.top, p.marginPreferences.left, doc.documentPreferences.pageHeight – p.marginPreferences.bottom, doc.documentPreferences.pageWidth – p.marginPreferences.right ] } ).contents = “Paragraph styles: \rNo. Style based on\r” + parstyles.join( “\r” );
titleSubtitleBold( p.textFrames[0] );
alert (‘There is no basedOn character styles.’ );
}
else if ( parstyles.length > 0 && charstyles.length > 0 ) {
var doc = app.documents.add();
addTitleStyle (); addSubTitleStyle();
with ( doc.documentPreferences ) { pagesPerDocument = 2; }
var p = doc.pages; i = p.length;
while ( i– ) {
with ( p[i].marginPreferences ) { top = 10; left = 10; bottom = 10; right = 10; }
p[i].textFrames.add( { geometricBounds : [ p[i].marginPreferences.top, p[i].marginPreferences.left, doc.documentPreferences.pageHeight – p[i].marginPreferences.bottom, doc.documentPreferences.pageWidth – p[i].marginPreferences.right ] } );
}
p[0].textFrames[0].contents = “Paragraph styles: \rNo. Style based on\r” + parstyles.join( “\r” );
p[1].textFrames[0].contents = “Character styles: \rNo. Style based on\r” + charstyles.join( “\r” );
titleSubtitleBold ( p[0].textFrames[0] ); titleSubtitleBold ( p[1].textFrames[0] );
}// ++++++++++++++++++++++++ func ++++++++++++++++++++++++++
function processStyles( s, x, a ) {
for ( var i = x; i < s.length; i++ ) {
var bs = s[i].basedOn.name;
if ( bs != undefined ) {
a.push( i + “\. ” + s[i].name + ‘ ——— ‘ + bs );
}
}
}
function titleSubtitleBold ( frame ) {
frame.parentStory.paragraphs[0].applyParagraphStyle( doc.paragraphStyles.item( “Title” ) );
frame.parentStory.paragraphs[1].applyParagraphStyle( doc.paragraphStyles.item( “SubTitle” ) );
}
function addTitleStyle ( ) {
doc.paragraphStyles.add( { name : “Title”, fontStyle : “Bold”, pointSize : 16 } );
}
function addSubTitleStyle ( ) {
doc.paragraphStyles.add( { name : “SubTitle”, fontStyle : “Bold”, pointSize : 14, fillTint : 50 } );
}Robert Ploch
MemberRick
I made a big mistake yesterday. Replace line 8 with this code :doc = app.documents().documentPreferences.pagesPerDocument = 2;
It should make the script to run properly :)
best
m.Robert Ploch
Membermy solution is in fact not as elegant as it could be, but my goal was to give you a quick solution. I very happy it help you :)
Robert Ploch
Memberthe error on line 10 must mean something elese
if there is no “basement” :) style you should get UNDEFINEDtry to delete line 10 :)
Robert Ploch
MemberHmmmmm,
I’ve tried this script on a few different documents and it works !try to exchange sigle quotes to double quotes – I use single but it is not exactly correct :)
do you use it om mac or pc?
Robert Ploch
Memberundefined means – there is no basedOn style …. ofcorse :)
Robert Ploch
MemberHi Rick,
try this:
#target indesign-14
var ps = app.activeDocument.allParagraphStyles, cs = app.activeDocument.allCharacterStyles, parstyles = [], charstyles = [];
processStyles ( ps, 2, parstyles );
processStyles ( cs, 1, charstyles );var doc = app.documents.add( { pages : 2 } );
doc.pages[0].textFrames.add( { geometricBounds : [ ‘0mm’,’0mm’,’150mm’,’150mm’ ] } ).contents = ‘Paragraph styles: ‘ + parstyles.join( ”);
doc.pages[1].textFrames.add( { geometricBounds : [ ‘0mm’,’0mm’,’150mm’,’150mm’ ] } ).contents = ‘Character styles: ‘ + charstyles.join( ”);function processStyles ( s, x, a ) {
for ( var i = x; i < s.length; i++ ) {
var bs = s[i].basedOn.name;
a.push( s[i].name + ‘ ——— ‘ + bs );
}
}Just open your template and run the script from ExtendScript Toolkit
It is very simple solution that produces two lists in two frames in new document.I hope it will help you :)
redards
m.Robert Ploch
MemberHi,
Write me please on priv. I can help you :-)
Regards
MarcRobert Ploch
Member… and if you like a graphic version of some of most important indesign DOM elements see this:
https://www.indesignjs.de/auflage2/wp-content/uploads/2015/04/InDesign_Skripting_Kurzreferenz.pdf
Robert Ploch
MemberI like this link very much :-)
https://www.indesignjs.de/extendscriptAPI/
I is very helpful and it is indexed.
-
AuthorPosts
