Skip to main content
December 15, 2023
Answered

Unable to set spread property to a text by script

  • December 15, 2023
  • 2 replies
  • 367 views

Hi everyone,

 

Using Framemaker 17 with some javascript, I don't understand why the following code won't change the spread property of the text selection :

 

var myDoc = app.ActiveDoc;

var myProp = new PropVal();

    myProp.propIdent.num = Constants.FP_Spread ;

    myProp.propVal.valType = Constants.FT_Metric ;

    myProp.propVal.ival = 655 ;

var myTR = myDoc.TextSelection ;

myDoc.SetTextPropVal(myTR, myProp) ;


alert(myDoc.GetTextPropVal(myTR.beg, Constants.FP_Spread).propVal.ival)

 No error raised, but the alert message sadly gives '0' every time...

 

Some insight  please ?

    This topic has been closed for replies.
    Correct answer frameexpert

    Workaround: create a Character Format with the desired properties and apply that to the text.

    #target framemaker
    
    main ();
    
    function main () {
    
        var doc;
        
        doc = app.ActiveDoc;
        if (doc.ObjectValid () === 1) {
            processDoc (doc);
        }
    }
    
    function processDoc (doc) {
        
        var textRange, charFmt;
        
        // Get the selected text.
        textRange = doc.TextSelection;
        
        // Get the custom spread character format.
        charFmt = getSpreadCharFmt (doc);
    
        // Apply the character format to the selected text.
        doc.SetTextProps (textRange, charFmt.GetProps ());
    }
    
    function getSpreadCharFmt (doc) {
        
        var charFmt, PT = 65536;
        
        // See if the character format exists.
        charFmt = doc.GetNamedCharFmt ("custom-spread");
        if (charFmt.ObjectValid () === 0) {
            // Create the character format.
            charFmt = doc.NewNamedCharFmt ("custom-spread");
        }
        
        // Set the desired properties.
        charFmt.UseSpread = 1;
        charFmt.Spread = .5 * PT;
        
        return charFmt;
    }

     

    2 replies

    frameexpert
    Community Expert
    Community Expert
    December 15, 2023

    I haven't had any success setting text properties using PropVals with ExtendScript. I think I have a workaround that I will post shortly.

    frameexpert
    Community Expert
    frameexpertCommunity ExpertCorrect answer
    Community Expert
    December 15, 2023

    Workaround: create a Character Format with the desired properties and apply that to the text.

    #target framemaker
    
    main ();
    
    function main () {
    
        var doc;
        
        doc = app.ActiveDoc;
        if (doc.ObjectValid () === 1) {
            processDoc (doc);
        }
    }
    
    function processDoc (doc) {
        
        var textRange, charFmt;
        
        // Get the selected text.
        textRange = doc.TextSelection;
        
        // Get the custom spread character format.
        charFmt = getSpreadCharFmt (doc);
    
        // Apply the character format to the selected text.
        doc.SetTextProps (textRange, charFmt.GetProps ());
    }
    
    function getSpreadCharFmt (doc) {
        
        var charFmt, PT = 65536;
        
        // See if the character format exists.
        charFmt = doc.GetNamedCharFmt ("custom-spread");
        if (charFmt.ObjectValid () === 0) {
            // Create the character format.
            charFmt = doc.NewNamedCharFmt ("custom-spread");
        }
        
        // Set the desired properties.
        charFmt.UseSpread = 1;
        charFmt.Spread = .5 * PT;
        
        return charFmt;
    }

     

    December 18, 2023

    Yes, this way it works, thank you ! I think PT should be 655 and not 65536 since we usualy enter a percentage.

    It's a bit frustrating, since I'm writing a script applying different spreads a testing the resulting paragraph, but I'll deal with it like you.

     

    Have a nice day

    frameexpert
    Community Expert
    Community Expert
    December 15, 2023

    What Spread value are you trying to set if you were using the interface?

    December 15, 2023

    I am talking about the value increasing the space between characters (not between words), also called "tracking" I think. In the interface, we set a percentage, but when displaying it from a script it is given as a metric (65536 for a 0% value).