Topic
  • 3 replies
  • Latest Post - ‏2019-06-03T13:37:41Z by Juanfergar
Juanfergar
Juanfergar
21 Posts

Pinned topic Delete a value in an enumetarion attribute type

‏2019-05-31T08:59:27Z | attribute type

Hi,

 

I have an attribute type with an enumeration, and I want to delete one of those values. I am trying withe the next code but it doesn't work, give a diagnostic log.

Module m = current
string enumerationType = "nameAttributeType"
string deleteValEnumeration = "valueToDelete"
AttrType att = find(m, enumerationType)
int arrColors[att.size]
int arrMap[att.size]
string arr[att.size]
int arrVal[att.size]
string arrDescs[att.size]
int i
int j = 0
for(i = 0; i < att.size-1; i++){ 
    if(att.strings[i] != deleteValEnumeration){
        arr[j] = att.strings[i]
        arrVal[j] = 0
        arrColors[j] = att.colors[i]
        arrDescs[j] = att.descriptions[i]
        arrMap[j] = i
        j++
    }
}

AttrType att2 = modify(att, enumerationType, arr, arrVal, arrColors, arrDescs, arrMap, err)

 

And the error in the DXL Editor is :

-R-E- DXL: <Line:23> An unexpected error has occurred: doors.exe caused an EXCEPTION_ACCESS_VIOLATION in module doors.exe at 000000003F9CF544

-R-F- DXL: <Line:23> internal error, please submit a bug report
-I- DXL: execution halted
 

Thank you!

 

  • Juanfergar
    Juanfergar
    21 Posts
    ACCEPTED ANSWER

    Re: Delete a value in an enumetarion attribute type

    ‏2019-06-03T13:37:41Z  

    Because you are deleting something , the new arrays are not the same size (att.size) as the old ones. Tested your script and yes, it crashes with exception. But if you just write out the arrays, instead of declaring them att.size and looping to copy values it will work:

    Module m = current
    string enumerationType = "Status"
    AttrType att = find(m, enumerationType)
    int arrColors[]={1,2,3,4,5}
    int arrMap[]= {0,3,4,5,6}
    //string oldStrings[] = {"Proposed","Justified","Specified","Committed","Completed","Rejected","Obsolete"}

    //delete Justified and Specified from list
    string arr[]= {"Proposed","Committed","Completed","Rejected","Obsolete"}
    int arrVal[]={1,2,3,4,5}
    string err= ""

    AttrType att2 = modify(att, enumerationType, arr, arrVal, arrColors, arrMap, err)
     

    I found the error.

     

    The problem was the size of the array as you say. If I adjust the new size it works and without the problem that you miss the values selected:

    Module m = current
    string enumerationType = "nameAttributeType"
    string deleteValEnumeration = "valueToDelete"
    AttrType att = find(m, enumerationType)
    int arrColors[att.size-1]
    int arrMap[att.size-1]
    string arr[att.size-1]
    int arrVal[att.size-1]
    int i
    int j = 0
    for(i = 0; i < att.size; i++){ 
        if(att.strings[i] != deleteValEnumeration){
            arr[j] = att.strings[i]
            arrVal[j] = 0
            arrColors[j] = att.colors[i]
            arrMap[j] = i
            j++
        }
    }
    
    AttrType att2 = modify(att, enumerationType, arr, arrVal, arrColors, arrMap, err)
    

    Thank you!!!

  • PekkaMakinen
    PekkaMakinen
    208 Posts

    Re: Delete a value in an enumetarion attribute type

    ‏2019-06-03T10:47:23Z  

    Because you are deleting something , the new arrays are not the same size (att.size) as the old ones. Tested your script and yes, it crashes with exception. But if you just write out the arrays, instead of declaring them att.size and looping to copy values it will work:

    Module m = current
    string enumerationType = "Status"
    AttrType att = find(m, enumerationType)
    int arrColors[]={1,2,3,4,5}
    int arrMap[]= {0,3,4,5,6}
    //string oldStrings[] = {"Proposed","Justified","Specified","Committed","Completed","Rejected","Obsolete"}

    //delete Justified and Specified from list
    string arr[]= {"Proposed","Committed","Completed","Rejected","Obsolete"}
    int arrVal[]={1,2,3,4,5}
    string err= ""

    AttrType att2 = modify(att, enumerationType, arr, arrVal, arrColors, arrMap, err)
     

    Updated on 2019-06-03T11:31:21Z at 2019-06-03T11:31:21Z by PekkaMakinen
  • Juanfergar
    Juanfergar
    21 Posts

    Re: Delete a value in an enumetarion attribute type

    ‏2019-06-03T11:59:39Z  

    Because you are deleting something , the new arrays are not the same size (att.size) as the old ones. Tested your script and yes, it crashes with exception. But if you just write out the arrays, instead of declaring them att.size and looping to copy values it will work:

    Module m = current
    string enumerationType = "Status"
    AttrType att = find(m, enumerationType)
    int arrColors[]={1,2,3,4,5}
    int arrMap[]= {0,3,4,5,6}
    //string oldStrings[] = {"Proposed","Justified","Specified","Committed","Completed","Rejected","Obsolete"}

    //delete Justified and Specified from list
    string arr[]= {"Proposed","Committed","Completed","Rejected","Obsolete"}
    int arrVal[]={1,2,3,4,5}
    string err= ""

    AttrType att2 = modify(att, enumerationType, arr, arrVal, arrColors, arrMap, err)
     

    If I use that code it works, but I miss all the values selected except those who doesn't change inte the enumeration, I mean, in the example, if I have objects with the value Rejected selected, it disapear. I need remove the value in the enumeration but doesn't miss the others values selected in the objects

  • Juanfergar
    Juanfergar
    21 Posts

    Re: Delete a value in an enumetarion attribute type

    ‏2019-06-03T13:37:41Z  

    Because you are deleting something , the new arrays are not the same size (att.size) as the old ones. Tested your script and yes, it crashes with exception. But if you just write out the arrays, instead of declaring them att.size and looping to copy values it will work:

    Module m = current
    string enumerationType = "Status"
    AttrType att = find(m, enumerationType)
    int arrColors[]={1,2,3,4,5}
    int arrMap[]= {0,3,4,5,6}
    //string oldStrings[] = {"Proposed","Justified","Specified","Committed","Completed","Rejected","Obsolete"}

    //delete Justified and Specified from list
    string arr[]= {"Proposed","Committed","Completed","Rejected","Obsolete"}
    int arrVal[]={1,2,3,4,5}
    string err= ""

    AttrType att2 = modify(att, enumerationType, arr, arrVal, arrColors, arrMap, err)
     

    I found the error.

     

    The problem was the size of the array as you say. If I adjust the new size it works and without the problem that you miss the values selected:

    Module m = current
    string enumerationType = "nameAttributeType"
    string deleteValEnumeration = "valueToDelete"
    AttrType att = find(m, enumerationType)
    int arrColors[att.size-1]
    int arrMap[att.size-1]
    string arr[att.size-1]
    int arrVal[att.size-1]
    int i
    int j = 0
    for(i = 0; i < att.size; i++){ 
        if(att.strings[i] != deleteValEnumeration){
            arr[j] = att.strings[i]
            arrVal[j] = 0
            arrColors[j] = att.colors[i]
            arrMap[j] = i
            j++
        }
    }
    
    AttrType att2 = modify(att, enumerationType, arr, arrVal, arrColors, arrMap, err)
    

    Thank you!!!