How do I display links from all modules (opened or closed) in DOORS DXL?

Tags: dxl doors
By : KronoS
Source: Stackoverflow.com
Question!

I'm writing a DXL script that is following links through multiple levels. I've noticed that the script correctly iterates through these links when the modules are open. However, there are approximately 20 modules to iterate through and I don't want to open all of these modules. How do I view these links without having to manually open the linked modules?

Here's an example of my code:

// Checks to see if the object exists or not.  If not returns a null.  
//  This will be eventually adapted to make sure the object is from a 
//  specific set of modules, but for now we're just checking for ability
//  to retrieve
Object getObject(Link obj_link) {
    ModuleVersion other_ver = null
    ModName_ other_mod = null
    Object other_obj

    other_ver = sourceVersion obj_link
    other_mod = module(other_ver)
    if (null other_mod || isDeleted other_mod) return null

    other_obj = source obj_link
    if (null other_obj) load(other_ver, true)
    other_obj = source obj_link
    if (isDeleted other_obj) return null

    return other_obj
}

// Displays the object from a specific link module if it's found
void showOut(Object o) {
    Link l_obj_link
    string s = null

    Item linkModItem = itemFromID(MODULE_ID)
    string linkModName = fullName(linkModItem)

    for l_obj_link in all(o <- linkModName) do {

        Object test_obj
        display("Test")
        test_obj = getObject(l_obj_link)
        if (null test_obj){
            display("Null Object Found")
        } else {
            s = probeRichAttr_(test_obj, "Object Identifier", false)
            displayRich(s)
        }
    }
}

// Call showOut for the object
showOut(obj)

Again, using this as a Layout DXL script I can see the object ID if and only if the linked module is opened.

By : KronoS


Answers

You need to load the module using the link references (LinkRef). Here's a simple function that loads all the modules for a specific LinkModule and Object:

// Loads all incoming linked modules for the given link module and Object.  To load from 
//  ALL link modules use the linkModName = "*"
void LoadSourceModules(string linkModName, Object o) {
    ModName_ otherMod = null
    LinkRef lr

    // For each incoming link check to see if the moduel exists, isn't deleted and loaded
    //  if not loaded `(null data(sourceVersion lr))` then load the module.
    for lr in all(o<-linkModName) do {
        otherMod = module(sourceVersion lr)
        if (!null otherMod) {
            if ((!isDeleted otherMod) && (null data(sourceVersion lr))) {
                load((sourceVersion lr), false)
            }
        }
    }
}
By : KronoS


First of all, I would recommend using the Analysis -> Wizard and be sure to select the option for All Modules instead of All Open Modules to generate all the code for you instead, then modify that code to display what you want if it doesn't give you exactly what you need.

However, if you just want to update your existing code you need to change your getObject function to include opening each module silently (to get the information the module must be open, but it doesn't need to be visible).

Object getObject(Link obj_link) {
  ModuleVersion other_ver = null
  ModName_ other_mod = null
  Object other_obj

  other_ver = sourceVersion obj_link
  other_mod = module(other_ver)
  Module m = read(fullName(other_ver), false)  // false, tells it to open silently.
  if (null other_mod || isDeleted other_mod) return null

  other_obj = source obj_link
  if (null other_obj) load(other_ver, true)
  other_obj = source obj_link
  if (isDeleted other_obj) return null

  return other_obj
}

This should work as well but I would still recommend starting with the analysis wizard instead because it would be cleaner.



This video can help you solving your question :)
By: admin