The DesignComponents method returns a collection of all components in the design (including annotate symbols like borders), it seems likely that not all components have a DNP attribute, so the code should not make that assumption.
You can check whether the attribute exists first, like this:
If Not itr.FindAttribute(DNP) Is Nothing Then
dicCompDNP.Add dicKey, itr.FindAttribute(DNP).EitherValue
Keep in mind that FindAttribute only looks at the attributes on the component instance, not the underlying symbol. If you need to look at the underlying symbol, get the component's SymbolBlock property and call FindAttribute there.
It could be worth creating a function that looks first at the component instance, then at the symbol block, and cleanly handles the case where the attribute does not exist. Search the forum here and you can probably find an example.
Thanks for the code safety suggestions - I do actually employ them, but didn't include them since it's not what I'm having a problem with.
For example, I only look at device components, shown below
For Each itr in objDxApp.DesignComponents("", schemName, -1, "STD", TRUE)
If itr.SymbolBlock.SymbolType = VDB_MODULE Then
'Grab attributes, do error checking
I have a snapshot shown below of some of the resistor properties. I went ahead and tried itr.SymbolBlock.FindAttribute("DNP").EitherValue, which allows the script to not "blow up", but returns "". This makes sense, because the Symbol Value is <none>.
However, what I don't understand is why itr.FindAttribute("DNP").EitherValue *does not* work - why grabbing the Symbol Value is ok but the Block Value is not - because the properties window says the Block Value is "dnp". If I grab the itr.FindAttribute("1ST_MANUFACTURER").EitherValue I will get its Block Value of "Vishay". Strangely, this does not work for DNP.
This is why I don't understand why the script would blow up on DNP, when it allows 1ST_MANUFACTURER.