I tried iterating over a NameValueMap using a 0-based index but it did not work. Iterating over it using a 1-based index worked.
Did not work.
public static void onParameterChange(_Document document,
Inventor.Parameter parameter,
EventTimingEnum BeforeOrAfter,
NameValueMap context ,
out HandlingCodeEnum handlingCode)
{
handlingCode = HandlingCodeEnum.kEventHandled;
// Did not work. Got an exception.
for ( int i = 0; i < context.Count; ++i )
{
string name = context.Name[i];
string value = (string)context.Value[name];
}
}
Worked.
public static void onParameterChange(_Document document,
Inventor.Parameter parameter,
EventTimingEnum BeforeOrAfter,
NameValueMap context ,
out HandlingCodeEnum handlingCode)
{
handlingCode = HandlingCodeEnum.kEventHandled;
// Worked.
for ( int i = 1; i <= context.Count; ++i )
{
string name = context.Name[i];
string value = (string)context.Value[name];
}
}
I was surprised by that. Is that expected?
I also noticed that NameValueMap
inherits IEnumerable
. I tried using foreach
to get the items of the NameValueMap
. However, that only gave me the values of the items. Is there a way to get the names of the items as well?
public static void onParameterChange(_Document document,
Inventor.Parameter parameter,
EventTimingEnum BeforeOrAfter,
NameValueMap context ,
out HandlingCodeEnum handlingCode)
{
handlingCode = HandlingCodeEnum.kEventHandled;
foreach ( var item in context )
{
// How do you get the name?
string value = item;
}
}
There is little information on this
NameValueMap
on the internet, so it is hard to tell if there is an existing method to take advantage of.However, you can always create an extension method to suit your needs: