I have a repeatable case where the following occurs (I'm using NX 9, vuilding under Visual Studio 2012 Update 1). Upon executing the following two lines:
UF_UDOBJ_create_class(className.c_str(), friendlyName.c_str(), &classid);
When the first line succeeds, setting a nonzero value in classid, the second line fails for some reason, setting the value of classid to zero. The second line is executed immediately after the first, so no funny business occurs in between. Also, className and friendlyName are non-empty strings containing only letters, numbers, spaces, and underscores. So it seems to me that this is a bug -- UF_UDOBJ_ask_class_id_of_name should not fail here.
The reason we are executing these lines back-to-back like this is we want to load the class with that name if it exists, and otherwise we want to create it. If a class already exists with the chosen name, the first line will fail, but the second line will find the id. Whereas if no class exists with that name, the first line will succeed and the second line should simply find the same id that the first line reserved. Unfortunately, this is not working because of this bug.
In the meantime, we are using the following:
if(0 == umuClass)
UF_UDOBJ_create_class(className.c_str(), friendlyName.c_str(), &umuClass);
However, I am not confident that UF_UDOBJ_ask_class_id_of_name is working at all, even in the above snippet.
Solved! Go to Solution.
This should help if you call it in between your two lines of code: