3 Replies Latest reply on Nov 24, 2016 12:36 AM by K.Daube

    Setting up a character format

    K.Daube Level 1

      Dear friends,

       

      It's quite easy to set up a new character format with 'all AsIs', but I have not found the necessary ingredients to set up one with particular properties:
      a) name = superscript:     all AsIs, but superscript
      b) name = highlight:         all AsIs, but a colour (from the standard set)
      Hence I had the idea to call the Character Designer by means of F-codes.
      Well - it opens, but I do not see how to set the dialogue to "All AsIs" - because the user normally has its cursor somewhere in the document and the really defined properties are only seen if the cursor is outside the document.
      So far I'm here:

      function DefineCharFmt (sName, oDoc, bProperty) {
      var charFmt = 0, fcode = [],  msg;  
        msg = "Character format '" + sName + "' does not exist in catalogue\nShall it be created?";
        charFmt = oDoc.GetNamedCharFmt (sName);  
        if (!charFmt.ObjectValid()) {                   // does not exist in catalogue
          if (confirm (msg, false, "Confirm new character format")) {
            charFmt = oDoc.NewNamedObject (Constants.FO_CharFmt, sName);
            if (bProperty) {                   
              fcode[0] = FCodes.CHAR_DESIGN_CAT;       // Open Charactr designer to set the property 
      //      fcode[1] = FCodes.CHAR_DESIGNKIT_RESET;   // nothing to do with Set AsIs
                Fcodes(fcode);
            } 
            return true;
          } else {
            return false;name
          }
        }
        return true;
      } //--- end DefineCharFmt  
      


      Maybe I need to put it the other way round:
      Instruct the user that for the proper function of the script the xxx character formats must exist in the catalogue and be set up accordingly...
      Or:
      Createte the needed character formats in the catalogue - only "AsIs" and instruct the user to set them up properly to see the effect in the document.

       

      Klaus

        • 1. Re: Setting up a character format
          K.Daube Level 1

          Well, for the simple cases (only AsIs, AsIs + superscript) I'm succesful.

          But defining a colour is not that easy:

          #target framemaker
          var oDoc = app.ActiveDoc, OK;
          $.writeln (DefineCharFmt ("0-C", oDoc));    // AsIs + colour Salmon
          
          function DefineCharFmt (sName, oDoc) {
          var charFmt = 0, oColor = new Object (Color);
            charFmt = oDoc.GetNamedCharFmt (sName);  
            if (!charFmt.ObjectValid()) {                   // does not exist in catalogue
              charFmt = oDoc.NewNamedObject (Constants.FO_CharFmt, sName); // define new char format - all AsIs
              oColor.ReservedColor = Constants.FV_COLOR_SALMON; // 1 
              charFmt.UseColor = true;
              charFmt.Color = oColor;   // 2 
            } 
          } //--- end DefineCharFmt  
          

          LIne 07 creates the character format "all AsIs", to which I want to add only one property: a predefined colour.

          At line 10 an inspection of the objects shows:

             oColor.Name = Salmon; oColor.ReservedColor = 16

          But line 12 reveals:

             charFmt.Color.Name = null; charFmt.Color.ReservedColor = 0

           

          What is missing here?

          Thanks for Your help

          Klaus

          • 2. Re: Setting up a character format
            frameexpert Level 4

            Hi Klaus,

             

            Your approach with the color is not quite correct. You need this:

             

            oColor = oDoc.GetNamedColor ("Salmon");
            charFmt.UseColor = true;
            charFmt.Color = oColor;
            

             

            -Rick

            • 3. Re: Setting up a character format
              K.Daube Level 1

              Thank You Rick - this works.

              Anidea last night was to use the PropVals method - but did not get all pieces to that puzzle. What are the necessary constants (besides FV_COLOR_SALMON) and how to assign the properties to the color? Would it be something like this?

              var oProps = new PropVals() ;
              var propVal = new PropVal() ;  
                    propVal.propIdent.num = Constants.????;  
                    propVal.propVal.valType = Constants.FT_Integer;  
                    propVal.propVal.ival = Constants.FV_COLOR_SALMON;  
                    oProps.push(propVal); 
                    oColor = oColor.SetProps(oProps);
              

              It was to late in the day for these experiments...

              And the method you present is much more transparent to me. So my final codeis this:

              #target framemaker
              var oDoc = app.ActiveDoc, OK;
              OK = DefineCharFmt ("0-A", oDoc, 0, true);          // just AsIs
              $.writeln (OK);
              OK = DefineCharFmt ("0-B", oDoc, 1, false);          // AsIs + superscript
              $.writeln (OK);
              OK = DefineCharFmt ("0-C", oDoc, 2, true);          // AsIs + colour Salmon
              $.writeln (OK);
              
              function DefineCharFmt (sName, oDoc, iType, bModifyable) {
              // In        sName:  name of character format to be checked
              //           oDoc:  current document
              //           iType:  Type of character format property to set
              //                   0  all set to AsIs
              //                   1  superscript
              //                   2  predefined colour Salmon
              //           bModifyable: see msg
              // Out       false, if char format is not defined (even after user prompt)
              // Reference Rick Quatro at https://forums.adobe.com/thread/2240616 
              var msg, charFmt = 0, oColor = new Object (Color);
                msg = "Character format '" + sName + "' does not exist in catalogue\nShall it be created?";
                if (bModifyable) {
                  msg = msg + "\n\nYou may modify the character format later to your desire, e.g. other colour";
                } else {
                  msg = msg + "\n\nDo not modify the character format later!";
                }
                charFmt = oDoc.GetNamedCharFmt (sName);  
                if (!charFmt.ObjectValid()) {                  // does not exist in catalogue
                  if (confirm (msg, false, "Confirm new character format")) {
                    charFmt = oDoc.NewNamedObject (Constants.FO_CharFmt, sName); // define new char format - all AsIs
                    switch (iType) {                  
                      case 0:
                        break;
                      case 1:
                        charFmt.Position = Constants.FV_POS_SUPER; // FV_POS_NORM, FV_POS_SUB
                        break;
                      case 2:
                        oColor = oDoc.GetNamedColor ("Salmon");
                        charFmt.UseColor = true;
                        charFmt.Color = oColor;
                        break;  
                      default:
                        alert ("DefineCharFmt:\nPgm error: case " + iType + " not defined.", "DefineCharFmt", true);
                        return false;
                    } 
                    return true;
                  } else {
                    return false;                              // No character format defined
                  }
                }
                return true;
              } //--- end DefineCharFmt