Topic
  • 4 replies
  • Latest Post - ‏2014-03-27T16:04:29Z by CMusicFan
CMusicFan
CMusicFan
22 Posts

Pinned topic Combine values in multi-value attribute

‏2014-03-26T16:36:21Z |

How would one go about combining the values of a multi-value attribute? For instance, I have an attribute called "Affected Modules" that is a multi-value enumeration. I am wanting to combine the values of this attribute from two different objects into the Affected Modules attribute of a single object. How would one go about doing this?

Thanks

  • CMusicFan
    CMusicFan
    22 Posts
    ACCEPTED ANSWER

    Re: Combine values in multi-value attribute

    ‏2014-03-27T16:04:29Z  

    The assignment only works for adding a single value to the multi-value enumeration.  So if the obj2 attribute has more than one value, it won't work.  What you have to do is to check if obj2 has a value set and if so, add it to your obj1.  This code snippit might help

    AttrDef adCur
    AttrType atCur
    int iCount, iEnums    
    Module curmod = current
    string sAttrName = "Program Specific"
    Object o = current
    Object oNext = next o
    
    adCur = find(curmod, sAttrName) //get the attribute definition of the selected attribute
    atCur = find(curmod, adCur.typeName) //get the attribute type
    
    iEnums = atCur.size //get total number of enumeration values in attribute
    string sEnumList[iEnums + 1] //make a string array one larger than total number to make sure it is big enough??
    for (iCount = 0; iCount < iEnums; iCount++) {  //now loop through and insert all the new enumeration values
       sEnumList[iCount] = atCur.strings[iCount]
    }
    
    for (iCount = 0; iCount < iEnums; iCount++) { //loop through the values
       if (isMember(oNext.sAttrName,sEnumList[iCount])){ //check if next object has that value
          o.sAttrName += sEnumList[iCount] //yes it does, so add it to current object
       }
    }
    

     

    I found a good way to do it! Here's the code I ended up using.

    AttrType ModulesType = find(()current Module), NLS_("Modules"))
    
    // Combine the Affected Modules attributes into the current object
    for (i = 0; i < ModulesType.size; i++)
    {
        // If the second object includes the current enumeration but the first one does not, add it to the first one
        if (isMember(obj."Affected Modules", ModulesType.strings[i]))
        {
            if (!isMember(o."Affected Modules", ModulesType.strings[i]))
            {
                o."Affected Modules" += ModulesType.strings[i]
            }
        }   
    }
    

    I hope this helps someone later on. Feel free to use it!

    Thanks for the help!

    Updated on 2014-03-27T16:05:29Z at 2014-03-27T16:05:29Z by CMusicFan
  • GregM_dxler
    GregM_dxler
    166 Posts

    Re: Combine values in multi-value attribute

    ‏2014-03-27T13:10:19Z  

    Hi,

    For a multivalue enumeration, you use the += operator to add values to it.  So say you want to combine attribute Attr1 and Attr2 into attribute Affected Modules:

    o."Affected Modules" += o."Attr1"

    o."Affected Modules" += o."Attr2"

    That should add the values.  If you wanted to use a different object, then you would replace the appropriate o.

    Hope this helps,

    Greg

     

  • CMusicFan
    CMusicFan
    22 Posts

    Re: Combine values in multi-value attribute

    ‏2014-03-27T13:21:58Z  

    Hi,

    For a multivalue enumeration, you use the += operator to add values to it.  So say you want to combine attribute Attr1 and Attr2 into attribute Affected Modules:

    o."Affected Modules" += o."Attr1"

    o."Affected Modules" += o."Attr2"

    That should add the values.  If you wanted to use a different object, then you would replace the appropriate o.

    Hope this helps,

    Greg

     

    I must have been unclear about exactly what I am asking. I have two objects, we will call them obj1 and obj2. They both have an  "Affected Modules" attribute with multiple values selected. I am wanting to add all of the selected "Affected Modules" from both obj1 and obj2  together into a single "Affected Modules" attribute (ideally the one for obj1). If I try to use the method you described above, it looks like this

    o."Affected Modules" += obj."Affected Modules"

    Unfortunately, DOORS returns an an incorrect arguments error  for the += sign with this syntax. I double checked my spelling, so I know it has to be the way I am trying to combine attributes. Is there a good way to do this?

    Thanks

  • GregM_dxler
    GregM_dxler
    166 Posts

    Re: Combine values in multi-value attribute

    ‏2014-03-27T14:31:41Z  
    • CMusicFan
    • ‏2014-03-27T13:21:58Z

    I must have been unclear about exactly what I am asking. I have two objects, we will call them obj1 and obj2. They both have an  "Affected Modules" attribute with multiple values selected. I am wanting to add all of the selected "Affected Modules" from both obj1 and obj2  together into a single "Affected Modules" attribute (ideally the one for obj1). If I try to use the method you described above, it looks like this

    o."Affected Modules" += obj."Affected Modules"

    Unfortunately, DOORS returns an an incorrect arguments error  for the += sign with this syntax. I double checked my spelling, so I know it has to be the way I am trying to combine attributes. Is there a good way to do this?

    Thanks

    The assignment only works for adding a single value to the multi-value enumeration.  So if the obj2 attribute has more than one value, it won't work.  What you have to do is to check if obj2 has a value set and if so, add it to your obj1.  This code snippit might help

    AttrDef adCurAttrType atCur
    int iCount, iEnums    
    Module curmod = current
    string sAttrName = "Program Specific"
    Object o = current
    Object oNext = next o
    
    adCur = find(curmod, sAttrName) //get the attribute definition of the selected attribute
    atCur = find(curmod, adCur.typeName) //get the attribute type
    
    iEnums = atCur.size //get total number of enumeration values in attribute
    string sEnumList[iEnums + 1] //make a string array one larger than total number to make sure it is big enough??
    for (iCount = 0; iCount < iEnums; iCount++) {  //now loop through and insert all the new enumeration values
       sEnumList[iCount] = atCur.strings[iCount]
    }
    
    for (iCount = 0; iCount < iEnums; iCount++) { //loop through the values
       if (isMember(oNext.sAttrName,sEnumList[iCount])){ //check if next object has that value
          o.sAttrName += sEnumList[iCount] //yes it does, so add it to current object
       }
    }
    

     

  • CMusicFan
    CMusicFan
    22 Posts

    Re: Combine values in multi-value attribute

    ‏2014-03-27T16:04:29Z  

    The assignment only works for adding a single value to the multi-value enumeration.  So if the obj2 attribute has more than one value, it won't work.  What you have to do is to check if obj2 has a value set and if so, add it to your obj1.  This code snippit might help

    <pre class="html dw" data-editor-lang="js" data-pbcklang="html" dir="ltr">AttrDef adCurAttrType atCur int iCount, iEnums Module curmod = current string sAttrName = "Program Specific" Object o = current Object oNext = next o adCur = find(curmod, sAttrName) //get the attribute definition of the selected attribute atCur = find(curmod, adCur.typeName) //get the attribute type iEnums = atCur.size //get total number of enumeration values in attribute string sEnumList[iEnums + 1] //make a string array one larger than total number to make sure it is big enough?? for (iCount = 0; iCount < iEnums; iCount++) { //now loop through and insert all the new enumeration values sEnumList[iCount] = atCur.strings[iCount] } for (iCount = 0; iCount < iEnums; iCount++) { //loop through the values if (isMember(oNext.sAttrName,sEnumList[iCount])){ //check if next object has that value o.sAttrName += sEnumList[iCount] //yes it does, so add it to current object } } </pre>

     

    I found a good way to do it! Here's the code I ended up using.

    AttrType ModulesType = find(()current Module), NLS_("Modules"))
    
    // Combine the Affected Modules attributes into the current object
    for (i = 0; i < ModulesType.size; i++)
    {
        // If the second object includes the current enumeration but the first one does not, add it to the first one
        if (isMember(obj."Affected Modules", ModulesType.strings[i]))
        {
            if (!isMember(o."Affected Modules", ModulesType.strings[i]))
            {
                o."Affected Modules" += ModulesType.strings[i]
            }
        }   
    }
    

    I hope this helps someone later on. Feel free to use it!

    Thanks for the help!

    Updated on 2014-03-27T16:05:29Z at 2014-03-27T16:05:29Z by CMusicFan