• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Setting up a character format

Community Expert ,
Nov 22, 2016 Nov 22, 2016

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

404

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
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 23, 2016 Nov 23, 2016

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

Votes

Translate

Translate
Community Expert ,
Nov 23, 2016 Nov 23, 2016

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
Nov 23, 2016 Nov 23, 2016

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
Nov 24, 2016 Nov 24, 2016

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines