Hi,
Here you are:
var mydoc = app.activeDocument, pstyles = mydoc.allParagraphStyles, cont, myResults, txfm, cstyles = mydoc.allCharacterStyles, mParaOSt = mydoc.objectStyles.item("mAnchored_PStInfo"), mCharOSt = mydoc.objectStyles.item("mAnchored_CStInfo"), which_P_Occurrence = 0, // 1 - first 0 or other than 1 - each occurrence which_C_Occurrence = 1; // 1 - first 0 or other than 1 - each occurrence if (!mParaOSt.isValid) mParaOSt = mydoc.objectStyles.add({name: "mAnchored_PStInfo"}); with (mParaOSt) { enableAnchoredObjectOptions = true; enableTextFrameGeneralOptions = true; enableStroke = true; textFramePreferences.insetSpacing = 1; strokeWeight = .5; strokeColor = "blue"; with (anchoredObjectSettings) { spineRelative = true; anchorPoint = AnchorPoint.TOP_RIGHT_ANCHOR; anchoredPosition = AnchorPosition.ANCHORED; anchorYoffset = 0; anchorXoffset = 0; horizontalAlignment = HorizontalAlignment.LEFT_ALIGN; horizontalReferencePoint = AnchoredRelativeTo.PAGE_MARGINS; verticalAlignment = VerticalAlignment.TOP_ALIGN; verticalReferencePoint = VerticallyRelativeTo.CAPHEIGHT; } } if (!mCharOSt.isValid) mCharOSt = mydoc.objectStyles.add({name: "mAnchored_CStInfo"}); with (mCharOSt) { enableAnchoredObjectOptions = true; enableTextFrameGeneralOptions = true; enableStroke = true; textFramePreferences.insetSpacing = 1; strokeWeight = .5; strokeColor = "red"; with (anchoredObjectSettings) { spineRelative = true; anchorPoint = AnchorPoint.TOP_RIGHT_ANCHOR; anchoredPosition = AnchorPosition.ANCHORED; anchorYoffset = 0; anchorXoffset = 0; horizontalAlignment = HorizontalAlignment.LEFT_ALIGN; horizontalReferencePoint = AnchoredRelativeTo.PAGE_MARGINS; verticalAlignment = VerticalAlignment.TOP_ALIGN; verticalReferencePoint = VerticallyRelativeTo.CAPHEIGHT; } } for (var i= 1; i<cstyles.length;i++){ cont = cstyles[i].name; app.findTextPreferences = NothingEnum.nothing; app.findTextPreferences.appliedCharacterStyle = cont; myResults = mydoc.findText(); if (which_C_Occurrence == 1) len = Math.min(1, myResults.length); else len = myResults.length; while (len-->0) { if (myResults[len].parentTextFrames[0] == null) continue; txfm = myResults[len].insertionPoints[0].textFrames.add(); currGB = txfm.geometricBounds; txfm.appliedObjectStyle = mCharOSt; with (txfm) { geometricBounds = [ currGB[0], currGB[1], currGB[0] + 40, currGB[1] + 150 ]; contents = cont; fit(FitOptions.FRAME_TO_CONTENT); } } } for (var i= 2; i<pstyles.length;i++){ cont = pstyles[i].name; app.findTextPreferences = NothingEnum.nothing; app.findTextPreferences.appliedParagraphStyle = cont; myResults = mydoc.findText(); if (which_P_Occurrence == 1) len = Math.min(1, myResults.length); else len = myResults.length; while (len-->0) { if (myResults[len].parentTextFrames[0] == null) continue; txfm = myResults[len].insertionPoints[0].textFrames.add(); currGB = txfm.geometricBounds; txfm.appliedObjectStyle = mParaOSt; with (txfm) { geometricBounds = [ currGB[0], currGB[1], currGB[0] + 40, currGB[1] + 150 ]; contents = cont; fit(FitOptions.FRAME_TO_CONTENT); } } } app.findTextPreferences = NothingEnum.nothing;
Assumed:
- Defined colors "red" and "blue" in active document
- objectStyle for paraStyles is named mAnchored_PStInfo (if not defined ==> script creates it)
- objectStyle for charStyles is named mAnchored_CStInfo (if not defined ==> script creates it)
- set which_P_Occurrence and which_C_Occurrence to determine if info supposed to be repeated for particular style
Jarek