Hi all, maybe somebody can help me, I am pretty desperate...
I have an enumeration attribute type, let say the colors: "white", "black", "red", "yellow" and so on , and the default enum value - "white". Any help will be extremely appreciated! Thank you in advance. vjub58 - Fri May 22 14:41:33 EDT 2015 |
Re: How to get the default Value (.defval) of Enumeration type? I have an enumeration called "abc" with 'a', 'b', 'c' as enumerations and 'a' is the default value. This DXL correctly printed out 'a' as the default value:
AttrDef ad = find(current Module, "abc") |
Re: How to get the default Value (.defval) of Enumeration type? kourosh - Fri May 22 16:08:59 EDT 2015 I have an enumeration called "abc" with 'a', 'b', 'c' as enumerations and 'a' is the default value. This DXL correctly printed out 'a' as the default value:
AttrDef ad = find(current Module, "abc") kourosh, thank you! But I have the STRINGS "red", "white", "blue" etc as enumerations , and you have the LITERALS 'a', 'b', 'c'. Maybe it's the critical difference and it is exactly the point here. |
Re: How to get the default Value (.defval) of Enumeration type? vjub58 - Sat May 23 11:08:03 EDT 2015 kourosh, thank you! But I have the STRINGS "red", "white", "blue" etc as enumerations , and you have the LITERALS 'a', 'b', 'c'. Maybe it's the critical difference and it is exactly the point here. Hi What Kourosh states is correct, however the problem I encountered is that the returned type string contained rich text so getting the actual value was an issue initially. In the attached file see the function: getAllAttrs which should give you an idea of what to do. This is working code but will need modifying for your purposes. Hope that helps
Attachments attsandtypes.inc |
Re: How to get the default Value (.defval) of Enumeration type? If I understand you correctly you want to assign the "default" value to an object attribute? In this case you just assign the null value to the attribute: o."abc" = null This will not assign empty, but the default value (or empty if there is no default value) Note that the default value is an "attribute" property - i.e. all attributes, also int, date, etc. can be empty or have a default value. Regards, Mathias |
Re: How to get the default Value (.defval) of Enumeration type? Mathias Mamsch - Mon May 25 04:09:42 EDT 2015 If I understand you correctly you want to assign the "default" value to an object attribute? In this case you just assign the null value to the attribute: o."abc" = null This will not assign empty, but the default value (or empty if there is no default value) Note that the default value is an "attribute" property - i.e. all attributes, also int, date, etc. can be empty or have a default value. Regards, Mathias No Matthias, I need to assign the default atribute value just TO VARIABLE , not to object attribute. And that is the point here. My purpose is to export the list of enumerations of the type to one CSV column, and the default value of the type - to one another CSV column. I need both the enumerations list and the default value as a strings for that purpose. Thank you in advance for any help! I read many your answers here in that forum, and these are always extremely professional and helpful. |
Re: How to get the default Value (.defval) of Enumeration type? vjub58 - Wed May 27 02:07:02 EDT 2015 No Matthias, I need to assign the default atribute value just TO VARIABLE , not to object attribute. And that is the point here. My purpose is to export the list of enumerations of the type to one CSV column, and the default value of the type - to one another CSV column. I need both the enumerations list and the default value as a strings for that purpose. Thank you in advance for any help! I read many your answers here in that forum, and these are always extremely professional and helpful. Hi myObect.myAttributeName += myDefaultMember1; myObect.myAttributeName += myDefaultMember2; myObect.myAttributeName += myDefaultMember3; // ... myObect.myAttributeName -= myNonDefaultMember1; myObect.myAttributeName -= myNonDefaultMember2; myObect.myAttributeName -= myNonDefaultMember3; // ... Best regards Wolfgang |
Re: How to get the default Value (.defval) of Enumeration type? vjub58 - Wed May 27 02:07:02 EDT 2015 No Matthias, I need to assign the default atribute value just TO VARIABLE , not to object attribute. And that is the point here. My purpose is to export the list of enumerations of the type to one CSV column, and the default value of the type - to one another CSV column. I need both the enumerations list and the default value as a strings for that purpose. Thank you in advance for any help! I read many your answers here in that forum, and these are always extremely professional and helpful. Hi i think what i posted earlier should help. However it might be easier if you attach your code and an example Module so we can see what the issue is. |
Re: How to get the default Value (.defval) of Enumeration type? Kourish and Chris are correct. Below is the function I use to extract it. here are some notes: There is a Boolean "defval" property of an AttrDef as well as a string "defval" property. My function below highlights how you are sure to get the correct property by using it in context (bool in the "if"; string in the Results assignment. In your original code I'm guessing you have AutoDeclare on and failed to declare "s" as a string. So for some reason "s" is a Date with a "null" value, which looks like 1970 01 January. "AttType"s have "strings[I]". "AttrDef"s are allowed to have default values. There is no such thing as a "default" for your list of colors. Once you define an attribute definition for it, such as "CarColors" of type "Colors", that can have a default value. So you may need something like this:
-Louie
|
Re: How to get the default Value (.defval) of Enumeration type? Thank you so much to all of you! Now I know at last the workaround. The code like: =========================================== AttrDef ad = find (current Module, "Attribute_Name") bool hasdef = ad.defval string defStr = "has no default value" if (hasdef) defStr = ad.defval print defStr ========================================== DOES WORK. The code like: =========================================== AttrDef ad = find (current Module, "Attribute_Name") string defStr = "has no default value" if (ad.defval) defStr = ad.defval print defStr ========================================== DOES NOT WORK. The tested bool value ad.defval (whether ad has default value) should be assigned to separate variable. Otherwise it has been interpreted as bool at assigning of af defval to string. |
Re: How to get the default Value (.defval) of Enumeration type? vjub58 - Fri May 29 10:27:10 EDT 2015 Thank you so much to all of you! Now I know at last the workaround. The code like: =========================================== AttrDef ad = find (current Module, "Attribute_Name") bool hasdef = ad.defval string defStr = "has no default value" if (hasdef) defStr = ad.defval print defStr ========================================== DOES WORK. The code like: =========================================== AttrDef ad = find (current Module, "Attribute_Name") string defStr = "has no default value" if (ad.defval) defStr = ad.defval print defStr ========================================== DOES NOT WORK. The tested bool value ad.defval (whether ad has default value) should be assigned to separate variable. Otherwise it has been interpreted as bool at assigning of af defval to string. I may be wrong here and you will be doling me a favor to prove it; but I'm pretty sure this line will work:
The "if" statement requires a Boolean parameter and the interpreter should find the Boolean version of "ad.defval" to accommodate it. If it found and returned the string version they you would end up with a run time error:
The second "ad.defal" should be interpreted as a string since it is being assigned to a string variable. that presumes AutoDeclare is OFF and you have declared "string defStr" above. Actually the following is technically perfectly save although overkill; which forces the issue directly:
With AutoDeclare left ON and no declaration, the following is I believe unreliable:
Is "defStr" a string or bool? IIRC, in DOORS v6 it was consistently a "bool" but in v7 it changed to a "string" ... most of the time. Finally consider the following; for a bool attribute:
|