Skip to main content
ethanb10986590
Participating Frequently
June 2, 2016
Answered

Rename ElementDef

  • June 2, 2016
  • 2 replies
  • 992 views

In a structured document, is there a way to remane an ElementDef. I want to search for some specific names and rename them.

Example code:

var doc = app.ActiveDoc

var elem = doc.MainFlowInDoc.HighestLevelElement;

if (elem.ElementDef.Name == "some_string"){

     //Change the name of the ElementDef here

}

I am assuming I need to use the SetProps function, something like this.

var props = elem.ElementDEf.GetProps();

var i = GetPropIndex(props, /*Constants.something_to_get_the_name*/ ) //need help here I think.

props.propVal = "some_new_string"

elem.ElementDEf.SetProps(props)

Is it possible to do this?

Thanks

Ethan

This topic has been closed for replies.
Correct answer frameexpert

If you decide to use scripting instead of Read/Write Rules, here is code that you can modify for your use. In this example, I am renaming Title elements to Title2.

#target framemaker

var doc = app.ActiveDoc;

var elementDef = doc.GetNamedElementDef ("Title");

var props = elementDef.GetProps ();

var i = GetPropIndex (props, Constants.FP_Name);

props.propVal.sval  = "Title2";

elementDef.SetProps (props);

-Rick

2 replies

4everJang
Legend
June 2, 2016

No need for scripting then. Make a full list of the elements to be renamed, then open the read-write rules for the structured application you will be using to save to XML and retag the elements in those rules. One of those rules would look like this:

element "column" is fm element "2column".

Then, when the names were corrected in the XML, use another structured application to read the file back into FrameMaker, which uses the default read-write rules. This effectively retags the elements in your FM file.

Will this work for you?

ethanb10986590
Participating Frequently
June 2, 2016

That sounds like it should work. I will give it a try.

Will those new rules be maintained after I close FrameMaker?

Also will those rules be applied if I save the document using a script. I am doing a lot of this xml conversion with a script because I have hundreds of documents that need to be converted.

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
June 2, 2016

If you decide to use scripting instead of Read/Write Rules, here is code that you can modify for your use. In this example, I am renaming Title elements to Title2.

#target framemaker

var doc = app.ActiveDoc;

var elementDef = doc.GetNamedElementDef ("Title");

var props = elementDef.GetProps ();

var i = GetPropIndex (props, Constants.FP_Name);

props.propVal.sval  = "Title2";

elementDef.SetProps (props);

-Rick

www.frameexpert.com
4everJang
Legend
June 2, 2016

Ethan,

You ask for renaming the element definition, but from your code I suspect you want to retag an element instead. Those are two very different things. And there are different ways of doing this, depending on what exactly you want to achieve.

Jang

ethanb10986590
Participating Frequently
June 2, 2016

I guess retaging is what I want.

I have a structured FM file that I want to export to xml, but there are some tags in the FM doc that begin with a number (ex. "2column"), and xml doesnt allow for tags to start with numbers. I want to find those tags and change them.