11 Replies Latest reply on Aug 26, 2014 12:57 AM by poortip87

    How to get certain applied styles using script?

    poortip87 Level 1

      Hi All,

       

      I need to know how to get certain applied styles using ID Scripting. I don't have much experience in InDesign so need some help.

      Here is a screenshot with a sample text with the said styles applied and highlighted.

       

      screenshot.png

       

      I need to know what texts in my document have these styles applied like All Caps, Strikethrough, Underline, Subscript and Superscript etc.

       

      Please help.

      Thanks!

        • 1. Re: How to get certain applied styles using script?
          Trevorׅ Adobe Community Professional

          Hi Poortip87

           

          The first thing you have to understand is how to refer to "where" you want to apply the style.

          If you want the script to apply the style to the selected text then you would use for example app.selection[0].strikeThru = true;

          If you for example want to underline the last word of the first paragraph of the first story you would use app.activeDocument.stories[0].paragraphs[0].words[-1].underline = true;

          If you just wanted the first letter of that word underlined then you would add .characters[0] after the words[-1]

          To for example apply All Caps to all the text in all the stories you would use

          app.activeDocument.stories.everyItem().texts[0].capitalization = Capitalization.ALL_CAPS;


          The easiest way to find how to set properties to a selections is to set them manually and make the selection and then run the script below.

          You should be able to find all the properties you want very easily after running the script.

          Or you can use Jongwares excellent reference guide. Indesign JavaScript Help

           

          HTH

           

          Trevor




          // script to show most of the selection properties by Trevor
          // Creative-Scripts.Com (Still not ready!) available (sometimes) for custom scripts $$$
          // scripts {at} Creative-Scripts [dot] Com
          $.level = 0; // set debug mode to allow try catch (not read only as stated in manual);
          if (!app.selection.length) exit();
          var c = 0, s = app.selection[0], p,
                a = [], n, er;
          for (n in s) {
              try {
                  p = s[n];
                  if (p && p.constructor.name === "Enumerator") p = getEnum(p ,n);
                  a[c++] = n + ": " + p;
              } catch (er) {a[c++] = n + ": ???"}
          }
          var f = new File (Folder.temp + +(new Date) + ".txt");
          f.open('r');
          f.encoding = "UTF-8";
          f.lineFeed = ($.os[0]=="M") ? "Macintosh" :" Windows";
          f.open('w');
          f.write("\uFEFF" + a.join("\r"));
          f.close();
          $.sleep(300);
          f.execute(true);
          
          function getEnum (q, n) {
              var enums = ["AcrobatCompatibility",
              "AddPageOptions",
              "AdornmentOverprint",
              "AlignDistributeBounds",
              "AlignOptions",
              "AlignmentStyleOptions",
              "AlternateGlyphForms",
              "AlternatingFillsTypes",
              "AnchorPoint",
              "AnchorPosition",
              "AnchoredRelativeTo",
              "AnimationEaseOptions",
              "AnimationPlayOperations",
              "AntiAliasType",
              "ArrangeBy",
              "ArrowHead",
              "AssetType",
              "AssignmentExportOptions",
              "AssignmentStatus",
              "AutoEnum",
              "AutoSizingReferenceEnum",
              "AutoSizingTypeEnum",
              "BalanceLinesStyle",
              "BaselineFrameGridRelativeOption",
              "BaselineGridRelativeOption",
              "BehaviorEvents",
              "BevelAndEmbossDirection",
              "BevelAndEmbossStyle",
              "BevelAndEmbossTechnique",
              "BindingOptions",
              "BitmapCompression",
              "BlendMode",
              "BlendingSpace",
              "BookContentStatus",
              "BookletTypeOptions",
              "BoundingBoxLimits",
              "BuildingBlockTypes",
              "BulletCharacterType",
              "BulletListExportOption",
              "Capitalization",
              "ChangeBackgroundColorChoices",
              "ChangeCaseOptions",
              "ChangeConditionsModes",
              "ChangeMarkings",
              "ChangeTextColorChoices",
              "ChangeTypes",
              "ChangebarLocations",
              "ChangecaseMode",
              "ChapterNumberSources",
              "CharacterAlignment",
              "CharacterCountLocation",
              "CharacterDirectionOptions",
              "ClippingPathType",
              "ColorModel",
              "ColorOutputModes",
              "ColorRenderingDictionary",
              "ColorSettingsPolicy",
              "ColorSpace",
              "ComposeUsing",
              "CompressionQuality",
              "ConditionIndicatorMethod",
              "ConditionIndicatorMode",
              "ConditionUnderlineIndicatorAppearance",
              "ContainerType",
              "ContentType",
              "ContourOptionsTypes",
              "ConvertPageBreaks",
              "ConvertShapeOptions",
              "ConvertTablesOptions",
              "CoordinateSpaces",
              "CopyrightStatus",
              "CornerOptions",
              "CreateProxy",
              "CrossReferenceType",
              "CursorTypes",
              "CustomLayoutTypeEnum",
              "DataFormat",
              "DefaultRenderingIntent",
              "DesignOptions",
              "DiacriticPositionOptions",
              "DigitsTypeOptions",
              "DimensionsConstraints",
              "DisplayOrderOptions",
              "DisplaySettingOptions",
              "DistributeOptions",
              "DocumentIntentOptions",
              "DocumentPrintUiOptions",
              "DynamicDocumentsJPEGQualityOptions",
              "DynamicDocumentsTextExportPolicy",
              "DynamicMediaHandlingOptions",
              "DynamicTriggerEvents",
              "EPSColorSpace",
              "EPSImageData",
              "EditingState",
              "EmptyFrameFittingOptions",
              "EndCap",
              "EndJoin",
              "EpubCover",
              "EpubVersion",
              "EventPhases",
              "ExportFormat",
              "ExportLayerOptions",
              "ExportOrder",
              "ExportPresetFormat",
              "ExportRangeOrAllPages",
              "FeatherCornerType",
              "FeatherMode",
              "FeatureSetOptions",
              "FindChangeTransliterateCharacterTypes",
              "FirstBaseline",
              "FitDimension",
              "FitMethodSettings",
              "FitOptions",
              "Fitting",
              "FlattenerLevel",
              "Flip",
              "FlipValues",
              "FloatingWindowPosition",
              "FloatingWindowSize",
              "FollowShapeModeOptions",
              "FontDownloading",
              "FontEmbedding",
              "FontStatus",
              "FontTypes",
              "FootnoteFirstBaseline",
              "FootnoteMarkerPositioning",
              "FootnoteNumberingStyle",
              "FootnotePrefixSuffix",
              "FootnoteRestarting",
              "GIFOptionsPalette",
              "GlobalClashResolutionStrategy",
              "GlobalClashResolutionStrategyForMasterPage",
              "GlowTechnique",
              "GoToZoomOptions",
              "GradientType",
              "GridAlignment",
              "GridViewSettings",
              "GuideTypeOptions",
              "HeaderFooterBreakTypes",
              "HeaderTypes",
              "HorizontalAlignment",
              "HorizontalOrVertical",
              "HyperlinkAppearanceHighlight",
              "HyperlinkAppearanceStyle",
              "HyperlinkAppearanceWidth",
              "HyperlinkDestinationPageSetting",
              "ICCProfiles",
              "IconSizes",
              "ImageAlignmentType",
              "ImageConversion",
              "ImageDataTypes",
              "ImageExportOption",
              "ImageFormat",
              "ImagePageBreakType",
              "ImageResolution",
              "ImageSizeOption",
              "ImportFormat",
              "ImportPlatform",
              "ImportedPageCropOptions",
              "InCopyUIColors",
              "IndexCapitalizationOptions",
              "IndexFormat",
              "InkTypes",
              "InnerGlowSource",
              "InteractiveElementsOptions",
              "InteractivePDFInteractiveElementsOptions",
              "JPEGOptionsFormat",
              "JPEGOptionsQuality",
              "JoinOptions",
              "JpegColorSpaceEnum",
              "Justification",
              "KashidasOptions",
              "KentenAlignment",
              "KentenCharacter",
              "KentenCharacterSet",
              "KinsokuHangTypes",
              "KinsokuSet",
              "KinsokuType",
              "LanguageAndRegion",
              "LayoutRuleOptions",
              "Leading",
              "LeadingModel",
              "LibraryPanelViews",
              "LineAlignment",
              "LineSpacingType",
              "LinkStatus",
              "ListAlignment",
              "ListType",
              "LiveDrawingOptions",
              "Locale",
              "LocationOptions",
              "LockStateValues",
              "MapType",
              "MarkLineWeight",
              "MarkTypes",
              "MatrixContent",
              "MeasurementUnits",
              "MojikumiTableDefaults",
              "MonoBitmapCompression",
              "MoviePlayOperations",
              "MoviePosterTypes",
              "NestedStyleDelimiters",
              "NoteBackgrounds",
              "NoteColorChoices",
              "NothingEnum",
              "NumberedListExportOption",
              "NumberedParagraphsOptions",
              "NumberingStyle",
              "OTFFigureStyle",
              "ObjectTypes",
              "OpenOptions",
              "OpenTypeFeature",
              "OutlineJoin",
              "OverrideType",
              "PDFColorSpace",
              "PDFCompressionType",
              "PDFCrop",
              "PDFJPEGQualityOptions",
              "PDFMarkWeight",
              "PDFProfileSelector",
              "PDFRasterCompressionOptions",
              "PDFXStandards",
              "PNGColorSpaceEnum",
              "PNGExportRangeEnum",
              "PNGQualityEnum",
              "PPDValues",
              "PageBindingOptions",
              "PageColorOptions",
              "PageLayoutOptions",
              "PageNumberPosition",
              "PageNumberStyle",
              "PageNumberingOptions",
              "PageOrientation",
              "PagePositions",
              "PageRange",
              "PageReferenceType",
              "PageSideOptions",
              "PageTransitionDirectionOptions",
              "PageTransitionDurationOptions",
              "PageTransitionOverrideOptions",
              "PageTransitionTypeOptions",
              "PageViewOptions",
              "PaginationOption",
              "PanelLayoutResize",
              "PanningTypes",
              "PaperSize",
              "PaperSizes",
              "ParagraphDirectionOptions",
              "ParagraphJustificationOptions",
              "PathType",
              "PathTypeAlignments",
              "PdfMagnificationOptions",
              "PerformanceMetricOptions",
              "PlacedVectorProfilePolicy",
              "PlayOperations",
              "PointType",
              "Position",
              "PositionalForms",
              "PostScriptLevels",
              "PreflightLayerOptions",
              "PreflightProfileOptions",
              "PreflightRuleFlag",
              "PreflightScopeOptions",
              "PreviewPagesOptions",
              "PreviewSizeOptions",
              "PreviewTypes",
              "PrintLayerOptions",
              "PrintPageOrientation",
              "Printer",
              "PrinterPresetTypes",
              "Profile",
              "ProofingType",
              "RangeSortOrder",
              "RasterCompressionOptions",
              "RasterResolutionOptions",
              "RecordSelection",
              "RecordsPerPage",
              "RenderingIntent",
              "RepaginateOption",
              "ResizeConstraints",
              "ResizeMethods",
              "ResolveStyleClash",
              "RestartPolicy",
              "RotationDirection",
              "RowTypes",
              "RubyAlignments",
              "RubyKentenPosition",
              "RubyOverhang",
              "RubyParentSpacing",
              "RubyTypes",
              "RuleDataType",
              "RuleWidth",
              "RulerOrigin",
              "SWFBackgroundOptions",
              "SWFCurveQualityValue",
              "Sampling",
              "SaveOptions",
              "ScaleModes",
              "Screeening",
              "ScreenModeOptions",
              "ScriptLanguage",
              "SearchModes",
              "SearchStrategies",
              "SelectAll",
              "SelectionOptions",
              "Sequences",
              "ShadowMode",
              "SignatureSizeOptions",
              "SingleWordJustification",
              "SmartMatchOptions",
              "SnapshotBlendingModes",
              "SortAssets",
              "SoundPosterTypes",
              "SourceFieldType",
              "SourceSpaces",
              "SourceType",
              "SpanColumnCountOptions",
              "SpanColumnTypeOptions",
              "SpecialCharacters",
              "SpreadFlattenerLevel",
              "StartParagraph",
              "StateTypes",
              "StaticAlignmentOptions",
              "StoryDirectionOptions",
              "StoryHorizontalOrVertical",
              "StoryTypes",
              "StrokeAlignment",
              "StrokeCornerAdjustment",
              "StrokeFillProxyOptions",
              "StrokeFillTargetOptions",
              "StrokeOrderTypes",
              "StyleConflict",
              "StyleSheetExportOption",
              "SyncConflictResolution",
              "TabStopAlignment",
              "TableDirectionOptions",
              "TableFormattingOptions",
              "TagRaster",
              "TagTextExportCharacterSet",
              "TagTextForm",
              "TagTransparency",
              "TagType",
              "TagVector",
              "TaggedPDFStructureOrderOptions",
              "TaskAlertType",
              "TaskState",
              "TextExportCharacterSet",
              "TextFrameContents",
              "TextImportCharacterSet",
              "TextPathEffects",
              "TextStrokeAlign",
              "TextTypeAlignments",
              "TextWrapModes",
              "TextWrapSideOptions",
              "ThumbsPerPage",
              "TilingTypes",
              "ToolTipOptions",
              "ToolsPanelOptions",
              "TrapEndTypes",
              "TrapImagePlacementTypes",
              "Trapping",
              "UIColors",
              "UITools",
              "UndoModes",
              "UpdateLinkOptions",
              "UserInteractionLevels",
              "VariableNumberingStyles",
              "VariableScopes",
              "VariableTypes",
              "VersionCueSyncStatus",
              "VersionState",
              "VerticalAlignment",
              "VerticalJustification",
              "VerticallyRelativeTo",
              "ViewDisplaySettings",
              "ViewZoomStyle",
              "WarichuAlignment",
              "WatermarkHorizontalPositionEnum",
              "WatermarkVerticalPositionEnum",
              "WhenScalingOptions",
              "XFLRasterizeFormatOptions",
              "XMLElementLocation",
              "XMLElementPosition",
              "XMLExportUntaggedTablesFormat",
              "XMLFileEncoding",
              "XMLImportStyles",
              "XMLTransformFile",
              "ZoomOptions"];
          
              var l = enums.length,
                  s = q.toString(), e, er, a;
              while (l--) {
                  try {
                      e = $.global [enums[l]];
                      if (e.hasOwnProperty (s) && q === e[s]) {
                          a = e.reflect.properties;
                          a.pop();
                          a = (a.length < 2) ? "" : "\r[Possible " + enums[l]+ " Enumerations for " + n + "]:\r" + enums[l] + "." + a.join ("\r" + enums[l] + ".");
                          return enums[l] + "." + q.toString () + a;
                      }
                  }
                  catch (er) {};
              }
              return "???." + q.toString ();
          }
          
          
          



          • 2. Re: How to get certain applied styles using script?
            Jump_Over Level 5

            Hi,

             

            As you can see - help can come with many faces.

            The main question is what kind of help are you asking:

            •     help to understand some syntax
            •     help to code some quick steps
            •     help to create entire script
            •    just create a script

             

            I prefer first three ways and, if so, I need to know

            1. what have you done till now?
            2. and where is a point you want to reach?

             

            I.e. if you say: "...I need to know what texts in my document have these styles applied... "

            I am asking: "how you need to know?"

            •      by selecting texts one by one
            •      by alerting one by one
            •      by alerting all at once
            •      by saving it in a file
            •      by sending it to an email...
            •      ... and so on

             

            Script is a set of orders so you have to be as accurate as possible.

             

            Jarek

            • 3. Re: Re: How to get certain applied styles using script?
              poortip87 Level 1

              Yes, I want to know what texts in my document have these styles applied,

              I have to create a syntax similar to html and save the output in an xml file.

               

              For eg, for underlined texts for a text frame,

              <text-container>
                   <text style="underlined">hello</text>
              </text-container>
              

               

              Something like the above.

              • 4. Re: Re: How to get certain applied styles using script?
                Trevorׅ Adobe Community Professional

                Whoops, didn't read poortip's post too carefully.

                Look like yet another "Please (at least that) write me a script."

                Enjoy

                 

                P.s. I'm not against all please write scripts request, depends on different things

                • 5. Re: Re: How to get certain applied styles using script?
                  poortip87 Level 1

                  Appreciate the honesty!

                   

                  I should have been clear in what I have been able to do. My bad!

                   

                  I have been able to get the styles for underlined, strikethrough etc.

                  What I haven't been able to get is how to detect the subscript and superscript styles.

                   

                  I wish I could have a little guidance here. I know these styles can be either nested or overridden. But still no break-through here.

                  • 6. Re: Re: How to get certain applied styles using script?
                    Trevorׅ Adobe Community Professional

                    Post the code that you used to do what you managed to do

                    • 7. Re: Re: Re: How to get certain applied styles using script?
                      poortip87 Level 1

                      The code for what I managed to do is as follows,

                       

                      GetTextFrameDetails(item:TextFrame):void
                      {
                           for each(var para:Paragraph in item.paragraphs)
                           {
                      
                           
                           for each(var tRange:TextStyleRange in para.textStyleRanges)
                                {
                                     // For unnderline
                                     isUnderline = tRange.underLine;
                      
                                     // For strikethrough
                                     isStrikeThru = tRange.strikeThru;
                      
                                     // For Capitalization
                                     capsType = tRange.capitalization;
                                     if(capsType == Capitalization.ALL_CAPS)
                                     {
                                     }
                                     else if(capsType == Capitalization.SMALL_CAPS)
                                     {
                                     }
                      
                                     else if(capsType == Capitalization.NORMAL)
                                     {
                                     }
                                }
                           }
                      }
                      

                       

                      I don't know what properties give access to subscript and superscript values.

                      • 8. Re: Re: Re: How to get certain applied styles using script?
                        Trevorׅ Adobe Community Professional

                        Use the script as instructed in 1 above and you should find the values easily

                        • 9. Re: Re: Re: How to get certain applied styles using script?
                          Trevorׅ Adobe Community Professional

                          P.s. You probably should be using FindTextPreference

                          • 10. Re: Re: Re: How to get certain applied styles using script?
                            Trevorׅ Adobe Community Professional

                            Apply formatting and make selection then run the script

                            _Sample Doc.indd @ 200%_2014-08-26_10-47-19.png

                            Look through the file for the properties you want.

                             

                            Find_2014-08-26_10-50-57.png

                            Pretty easy

                            • 11. Re: Re: Re: Re: How to get certain applied styles using script?
                              poortip87 Level 1

                              Okay, I was able to do it..

                               

                              GetTextFrameDetails(item:TextFrame):void
                              {
                                  for each(var para:Paragraph in item.paragraphs)
                                  {
                                      for each(var tRange:TextStyleRange in para.textStyleRanges)
                                      {
                                          // For unnderline
                                          isUnderline = tRange.underLine;
                              
                              
                                          // For strikethrough
                                          isStrikeThru = tRange.strikeThru;
                              
                              
                                          // For Capitalization
                                          capsType = tRange.capitalization;
                                          if(capsType == Capitalization.ALL_CAPS)
                                          {
                                          }
                                          else if(capsType == Capitalization.SMALL_CAPS)
                                          {
                                          }
                                          else if(capsType == Capitalization.NORMAL)
                                          {
                                          }
                                      
                                          // For subscript, superscript
                                          if (Position.SUBSCRIPT == tRange.position)
                                              $.writeln("subscript");
                                          else if (Position.SUPERSCRIPT == tRange.position)
                                              $.writeln("superscript");
                                          else if (Position.NORMAL == tRange.position)
                                              $.writeln("normal");
                                      }
                                  }
                              }
                              

                               

                               

                              Thanks!