Error: null Attribute Def do loop parameter was passed

I have a loop within another loop that is supposed to get all the non-system attributes of each module in a project.  However, I'm getting the error in the title of this post.  Here is the pared down version of the script I'm trying to run:

AttrDef ad;
Module currMod = current Module;        //Set just to initialize the variable

for itemRef in current Project do {
    if (type(itemRef) == "Formal") {
        modName = fullName(itemRef);
        skAttrs = create;   //skAttrs is defined as a skip list above this
        
        currMod = module(itemRef);
        
        for ad in currMod do {
            if (!ad.system) {
                put(skAttrs, ad.name"", 0);
            }
        }
    }
}

The error I'm getting is happening in line 10 (for ad in currMod do), but I think the problem is 2 lines above where I'm assigning the module to currMod.  I've never seen this error before, so I don't know how to fix it.  I'm hoping someone out there has seen this error and can help me out.  I'd REALLY appreciate it.

 

Chris


Christopher Cote - Thu May 23 13:20:22 EDT 2019

Re: Error: null Attribute Def do loop parameter was passed
PekkaMakinen - Thu May 23 13:35:16 EDT 2019

Module has to be open to access the attributes if you are looping with AttrDef in Module loop.

"currMod = module(itemRef);" does not open the module, it just gives you a module handle of ModName_ type

"currMod = read(modName)" would open the module and give a a module handle of Module type which you need for that loop.

 

Re: Error: null Attribute Def do loop parameter was passed
Christopher Cote - Thu May 23 15:13:13 EDT 2019

PekkaMakinen - Thu May 23 13:35:16 EDT 2019

Module has to be open to access the attributes if you are looping with AttrDef in Module loop.

"currMod = module(itemRef);" does not open the module, it just gives you a module handle of ModName_ type

"currMod = read(modName)" would open the module and give a a module handle of Module type which you need for that loop.

 

Thank you very much Pekka.

Re: Error: null Attribute Def do loop parameter was passed
llandale - Fri May 24 13:55:46 EDT 2019

Yes, open the module.  currMod is null at line 11.

Nit-Picks:

Line 2 is confusing as it implies this script works on a current module when it does not.  Initialize it to null

Line7: I notice that at line 13 you "put" a string as KEY of the skip (the name of the attribute).  Therefore this line 7 should be "skpAttrs = createString()".  You can expect strange errors using this Skip if not.

Line 7 creates the Skip; surely you want a corresponding delete(skpAttrs) above line 16.  That's good programming practice even it if doesn't matter for this small script.

Line 13: probably better to put the "ad" as the DATA of the Skip.  Using it later (invisible code between lines 15 and 16) will often be easier.

-Louie