I am working on a script to automatically sort the list of entries in an enumeration of Attribute Type in a formal module. The attributes (of the Attribute Type)are in use. I have the feeling that the script is a bit complex: |
Re: alphabetic sorting for an enum Go to the DXL manual chapter 'Attributes' section 'Attribute type manipulation' command 'modify (attribute type)'. There is an undocumented version of this command: AttrType modify(AttrType, string, string], int[, int], string[, int[], string&) That extra 7th int[] parameter is a mapping of New Enums to the Old enums. So if your old enums are 'Low', 'Medium', and 'High' and you want 'High', 'Low', and 'Medium' the values of that array will be {2, 0, 1} (where position '0' in the array maps to new 'High', and its value 2 maps to 'High' in the old enums list). So I would read the old Enums, copy to a New enums array, alpha-sort the new array, then for each new sorted value, find its position in the old enums array and build that extra int array. If there are duplicate Enum values then you have a problem. Now I said you won't 'need' to reset the Object values. Until you do, however, they will display the correct values but in the old order. To get them to display their values in the new order I would do the follow after you modify the type: {for obj in entire mod do; obj.NameAttr = obj.NameAttr}
|
Re: alphabetic sorting for an enum
I hacked together the following to sort enums alphabetically.
string sortEnumAttrType(string attrTypeName)
{
Module m = current Module
int i = 0
string errmsg = ""
if (null m) return("No current module")
AttrType at = find(current Module, attrTypeName)
if (null at) return("Attribute type not found")
setRealColorOptionForTypes(true)
int atSize = at.size
int newPos = 0
string new_strings[atSize]
int new_values[atSize]
int new_colors[atSize]
string new_descs[atSize]
int arrMaps[atSize]
Skip stringsList = createString
for(i=0;i < atSize; i++)
{
put(stringsList, at.strings[i], i)
}
newPos = 0
for i in stringsList do
{
new_strings[newPos] = at.strings[i]
new_values[newPos] = at.values[i]
new_colors[newPos] = at.colors[i]
new_descs[newPos] = at.descriptions[i]
arrMaps[newPos] = newPos
newPos++
}
at = modify(at, attrTypeName, new_strings, new_values, new_colors, new_descs, arrMaps, errmsg)
return(errmsg)
}
string res = sortEnumAttrType("a")
print res
|
Re: alphabetic sorting for an enum Tony_Goodman - Fri Jun 19 04:07:56 EDT 2009
I hacked together the following to sort enums alphabetically.
string sortEnumAttrType(string attrTypeName)
{
Module m = current Module
int i = 0
string errmsg = ""
if (null m) return("No current module")
AttrType at = find(current Module, attrTypeName)
if (null at) return("Attribute type not found")
setRealColorOptionForTypes(true)
int atSize = at.size
int newPos = 0
string new_strings[atSize]
int new_values[atSize]
int new_colors[atSize]
string new_descs[atSize]
int arrMaps[atSize]
Skip stringsList = createString
for(i=0;i < atSize; i++)
{
put(stringsList, at.strings[i], i)
}
newPos = 0
for i in stringsList do
{
new_strings[newPos] = at.strings[i]
new_values[newPos] = at.values[i]
new_colors[newPos] = at.colors[i]
new_descs[newPos] = at.descriptions[i]
arrMaps[newPos] = newPos
newPos++
}
at = modify(at, attrTypeName, new_strings, new_values, new_colors, new_descs, arrMaps, errmsg)
return(errmsg)
}
string res = sortEnumAttrType("a")
print res
|
Re: alphabetic sorting for an enum Tony_Goodman - Fri Jun 19 04:07:56 EDT 2009
I hacked together the following to sort enums alphabetically.
string sortEnumAttrType(string attrTypeName)
{
Module m = current Module
int i = 0
string errmsg = ""
if (null m) return("No current module")
AttrType at = find(current Module, attrTypeName)
if (null at) return("Attribute type not found")
setRealColorOptionForTypes(true)
int atSize = at.size
int newPos = 0
string new_strings[atSize]
int new_values[atSize]
int new_colors[atSize]
string new_descs[atSize]
int arrMaps[atSize]
Skip stringsList = createString
for(i=0;i < atSize; i++)
{
put(stringsList, at.strings[i], i)
}
newPos = 0
for i in stringsList do
{
new_strings[newPos] = at.strings[i]
new_values[newPos] = at.values[i]
new_colors[newPos] = at.colors[i]
new_descs[newPos] = at.descriptions[i]
arrMaps[newPos] = newPos
newPos++
}
at = modify(at, attrTypeName, new_strings, new_values, new_colors, new_descs, arrMaps, errmsg)
return(errmsg)
}
string res = sortEnumAttrType("a")
print res
I know this is an old post, but I found this piece of code fairly useful for a large existing enumeration I have to maintain. There is one small bug that causes attributes to change both their values and their position, instead of only the position in the list as desired. "arrMaps[newPos] = newPos" should be "arrMaps[newPos] = i" instead.
For those wanting to copy paste:
string sortEnumAttrType(string attrTypeName)
{
Module m = current Module
int i = 0
string errmsg = ""
if (null m) return("No current module")
AttrType at = find(current Module, attrTypeName)
if (null at) return("Attribute type not found")
setRealColorOptionForTypes(true)
int atSize = at.size
int newPos = 0
string new_strings[atSize]
int new_values[atSize]
int new_colors[atSize]
string new_descs[atSize]
int arrMaps[atSize]
Skip stringsList = createString
for(i=0;i < atSize; i++)
{
put(stringsList, at.strings[i], i)
}
newPos = 0
for i in stringsList do
{
new_strings[newPos] = at.strings[i]
new_values[newPos] = at.values[i]
new_colors[newPos] = at.colors[i]
new_descs[newPos] = at.descriptions[i]
arrMaps[newPos] = newPos
newPos++
}
at = modify(at, attrTypeName, new_strings, new_values, new_colors, new_descs, arrMaps, errmsg)
return(errmsg)
}
string res = sortEnumAttrType("a")
print res
|