79250926

Date: 2024-12-04 11:17:49
Score: 1
Natty:
Report link

As suggeste by @Geert Bellekens I had a try with Document Script Fragment and managed to document enumeration data types in a table (each enum in separate row, code and description in separate columns).

my solution approach:

Create a custom template with a template fragment 'templateSelector' in the element > section.

template_userManual

The fragment 'templateSelector' contains just a custom > section

fragment_templateSelector

In the Document Options of the fragment, go to 'Custom Query' and select 'Document Script' as template fragment type and select via the dropdown the Custom Script ('getAttributeAndType') to get the attributes and their types (see further below). Call the script getAttributeAndType(#OBJECTID#) in the window and pass the #OBJECTID#

custom_query_window

Create a Custom Script. The Custom Script 'getAttributeAndType' gets the attribute name and notes and calls two other templates 'template_simpleType' and 'template_enumType' depending on whether the data type is simple (e.g. FLAG) or an enumeration.

!INC Local Scripts.EAConstants-JScript
 
var ENUM_TYPE_TEMPLATE = "template_enumType";
var SIMPLE_TYPE_TEMPLATE = "template_simpleType";
 
function getAttributeAndType(objectID)
{
    var docGenerator as EA.DocumentGenerator;
        docGenerator = Repository.CreateDocumentGenerator();
        if ( docGenerator.NewDocument("") )
        {  
            try
            {
                var currentElement as EA.Element;
                    currentElement = Repository.GetElementByID(objectID);
            
                var attributesCollection as EA.Collection;
                    attributesCollection = currentElement.Attributes;
                
                for ( var i = 0; i < attributesCollection.Count; i++) {
                    
                    var currentAttribute as EA.Attribute;
                        currentAttribute = attributesCollection.GetAt(i);
                    
                    docGenerator.InsertText("Attribute: " + currentAttribute.Name,"");
                    docGenerator.InsertText("\n","");
                    docGenerator.InsertText(currentAttribute.Notes,"");
                    
                    var currentAttributeTypeElement as EA.Element;
                        currentAttributeTypeElement = Repository.GetElementByID(currentAttribute.ClassifierID);
                    
                    if(currentAttributeTypeElement.Type == "Enumeration")
                        docGenerator.DocumentElement(currentAttributeTypeElement.ElementID,1,ENUM_TYPE_TEMPLATE);
                    
                    else if(currentAttributeTypeElement.Type == "DataType")
                        docGenerator.DocumentElement(currentAttributeTypeElement.ElementID,1,SIMPLE_TYPE_TEMPLATE);
                    
                    else Session.Output("Data type not recognized");
                }
            }
            catch(e)
            {
                Session.Output(e);
            }
            var rtf = docGenerator.GetDocumentAsRTF();
            
            return rtf;
            
        }
     
    return "";
} 

The two templates being called by the script look as follows:

template_enumType:

template_enumType

template_simpleType:

template_simpleType

All in all, you need a three templates, one fragment and one script. The first template calls the fragment, the fragment calls the script, the script calls the other two templates.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Geert
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: BAAM