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.
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.
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?
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.
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[i].propVal.sval = "Title2"; elementDef.SetProps (props);
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.
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";
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
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.
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 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.
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.