Quantcast
Channel: Adobe Community: Message List - FrameMaker Scripting
Viewing all articles
Browse latest Browse all 3715

Re: Getting and setting attribute values [ExtendScript]

$
0
0

Hi,

 

I know this is an old thread but I ran across the same question and was helped by it. I came up with a different way that I think might be a little bit cleaner, more closely modeled to the FDK methodology. So, I thought I'd post it in case it might help anyone.

 

The following function sets an attribute value by name or index. Send an empty string to look by index or a negative index to look by name. Attribute indexes start at zero and follow the sequence in which the attributes appear in the Structure View.

 

It will replace any current attribute contents. It returns true if it thinks the operation was successful.

 

function elem_SetAttribute(elem, attrName, attrIndex, newValue)

{

    var returnVal = false;

   

    var attrs = elem.Attributes;

 

    for(var i=0 ; i < attrs.length; i++)

    {

        if (attrs[i].name == attrName ||

            i == attrIndex)

        {

            attrs[i].values = new Strings();

            attrs[i].values.push(newValue);

           

            elem.Attributes = attrs;

            i = attrs.length;

            returnVal = true;

        }

    }

 

    return returnVal;

}


Viewing all articles
Browse latest Browse all 3715

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>