A script/plugin to write position and size of object
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / A script/plugin to write position and size of object
- This topic has 17 replies, 2 voices, and was last updated 7 years, 8 months ago by Ari Singer.
-
AuthorPosts
-
-
June 30, 2016 at 8:01 pm #86184Denise StanleyMember
HI there,
I am working on a 800 page document and have to record on each page the x/y position and the size of every object. It is info for further software developement. The last time it was all input manually and took 3 months to finish but I’m wondering if there is a script or plugin that could do this for me. Pain in the neck!!
-
June 30, 2016 at 9:19 pm #86186Ari SingerMember
This can probably be done. But more details is needed, such as what is considered an ‘object’? Text frames, images, etc. And where do you want to output this info? To a text file, or on the page directly?
-
June 30, 2016 at 10:13 pm #86187Denise StanleyMember
Yes every text frame and image needs to have info on size and position on page. We have been doing this manually and putting info next to the corresponding objects but on a different layer so that you can see the clean design. For 800 pages that’s a lot of work.
-
July 1, 2016 at 12:47 am #86192Ari SingerMember
Here you go:
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Get XY Coords"); function main() { var myDoc = app.activeDocument; var myPages = myDoc.pages; var myLayers = myDoc.layers; for (var k = 0; k < myLayers.length; k++) { if (myLayers[k].name == "Info Layer") myLayers[k].remove(); break; } var myObjectStyle; var myParaStyle; myDoc.layers.add({name: "Info Layer"}); try { myParaStyle = myDoc.paragraphStyles.item("InfoStyle"); myParaStyle.name; } catch (myError){ myParaStyle = myDoc.paragraphStyles.add({name:"InfoStyle", pointSize:10, leading:14, noBreak: true}); } try{ myObjectStyle = myDoc.objectStyles.item("InfoFrame"); myObjectStyle.name; } catch (myError){ myObjectStyle = myDoc.objectStyles.add(); with(myObjectStyle) { name = "InfoFrame"; basedOn = "[None]"; enableFrameFittingOptions = true; enableAnchoredObjectOptions = false; enableFill = false; enableParagraphStyle = true; enableStroke = false; enableStrokeAndCornerOptions = false; enableTextFrameAutoSizingOptions = true; enableTextFrameGeneralOptions = true; enableTextWrapAndOthers = false; myObjectStyle.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH; myObjectStyle.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.BOTTOM_LEFT_POINT; myObjectStyle.appliedParagraphStyle = myParaStyle; } } for (i = 0; i <myPages.length; i++) { var allStuff = myPages[i].allPageItems; for (j = 0; j < allStuff.length; j++) { var curStuff = allStuff[j]; var myBounds = curStuff.geometricBounds; var myY = myBounds[0]; var myX = myBounds[1]; var myH = myBounds[2] - myY; var myW = myBounds[3] - myX; var myString = "Y: " + myY.toFixed(1) + " X: " + myX.toFixed(1) + " H: " + myH.toFixed(1) + " W: " + myW.toFixed(1); var myFrame = myPages[i].textFrames.add(); myFrame.geometricBounds = [(myY - 5), myX, (myY - 2), (myX + 1)]; myFrame.appliedObjectStyle = myObjectStyle; myFrame.contents = myString; //alert(myString); } } }
This creates a new layer called “Info Layer”, and places all the info text on that layer. Don’t place anything yourself on this layer, because whenever you run the script again this layer will automatically be destroyed to make sure all the info is up to date.
You can play around with the paragraph style (“InfoStyle”), and the object style (“InfoFrame”) that the script automatically creates, and the good news is that your settings won’t be lost when you run the script again.
This script assumes that you have a later version of InDesign that supports auto-sizing text frames.
Good luck!
Ari
-
July 1, 2016 at 1:13 pm #86199Denise StanleyMember
Wow, thanks very much for this—I can’t wait to try it!!
-
July 1, 2016 at 1:36 pm #86200Denise StanleyMember
Ummmm, I’ve not done this before but I followed all the instructions to get it into InDesign (not hard) but it didn’t work. Is it Javascript or Applescript. Sorry, just a front end user!! :-(
-
July 1, 2016 at 1:37 pm #86201Ari SingerMember
Please upload a screenshot of the error. Did you copy the code from here or from your email? Because copying from the email can be problematic.
-
July 1, 2016 at 1:37 pm #86202Ari SingerMember
And it’s JavaScript.
-
July 1, 2016 at 1:39 pm #86203Ari SingerMember
Refer to this article for help on installing a script: https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post.php
-
July 1, 2016 at 1:45 pm #86204Denise StanleyMember
Yeeeha, it worked! I can’t thank you enough. can I donate something to you?
-
July 1, 2016 at 1:49 pm #86205Ari SingerMember
My pleasure! I did not do it for money, but donations are always accepted :) Please send me an email to designerjoe[at]outlook.com
-
July 1, 2016 at 1:56 pm #86206Denise StanleyMember
Will do. A slight problem though. It only works the first time. As its 800 pages long, you cannot select all the objects at once. It works fine the first time but then errors as it tries to make another layer of the same name each time. Is there any way it can be scripted so that I can make the layer first and give it a name then you use this name in the script?
-
July 1, 2016 at 2:00 pm #86207Ari SingerMember
That’s interesting, because the script is supposed to delete that layer every time it runs. Did you try to manually delete the entire layer?
-
July 1, 2016 at 2:33 pm #86208Denise StanleyMember
I think I see how it works now. I think I am correct in saying that you don’t select the objects first. You just double click the script. That is where I was going wrong perhaps. So works when I test on a 2 page doc but freezes with the real one
-
July 1, 2016 at 2:56 pm #86209Denise StanleyMember
I will test by breaking up the document into managable sizes
-
July 1, 2016 at 4:12 pm #86210Ari SingerMember
Who says that it actually freezes? Maybe you just have to let it finish. How long did you wait?
-
July 1, 2016 at 6:46 pm #86211Denise StanleyMember
You are correct but can’t handle 800 pages. I broke it up to 200 pages and it took about 2 mins to process.Brilliant. Thanks.
-
July 5, 2016 at 7:05 am #86270Ari SingerMember
I fixed the script to use only frames, and not the inner objects in them, so not to duplicate the label frames. I also made sure that when the script ends executing, the active layer is not the “InfoLayer” so you don’t mistakenly put important objects on this layer (it gets deleted every time the script runs).
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Get XY Coords"); function main() { var myDoc = app.activeDocument; var myPages = myDoc.pages; var myLayers = myDoc.layers; for (var k = 0; k < myLayers.length; k++) { if (myLayers[k].name == "Info Layer") myLayers[k].remove(); break; } var myObjectStyle; var myParaStyle; myDoc.layers.add({name: "Info Layer"}); try { myParaStyle = myDoc.paragraphStyles.item("InfoStyle"); myParaStyle.name; } catch (myError){ myParaStyle = myDoc.paragraphStyles.add({name:"InfoStyle", pointSize:10, leading:14, noBreak: true}); } try{ myObjectStyle = myDoc.objectStyles.item("InfoFrame"); myObjectStyle.name; } catch (myError){ myObjectStyle = myDoc.objectStyles.add(); with(myObjectStyle) { name = "InfoFrame"; basedOn = "[None]"; enableFrameFittingOptions = true; enableAnchoredObjectOptions = false; enableFill = false; enableParagraphStyle = true; enableStroke = false; enableStrokeAndCornerOptions = false; enableTextFrameAutoSizingOptions = true; enableTextFrameGeneralOptions = true; enableTextWrapAndOthers = false; myObjectStyle.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH; myObjectStyle.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.BOTTOM_LEFT_POINT; myObjectStyle.appliedParagraphStyle = myParaStyle; } } for (i = 0; i <myPages.length; i++) { var allStuff = myPages[i].allPageItems; for (j = 0; j < allStuff.length; j++) { var curStuff = allStuff[j]; if ((curStuff.constructor.name == "Image") || (curStuff.constructor.name == "PDF") || (curStuff.constructor.name == "ImportedPage")) { continue; } var myBounds = curStuff.geometricBounds; var myY = myBounds[0]; var myX = myBounds[1]; var myH = myBounds[2] - myY; var myW = myBounds[3] - myX; var myString = "Y: " + myY.toFixed(1) + " X: " + myX.toFixed(1) + " H: " + myH.toFixed(1) + " W: " + myW.toFixed(1); var myFrame = myPages[i].textFrames.add(); myFrame.geometricBounds = [(myY - 5), myX, (myY - 2), (myX + 1)]; myFrame.appliedObjectStyle = myObjectStyle; myFrame.contents = myString; } } myDoc.activeLayer = myDoc.layers[1]; }
-
-
AuthorPosts
- You must be logged in to reply to this topic.