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

Rename ElementDef

New Here ,
Jun 02, 2016 Jun 02, 2016

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

592

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 , Jun 02, 2016 Jun 02, 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

Votes

Translate

Translate
Advocate ,
Jun 02, 2016 Jun 02, 2016

Copy link to clipboard

Copied

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

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
New Here ,
Jun 02, 2016 Jun 02, 2016

Copy link to clipboard

Copied

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.

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
Advocate ,
Jun 02, 2016 Jun 02, 2016

Copy link to clipboard

Copied

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?

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
New Here ,
Jun 02, 2016 Jun 02, 2016

Copy link to clipboard

Copied

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.

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 ,
Jun 02, 2016 Jun 02, 2016

Copy link to clipboard

Copied

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

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
New Here ,
Jun 03, 2016 Jun 03, 2016

Copy link to clipboard

Copied

Thanks for the code. I will give both of the methods a try and see which one works better in the process.

Thanks for keeping it simple for me. I am new to this, just started with framemaker about a week ago.

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
Advocate ,
Jun 02, 2016 Jun 02, 2016

Copy link to clipboard

Copied

Hi Ethan,

Yes, the read-write rules are in a text file that is used by the structured application which saves the FM file to XML.

You set up your own structured application (go to Edit Application Definitions) and name it whatever you want. Link your read-write rules to it. Then in a script use the Save method and call out your structured application. Takes a bit of trying to make it work, but with 100s of files to process, this is worth it.

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
Mentor ,
Jun 03, 2016 Jun 03, 2016

Copy link to clipboard

Copied

Rick, you are smarter than me about this stuff. Why doesn't this work? How do I know when I have to use GetProps()/SetProps()?

var doc = app.ActiveDoc; 

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

elementDef.Name  = "Title2"; 

Russ

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 ,
Jun 03, 2016 Jun 03, 2016

Copy link to clipboard

Copied

Hi Russ, It is funny that you should ask. I tried your approach with FrameScript and it does work, even though it doesn't work with ExtendScript. So, the less-than-technical answer is: I try the simple approach and if it doesn't work, I use the GetProps/SetProps method. I am curious about how this would be done in the FDK. Would the "simple" approach work? -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
Advisor ,
Jun 03, 2016 Jun 03, 2016

Copy link to clipboard

Copied

Jang,

   R/w rules need not be text files. They can be structured or unstructured FM files as well. I have a structured template for r/w rules, although it needs to be updated to recent releases of FM. I'll try to get that done in the next week or two and make it available.

   The structured template prevents syntax errors. Its Element Catalog and Smart Catalog make editing easy just as they do in any structured document. While the Structured Application Designer that is available on the StructureTools menu also prevents syntax errors and reminds the user about available rules, the structured template offers significant advantages over the Structured Application Designer. In particular:

  • To create multiple similar rules, the user can copy an existing rule and modify it.
  • Users can see multiple completed rules when editing the file.
  • Comments are permitted.
  • Rules can be divided into sections. Section titles are formatted as comments and hence are ignored when FM processes the rules.

              --Lynne

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
Advocate ,
Jun 03, 2016 Jun 03, 2016

Copy link to clipboard

Copied

Hi Lynne,

I am aware of that, but I did not want to make things too complicated for Ethan, as he appears to be a beginner in structured FM. In fact, I have already created modular sets of structured FM files for conversion tables, so doing that for read-write rules would be just as straightforward.

Do you have the read-write rule app available for geeks like me to download and test it ?

Thanks

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
Advisor ,
Jun 03, 2016 Jun 03, 2016

Copy link to clipboard

Copied

LATEST

Jang,

   I haven't updated the structured rules template since FM 9. That template works for later versions of FM but does not support FM properties added to the rules since. I will try to find time to update it soon.

   --Lynne

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