Article View: adobe.scripting.indesign
Article #9775Re: Variation of Dave's Script in "How To Begin Scripting"
From: Dave_Saunders
Date: Mon, 17 Jul 2006 15:13
Date: Mon, 17 Jul 2006 15:13
44 lines
2514 bytes
2514 bytes
You grabbed my attention with this (don't ask me why -- sometimes, things just seem to demand a solution). This method will add an anchored item to an insertion point, using the default settings you've established.
InsertionPoint.prototype.addAnchor = function() {
var aDoc = app.documents[0];
var anchProps = aDoc.anchoredObjectDefaults.properties;
var anchCont = anchProps.anchorContent;
// Make new object with correct default settings
if (anchCont == ContentType.unassigned) {
var myAO = this.rectangles.add();
} else {
var myAO = this.textFrames.add();
}
// Make new object right kind of object
myAO.contentType = anchCont;
// Recompose parent story so geometricBounds make sense
this.parentStory.recompose();
//save users measurement preferences
userHoriz = aDoc.viewPreferences.horizontalMeasurementUnits;
userVert = aDoc.viewPreferences.verticalMeasurementUnits;
aDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
aDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
var myBds = myAO.geometricBounds;
myBds[0] = myBds[2] - anchProps.initialAnchorHeight;
myBds[3] = myBds[1] + anchProps.initialAnchorWidth;
myAO.geometricBounds = myBds;
aDoc.viewPreferences.horizontalMeasurementUnits = userHoriz
aDoc.viewPreferences.verticalMeasurementUnits = userVert
myAO.applyObjectStyle(anchProps.anchoredObjectStyle);
if (anchProps.anchorContent == ContentType.textType) {
try { // might be null
myAO.parentStory.appliedParagraphStyle = anchProps.anchoredParagraphStyle;
} catch (e) {}
}
myAO.anchoredObjectSettings.properties = aDoc.anchoredObjectSettings.properties;
}
Well, I think it will. I tested it using:
myIP = app.selection[0];
myIP.addAnchor();
and it seemed to work. If you try to use addAnchor() with any other kind of object, you'll get a run-time error.
Dave
Technical Details
Message-ID:
<3bc0ed94.2@webcrossing.la2eafNXanI>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!news.ecp.fr!news.stben.net!webcrossingReferences:
<3bc0ed94.-1@webcrossing.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Thread: f939a,c3f000112de732ba X-Google-Attributes: gidf939a,public X-Google-Language: ENGLISH,ASCII-7-bit From: Dave_Saunders@adobeforums.com Newsgroups: adobe.scripting.indesign Subject: Re: Variation of Dave's Script in "How To Begin Scripting" Message-ID: <3bc0ed94.2@webcrossing.la2eafNXanI> Date: Mon, 17 Jul 2006 08:13:32 -0700 References: <3bc0ed94.-1@webcrossing.la2eafNXanI> Lines: 51 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!news.ecp.fr!news.stben.net!webcrossing