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
A script/plugin to write position and size of object
- This topic has 17 replies, 2 voices, and was last updated 9 years, 5 months ago by
Ari Singer.
-
AuthorPosts
-
-
June 30, 2016 at 8:01 pm #86184
Anonymous
InactiveHI 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 #86186
Ari Singer
MemberThis 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 #86187
Anonymous
InactiveYes 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 #86192
Ari Singer
MemberHere 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 #86199
Anonymous
InactiveWow, thanks very much for this—I can’t wait to try it!!
-
July 1, 2016 at 1:36 pm #86200
Anonymous
InactiveUmmmm, 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 #86201
Ari Singer
MemberPlease 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 #86202
Ari Singer
MemberAnd it’s JavaScript.
-
July 1, 2016 at 1:39 pm #86203
Ari Singer
MemberRefer 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 #86204
Anonymous
InactiveYeeeha, it worked! I can’t thank you enough. can I donate something to you?
-
July 1, 2016 at 1:49 pm #86205
Ari Singer
MemberMy 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 #86206
Anonymous
InactiveWill 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 #86207
Ari Singer
MemberThat’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 #86208
Anonymous
InactiveI 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 #86209
Anonymous
InactiveI will test by breaking up the document into managable sizes
-
July 1, 2016 at 4:12 pm #86210
Ari Singer
MemberWho 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 #86211
Anonymous
InactiveYou 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 #86270
Ari Singer
MemberI 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.
