Skip to end of metadata
Go to start of metadata

Problem

Removing an element from a container in the model browser or from a diagram or view can cause faulty references within the tool. If a reference has been made to an element and it is removed from the model, it will show up in a color view as an undefined element. It will also show in other reporting features, but most common is it shows up in the color view.

While the color view is still open, look up the element that has the "faulty" statement in the legend, it will represent itself as follows:


Solution

This "faulty" reference can be removed by executing the following script:

// Remove invalid object references from profile values that are sets or lists.
// Presentation type: '-- no output --'

message "Checking for invalid collection elements...";
forall obj in modelpackage {
  forall attr in obj.attrs() {
    if ( obj.hasUserValue(attr.first) ) {
      if ( attr.second.isSet() || attr.second.isList() ) {
        new = (attr.second.isSet() ? Set() : List());
        change = false;
        forall elem in attr.second {
          if ( !elem.isObject() ) {
            change = false;
            break;
          }
          if ( elem.isValid() ) {
            new.add( elem );
          }
          else {
            change = true;
          }
        }
        if ( change ) {
          message "Removed " + (attr.second.size() - new.size()).toString() + " invalid element(s) from attribute '" + translate(attr.first.name()) + "' on object '" + obj.name() + "'.", List(obj);
          obj.setAttrValue( attr.first, !new.empty() ? new : undefined );
        }
      }
      else if(attr.second.isObject()) {
        if(!attr.second.isValid()) {
          message "Removed invalid element from attribute '" + translate(attr.first.name()) + "' on object '" + obj.name() + "'.", List(obj);
          obj.resetAttrValue(attr.first);
        }
      }
    }
  }
}
message "Done checking for invalid collection elements.";


To prevent this phenomenon from occurring it is best to do a check before removing an already long time existing element if it has been referenced. The Where used command in the object's context menu is useful to see where the element has been referenced.