Lesson 10 - extending to package documentation

Hi,

Lesson 10 demonstrates how to extract documentation of Part Definitions and Usages. I wish to experiment extending that to other element types, for example, documentation of the package.

In the lesson 10 directory, adding a doc to the top level package:

// L10_AnnotatedWorkshop.sysml
package L10_AnnotatedWorkshop {
    doc locale "en_US"
    /* package documentation text */

// ...

then modifying the script to add `syside.Package` to the list of element types:

# L10_extract_documentation.py
# ...
    # Iterate through all part definitions and part usages
    for element in model.elements(syside.Type, include_subtypes=True):
        if type(element) in [syside.PartDefinition, syside.PartUsage, syside.Package]:  # <-- here
# ...

Does not result in the new documentation getting picked up:

# ...
Total documentation entries: 7  # as before...

Any idea what is missing?

Thanks

Sean

model.elements(syside.Type, include_subtypes=True) returns Types only, whereas Packages are not Types. Change the iteration to model.elements(syside.Namespace, include_subtypes=True) instead.

PS: iteration can be more efficient by inverting the statements so that it doesn’t iterate discarded elements altogether:

    for type in [syside.PartDefinition, syside.PartUsage, syside.Package]:
        for element in model.elements(type, include_subtypes=False):
1 Like

Hi Daumantas,

thanks very much for the very quick reply!

Yep, that was the mistake. FYI using variable name `type` caused a clash with the `type(element)._name_` call later in the script. Quick fix changing `type` to `nodeType`.

Thanks again,

sean