Topic
  • 1 reply
  • Latest Post - ‏2019-06-12T16:04:11Z by Mike.Scharnow
Christopher Cote
Christopher Cote
67 Posts

Pinned topic Looping through skiplist that has both object and module attributes

‏2019-06-12T14:02:27Z |

I have a script that I modified to include module in addition to object attributes in a single skiplist.  Now, I am looping through the objects in a module and want to check the values of the object attributes.  Is there an easy way to distinguish whether the attribute in the skip list is an object attribute?  Right now, when I loop through the list, I, of course, get an error when the loop gets to a module-level attribute.  I want to check and make sure that the attribute is an object-level one.  Here is the code I currently have with the addition:

AttrDef ad;
Skip skAttrs = createString;
Module currMod = current Module;

for itemRef in current Project do {
    //First, loop thru all attributes and module amd store
    //them if they are object or module attributes
    for ad in currMod do {
        if (ad.object || ad.module) {       //Added "|| ad.module"
            //Preset the number of times this attribute is used to zero
            attribName = ad.name"";
            //If this is a custome attribute
            if (findPlainText(attribName, "*", offset, lenth, true)) {
                put(skAttrs, attribName, 0);
            }
        }
    }
    //Next step is to loop through the objects in the module and
    //see if it has a value.  If it does, increment its value in the skip list
    for obj in currMod do {
        for o in skAttrs do {
            attribName = (string key skAttrs);
            if (obj.attribName"" != "") {
                //Increment the value
                if (find(skAttrs, attribName, numAttr)) {
                    delete(skAttrs, attribName);
                    numAttr++;
                    bAttribNumFound = put(skAttrs, attribName, numAttr);
                    find(skAttrs, attribName, numAttr);
                }
            }
        }
    }
    close(currMod);
}

The error I get is "unknown Object attribute (*Contract Number)" , where *Contract Number is a module-level attribute, on the line 

  if (obj.attribName"" != "")

The thing is that I understand why the error is appearing.  I just don't know how to check if that attribName string is an object-level attribute.

 

Chris

  • Mike.Scharnow
    Mike.Scharnow
    585 Posts

    Re: Looping through skiplist that has both object and module attributes

    ‏2019-06-12T16:04:11Z  

    Well, you COULD ask DOORS about this attribute like this

    after line 22:
    AttrDef ad = find (currMod, attribName)
    if (!null ad and ad.object) {
        // is object AttrDef
        if (obj.attribName"" != "") { ....
    }
    

    but this would mean that you would do such a find command for EVERY Object for EVERY attr. I assume that this will slow down your script significantly.

    You should restructure your data model, perhaps use two skips, one for object and one for module attributes.