Highlighted

Markup dimensions in InDesign file

Explorer ,
Nov 21, 2019

Copy link to clipboard

Copied

Is there a way to markup a document in InDesign with dimensions?

Much like you can do in a drafting program, like AutoCAD.

See sample screenshot below (made in AutoCAD).

 

GUID-981465FF-9076-41CF-83D0-189A1130DC6E.png

I asked the question and discovered the answer!

The script below is the correct one.

 

Copy and paste the following lines in notepad and save as"labelImageSize.jsx" (must include the .jsx extension, obviosuly). Also, make sure you have "Arial" font installed on your machine, otherwise replace "Arial" with a font you have installed.

 

Finally, by default the dimensions won't print. If you want them to; check the "Print Layer" option within "ImageLabel" layer.

 

Annotation 2019-11-21 134158.png

 

SCRIPT STARTS AFTER THIS LINE:

----------------------------------------------

 

//DESCRIPTION:Label image with its size
// Jongware, 13-Jan-2012
// No Guarantees, Etc.

if (app.documents.length && app.selection.length == 1 && app.selection[0].hasOwnProperty("paths"))
{
if (app.version < 6)
labelItem(app.selection[0]);
else
app.doScript(labelItem, ScriptLanguage.JAVASCRIPT, app.selection[0], UndoModes.ENTIRE_SCRIPT, "Label Image Size");
} else
{
alert ("No valid selection.\nPlease select one single object with the black arrow before running this script.");
}

function labelItem (item)
{
// Save current selected layer because adding one will make it active!
activeLayer = app.activeDocument.layoutWindows[0].activeLayer;
// Make sure the layer "ImageSize" exists
try {
app.activeDocument.layers.add({name:"ImageLabel", ignoreWrap:true, layerColor: [90,192,90], printable: false});
} catch (_) { }
reportLayer = app.activeDocument.layers.item("ImageLabel");

// Make sure the swatch "ImageGreen" exists
try {
app.activeDocument.colors.add({name:"ImageLabel", space:ColorSpace.RGB, colorValue:[90,192,90], colorModel:ColorModel.PROCESS});
} catch (_) { }
reportGreen = app.activeDocument.swatches.item("ImageLabel");

// Make sure the paragraph style "ImageSize" exists
try {
app.activeDocument.paragraphStyles.add({name:"ImageLabel", appliedFont:"Arial", pointSize:12, fillColor:reportGreen, justification: Justification.CENTER_ALIGN});
} catch (_) { }
reportStyle = app.activeDocument.paragraphStyles.item("ImageLabel");

// Make sure measurement units are in inches
hmmu = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
vmmu = app.activeDocument.viewPreferences.verticalMeasurementUnits;
app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
// .. and Smart Quotes is Off
sqt = app.activeDocument.textPreferences.typographersQuotes;
app.activeDocument.textPreferences.typographersQuotes = false;
// Save all of the previous settings to be able to restore them later 🙂

// fetch width and height for the numbers, left and bottom for the lines
gb = item.geometricBounds;
// gb now holds [ top, left, bottom, right ] values -- get shorthand values
top = gb[0];
left = gb[1];
bottom = gb[2];
right = gb[3];

width = Math.round(Math.abs(right - left)*1000)/1000;
height= Math.round(Math.abs(bottom - top)*1000)/1000;

// Retrieve the current page.
// Actually, in CS5 and newer, page items have a property for this (parentPage),
// but I don't have that one near, and it's also nicer to make it work in CS4
// (and possibly even in older versions).
pg = item.parent;
while (1)
{
if (pg instanceof InsertionPoint)
pg = pg.parentTextframes[0];
if (pg instanceof Document || pg instanceof Spread || pg instanceof Page)
break;
pg = pg.parent;
}
// Draw text frame #1: Height
// Put it at the left of the selection, 0.5" wide and 0.2" off the left side
frh = pg.textFrames.add(reportLayer, {geometricBounds:[ top, left - 0.7, top + height, left - 0.2 ],
textFramePreferences: {verticalJustification: VerticalJustification.CENTER_ALIGN,
ignoreWrap: true } });
// ... and put text into it.
frh.insertionPoints[0].appliedParagraphStyle = reportStyle;
frh.contents = String(height)+'"';

// Draw text frame #2: Width
// Put it at 0.2" off the bottom of the selection, 0.25" high, full width for convenience
frw = pg.textFrames.add(reportLayer, {geometricBounds:[ bottom + 0.2, left, bottom + 0.2 + 0.25, left + width ],
textFramePreferences: {verticalJustification: VerticalJustification.CENTER_ALIGN,
ignoreWrap: true } });
// ... and put text into it.
frw.insertionPoints[0].appliedParagraphStyle = reportStyle;
frw.contents = String(width)+'"';

// Add vertical (height) line
lnh = pg.graphicLines.add (reportLayer, {strokeColor:reportGreen, strokeWeight:0.5});
// It appears in a default position so move it to the right one
lnh.paths[0].entirePath = [ [left - 0.15, top ], [left - 0.15, bottom ] ];
// add top stroke; it's 0.05" wide so offset left and right with 0.025"
lnh.paths.add ({ entirePath:[ [left-0.15 - 0.025, top ], [left-0.15 + 0.025, top] ] });
// add bottom stroke
lnh.paths.add ({ entirePath:[ [left-0.15 - 0.025, bottom ], [left-0.15 + 0.025, bottom] ] });

// Add horizontal (width) line
lnw = pg.graphicLines.add (reportLayer, {strokeColor:reportGreen, strokeWeight:0.5});
// Again we move it to the right position
lnw.paths[0].entirePath = [ [left, bottom + 0.15 ], [right, bottom + 0.15 ] ];
// Add end caps as above
lnw.paths.add ({ entirePath:[ [left, bottom+0.15 - 0.025 ], [left, bottom+0.15 + 0.025] ] });
lnw.paths.add ({ entirePath:[ [right, bottom+0.15 - 0.025 ], [right, bottom+0.15 + 0.025] ] });

// At this point we added four items: 2 text frames and 2 graphic lines.
// Group them together for convenience
app.activeDocument.groups.add ( [ frh, frw, lnh, lnw ] );

// Restore old layer selection
app.activeDocument.layoutWindows[0].activeLayer = activeLayer;

// Restore previous global settings
app.activeDocument.viewPreferences.horizontalMeasurementUnits = hmmu;
app.activeDocument.viewPreferences.verticalMeasurementUnits = vmmu;
app.activeDocument.textPreferences.typographersQuotes = sqt;

}

Topics

How to

Views

694

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Markup dimensions in InDesign file

Explorer ,
Nov 21, 2019

Copy link to clipboard

Copied

Is there a way to markup a document in InDesign with dimensions?

Much like you can do in a drafting program, like AutoCAD.

See sample screenshot below (made in AutoCAD).

 

GUID-981465FF-9076-41CF-83D0-189A1130DC6E.png

I asked the question and discovered the answer!

The script below is the correct one.

 

Copy and paste the following lines in notepad and save as"labelImageSize.jsx" (must include the .jsx extension, obviosuly). Also, make sure you have "Arial" font installed on your machine, otherwise replace "Arial" with a font you have installed.

 

Finally, by default the dimensions won't print. If you want them to; check the "Print Layer" option within "ImageLabel" layer.

 

Annotation 2019-11-21 134158.png

 

SCRIPT STARTS AFTER THIS LINE:

----------------------------------------------

 

//DESCRIPTION:Label image with its size
// Jongware, 13-Jan-2012
// No Guarantees, Etc.

if (app.documents.length && app.selection.length == 1 && app.selection[0].hasOwnProperty("paths"))
{
if (app.version < 6)
labelItem(app.selection[0]);
else
app.doScript(labelItem, ScriptLanguage.JAVASCRIPT, app.selection[0], UndoModes.ENTIRE_SCRIPT, "Label Image Size");
} else
{
alert ("No valid selection.\nPlease select one single object with the black arrow before running this script.");
}

function labelItem (item)
{
// Save current selected layer because adding one will make it active!
activeLayer = app.activeDocument.layoutWindows[0].activeLayer;
// Make sure the layer "ImageSize" exists
try {
app.activeDocument.layers.add({name:"ImageLabel", ignoreWrap:true, layerColor: [90,192,90], printable: false});
} catch (_) { }
reportLayer = app.activeDocument.layers.item("ImageLabel");

// Make sure the swatch "ImageGreen" exists
try {
app.activeDocument.colors.add({name:"ImageLabel", space:ColorSpace.RGB, colorValue:[90,192,90], colorModel:ColorModel.PROCESS});
} catch (_) { }
reportGreen = app.activeDocument.swatches.item("ImageLabel");

// Make sure the paragraph style "ImageSize" exists
try {
app.activeDocument.paragraphStyles.add({name:"ImageLabel", appliedFont:"Arial", pointSize:12, fillColor:reportGreen, justification: Justification.CENTER_ALIGN});
} catch (_) { }
reportStyle = app.activeDocument.paragraphStyles.item("ImageLabel");

// Make sure measurement units are in inches
hmmu = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
vmmu = app.activeDocument.viewPreferences.verticalMeasurementUnits;
app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
// .. and Smart Quotes is Off
sqt = app.activeDocument.textPreferences.typographersQuotes;
app.activeDocument.textPreferences.typographersQuotes = false;
// Save all of the previous settings to be able to restore them later 🙂

// fetch width and height for the numbers, left and bottom for the lines
gb = item.geometricBounds;
// gb now holds [ top, left, bottom, right ] values -- get shorthand values
top = gb[0];
left = gb[1];
bottom = gb[2];
right = gb[3];

width = Math.round(Math.abs(right - left)*1000)/1000;
height= Math.round(Math.abs(bottom - top)*1000)/1000;

// Retrieve the current page.
// Actually, in CS5 and newer, page items have a property for this (parentPage),
// but I don't have that one near, and it's also nicer to make it work in CS4
// (and possibly even in older versions).
pg = item.parent;
while (1)
{
if (pg instanceof InsertionPoint)
pg = pg.parentTextframes[0];
if (pg instanceof Document || pg instanceof Spread || pg instanceof Page)
break;
pg = pg.parent;
}
// Draw text frame #1: Height
// Put it at the left of the selection, 0.5" wide and 0.2" off the left side
frh = pg.textFrames.add(reportLayer, {geometricBounds:[ top, left - 0.7, top + height, left - 0.2 ],
textFramePreferences: {verticalJustification: VerticalJustification.CENTER_ALIGN,
ignoreWrap: true } });
// ... and put text into it.
frh.insertionPoints[0].appliedParagraphStyle = reportStyle;
frh.contents = String(height)+'"';

// Draw text frame #2: Width
// Put it at 0.2" off the bottom of the selection, 0.25" high, full width for convenience
frw = pg.textFrames.add(reportLayer, {geometricBounds:[ bottom + 0.2, left, bottom + 0.2 + 0.25, left + width ],
textFramePreferences: {verticalJustification: VerticalJustification.CENTER_ALIGN,
ignoreWrap: true } });
// ... and put text into it.
frw.insertionPoints[0].appliedParagraphStyle = reportStyle;
frw.contents = String(width)+'"';

// Add vertical (height) line
lnh = pg.graphicLines.add (reportLayer, {strokeColor:reportGreen, strokeWeight:0.5});
// It appears in a default position so move it to the right one
lnh.paths[0].entirePath = [ [left - 0.15, top ], [left - 0.15, bottom ] ];
// add top stroke; it's 0.05" wide so offset left and right with 0.025"
lnh.paths.add ({ entirePath:[ [left-0.15 - 0.025, top ], [left-0.15 + 0.025, top] ] });
// add bottom stroke
lnh.paths.add ({ entirePath:[ [left-0.15 - 0.025, bottom ], [left-0.15 + 0.025, bottom] ] });

// Add horizontal (width) line
lnw = pg.graphicLines.add (reportLayer, {strokeColor:reportGreen, strokeWeight:0.5});
// Again we move it to the right position
lnw.paths[0].entirePath = [ [left, bottom + 0.15 ], [right, bottom + 0.15 ] ];
// Add end caps as above
lnw.paths.add ({ entirePath:[ [left, bottom+0.15 - 0.025 ], [left, bottom+0.15 + 0.025] ] });
lnw.paths.add ({ entirePath:[ [right, bottom+0.15 - 0.025 ], [right, bottom+0.15 + 0.025] ] });

// At this point we added four items: 2 text frames and 2 graphic lines.
// Group them together for convenience
app.activeDocument.groups.add ( [ frh, frw, lnh, lnw ] );

// Restore old layer selection
app.activeDocument.layoutWindows[0].activeLayer = activeLayer;

// Restore previous global settings
app.activeDocument.viewPreferences.horizontalMeasurementUnits = hmmu;
app.activeDocument.viewPreferences.verticalMeasurementUnits = vmmu;
app.activeDocument.textPreferences.typographersQuotes = sqt;

}

Topics

How to

Views

695

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 21, 2019 0
Adobe Community Professional ,
Nov 21, 2019

Copy link to clipboard

Copied

There isn't a native feature that offers dimensioning in InDesign, and if someone makes a plugin, I haven't seen it.

 

You'd have better luck if it was Illustrator.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2019 1
Explorer ,
Nov 21, 2019

Copy link to clipboard

Copied

Thanks.

On second thought, I just came across this script:

https://www.drscripto.com/indesign-add-measurements/

I'll have to try it, but it seems that it would be a solution.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2019 1
Participant ,
Nov 21, 2019

Copy link to clipboard

Copied

This isn't exactly what you are looking for, but a user in the InDesign Forum wrote a script for me for labeling dimensions of a selected object.

https://indesignsecrets.com/topic/script-to-label-selection-with-height-and-width 

 

And in that thread, there is mention of a plug in, but I never tried it since the solution provided for me was excellent.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2019 1
Explorer ,
Nov 21, 2019

Copy link to clipboard

Copied

Thanks, "pedley_s".

I've tried one of the solutions, but got an error (see screenshot) when running the script.

Anyone know what that means? I'm running latest version; InDesign 2020, btw.

Thanks.

Annotation 2019-11-21 130929.png

JavaScript Error!

Error Number: 30477
Error String: Invalid value for set property 'appliedParagraphStyle'. Expected ParagraphStyle or String, but received nothing.

Engine: main
File: C:\Users\ [my user name] \AppData\Roaming\Adobe\InDesign\Version 15.0-ME\en_IL\Scripts\Scripts Panel\labelImageSize.jsx
Line: 7
Source: app.doScript(labelItem, ScriptLanguage.JAVASCRIPT, app.selection[0], UndoModes.ENTIRE_SCRIPT, "Label Image Size");

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2019 1
Explorer ,
Nov 21, 2019

Copy link to clipboard

Copied

I asked the question and discovered the answer!

The script below is the correct one.

 

Copy and paste the following lines in notepad and save as"labelImageSize.jsx" (must include the .jsx extension, obviosuly). Also, make sure you have "Arial" font installed on your machine, otherwise replace "Arial" with a font you have installed.

 

Finally, by default the dimensions won't print. If you want them to; check the "Print Layer" option within "ImageLabel" layer.

 

Annotation 2019-11-21 134158.png

 

SCRIPT STARTS AFTER THIS LINE:

----------------------------------------------

 

//DESCRIPTION:Label image with its size
// Jongware, 13-Jan-2012
// No Guarantees, Etc.

if (app.documents.length && app.selection.length == 1 && app.selection[0].hasOwnProperty("paths"))
{
if (app.version < 6)
labelItem(app.selection[0]);
else
app.doScript(labelItem, ScriptLanguage.JAVASCRIPT, app.selection[0], UndoModes.ENTIRE_SCRIPT, "Label Image Size");
} else
{
alert ("No valid selection.\nPlease select one single object with the black arrow before running this script.");
}

function labelItem (item)
{
// Save current selected layer because adding one will make it active!
activeLayer = app.activeDocument.layoutWindows[0].activeLayer;
// Make sure the layer "ImageSize" exists
try {
app.activeDocument.layers.add({name:"ImageLabel", ignoreWrap:true, layerColor: [90,192,90], printable: false});
} catch (_) { }
reportLayer = app.activeDocument.layers.item("ImageLabel");

// Make sure the swatch "ImageGreen" exists
try {
app.activeDocument.colors.add({name:"ImageLabel", space:ColorSpace.RGB, colorValue:[90,192,90], colorModel:ColorModel.PROCESS});
} catch (_) { }
reportGreen = app.activeDocument.swatches.item("ImageLabel");

// Make sure the paragraph style "ImageSize" exists
try {
app.activeDocument.paragraphStyles.add({name:"ImageLabel", appliedFont:"Arial", pointSize:12, fillColor:reportGreen, justification: Justification.CENTER_ALIGN});
} catch (_) { }
reportStyle = app.activeDocument.paragraphStyles.item("ImageLabel");

// Make sure measurement units are in inches
hmmu = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
vmmu = app.activeDocument.viewPreferences.verticalMeasurementUnits;
app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
// .. and Smart Quotes is Off
sqt = app.activeDocument.textPreferences.typographersQuotes;
app.activeDocument.textPreferences.typographersQuotes = false;
// Save all of the previous settings to be able to restore them later 🙂

// fetch width and height for the numbers, left and bottom for the lines
gb = item.geometricBounds;
// gb now holds [ top, left, bottom, right ] values -- get shorthand values
top = gb[0];
left = gb[1];
bottom = gb[2];
right = gb[3];

width = Math.round(Math.abs(right - left)*1000)/1000;
height= Math.round(Math.abs(bottom - top)*1000)/1000;

// Retrieve the current page.
// Actually, in CS5 and newer, page items have a property for this (parentPage),
// but I don't have that one near, and it's also nicer to make it work in CS4
// (and possibly even in older versions).
pg = item.parent;
while (1)
{
if (pg instanceof InsertionPoint)
pg = pg.parentTextframes[0];
if (pg instanceof Document || pg instanceof Spread || pg instanceof Page)
break;
pg = pg.parent;
}
// Draw text frame #1: Height
// Put it at the left of the selection, 0.5" wide and 0.2" off the left side
frh = pg.textFrames.add(reportLayer, {geometricBounds:[ top, left - 0.7, top + height, left - 0.2 ],
textFramePreferences: {verticalJustification: VerticalJustification.CENTER_ALIGN,
ignoreWrap: true } });
// ... and put text into it.
frh.insertionPoints[0].appliedParagraphStyle = reportStyle;
frh.contents = String(height)+'"';

// Draw text frame #2: Width
// Put it at 0.2" off the bottom of the selection, 0.25" high, full width for convenience
frw = pg.textFrames.add(reportLayer, {geometricBounds:[ bottom + 0.2, left, bottom + 0.2 + 0.25, left + width ],
textFramePreferences: {verticalJustification: VerticalJustification.CENTER_ALIGN,
ignoreWrap: true } });
// ... and put text into it.
frw.insertionPoints[0].appliedParagraphStyle = reportStyle;
frw.contents = String(width)+'"';

// Add vertical (height) line
lnh = pg.graphicLines.add (reportLayer, {strokeColor:reportGreen, strokeWeight:0.5});
// It appears in a default position so move it to the right one
lnh.paths[0].entirePath = [ [left - 0.15, top ], [left - 0.15, bottom ] ];
// add top stroke; it's 0.05" wide so offset left and right with 0.025"
lnh.paths.add ({ entirePath:[ [left-0.15 - 0.025, top ], [left-0.15 + 0.025, top] ] });
// add bottom stroke
lnh.paths.add ({ entirePath:[ [left-0.15 - 0.025, bottom ], [left-0.15 + 0.025, bottom] ] });

// Add horizontal (width) line
lnw = pg.graphicLines.add (reportLayer, {strokeColor:reportGreen, strokeWeight:0.5});
// Again we move it to the right position
lnw.paths[0].entirePath = [ [left, bottom + 0.15 ], [right, bottom + 0.15 ] ];
// Add end caps as above
lnw.paths.add ({ entirePath:[ [left, bottom+0.15 - 0.025 ], [left, bottom+0.15 + 0.025] ] });
lnw.paths.add ({ entirePath:[ [right, bottom+0.15 - 0.025 ], [right, bottom+0.15 + 0.025] ] });

// At this point we added four items: 2 text frames and 2 graphic lines.
// Group them together for convenience
app.activeDocument.groups.add ( [ frh, frw, lnh, lnw ] );

// Restore old layer selection
app.activeDocument.layoutWindows[0].activeLayer = activeLayer;

// Restore previous global settings
app.activeDocument.viewPreferences.horizontalMeasurementUnits = hmmu;
app.activeDocument.viewPreferences.verticalMeasurementUnits = vmmu;
app.activeDocument.textPreferences.typographersQuotes = sqt;

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2019 0
Adobe Community Professional ,
Nov 21, 2019

Copy link to clipboard

Copied

Hi mosheyfri,

I think the answer is in the linked thread.

Somewhere in the script's code a font is defined to be used for a new paragraph style.

That font is not installed with your system. Could be "Helvetica".

So change that to e.g. "Arial". You are on Windows, so "Arial" should be available.

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 21, 2019 1
danezeq LATEST
Explorer ,
Jun 07, 2020

Copy link to clipboard

Copied

Can someone help change the ft units to mm?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 07, 2020 0