Trying to make a DXL boolean attribute (called "Is Requirement?") true if the word "shall" exists in another attribute (called "Text"), and otherwise false.
In edit-mode on the DOORS module, I click Edit -> Attributes -> "Is Requirement?" -> Edit... -> check DXL attribute -> Browse... -> New, write the code -> Ok, close all windows, Tools -> Refresh DXL Attributes
Object o
for o in current Module do{
if((o."Text") contains "shall")
{
o."Is Requirement?" = "True"
}
else
{
o."Is Requirement?" = "False"
}
}
Several aspects here:
obj
, the attribute is available in attrDXLName
. There is no loop over objects neither in DXL attributes nor in DXL layout columns.contains
has the signature int contains(Buffer b, string word, int offset)
, it operates on a Buffer, not on a string. You probably want to use bool findPlainText(string s, string sub, int &offset, int &length, bool matchCase[, bool reverse])
o."Text"
will return an object reference. But you want to check the content of the attribute. To get the content of a string attribute, you have to cast the object reference to string, e.g. by concatenating the reference with a string. You can use obj."Text" ""
.This changes your code to
int offset, length
bool matchCase = true
obj.attrDXLName = findPlainText (obj."Object Text" "", "shall", offset, length, matchCase)
Remember that the type of your DXL attribute must be boolean for this to work.
And last but not least: Are you sure that your condition "Text contains shall" is sufficient? What about all the words that contain "shall" (https://www.thefreedictionary.com/words-containing-shall)? There are some threads about this topic somewhere in the internet. Search for "Requirement DXL shall shallow". And: is "shall" enough? What about "may", "should", "must"?