Problem
The existence of DataTypes or Attributes shall be checked
Approach – Ansatz
- The first function uses the find-function to check for attributes
- The second uses a loop to check for datatypes
Solution – Lösung
bool attributeExists(Module tgt, string attributeName) { AttrDef ad = find(tgt, attributeName) if(null ad) { return false; } else { return true; } return false; } // This example is done in a different way but works // here for DataTypes (instead the find function can be used) bool dataTypeExists(Module tgt, string dataTypeName) { AttrType at; for at in tgt do { if(at.name == dataTypeName) { return true; } } return false; }
To check if an attribute exists in the current module, it is also possible to just do
if (exists attribute „MyAttributeName“)
Yes when you check in this way the only restriction could be, that the module has to be your current module.
Good point!
Another one: your function attributeExists() doesn’t check if the given attribute could be a module attribute. It only finds object attributes. The DXL manual, example for „for AttrType in ModuleProperties“ gives a solution on how to find those.