≡ Menu

How to Automate NX Migrations with Part Type Convert

Share the knowledge

When you import NX parts and drawings into Teamcenter there are two main challenges. The first is selecting the right item ID. I previously covered how to automate that by implementing a custom clone-autotranslate function. The second is selecting the right item type. Today I’ll show how to automate that by writing a custom Convert callback.

NX Open’s Clone API

NX’s Clone API, UF_CLONE_*, is the most customizable NX API I know. It gives you many opportunities to customize how you import NX part files. One such opportunity is UF_CLONE_register_cvt_callback(). It registers “convert” callback that is used by NX to answer questions like what item type to use.

[box type=”note”]
Cloning assemblies or single files is a process of duplicating an existing assembly. It can be used to create similar assemblies on the native file system or within Teamcenter. It can also create a duplicate assembly where the original is on a native file system and the duplicate is in Teamcenter. This is how NX data is imported into Teamcenter and why we use the UF_CLONE API.
[/box]

To automate the choice of item type we will implement our own convert callback that will look at each part’s filename and determine the item type.

Implementing the Convert Callback

First, we write a function using the following template:

extern "C" DllExport // so we can call this from an external program
UF_CLONE_convert_response_t dojo_cvt_item_type(
	UF_CLONE_convert_cb_t reason, 
	const char* part_spec, 
	char **answer)
{	
	// The magic happens here: 
	// * Parse part_spec (may include full path)
	// * Determine item item type 
	// ** infer from part number or directory
	// ** consult external database
	// ** etc.)
 
	// * Allocate enough space in *answer for 
	//   the correct item type and the line terminator.
	// * set the value of *answer to the item type chosen
 
	// The return code tells NX whether to use your answer or not
	// (you could tell it to try another callback).
	// UF_CLONE_use_supplied --> use this result
	return UF_CLONE_use_supplied; 
}

The argument reason tells you what sort of information NX is looking for. For our example the value will always be UF_CLONE_part_type_convert because that is the code we will use when we register the callback.

Registering the Part Type Convert Callback

Now you have to tell NX to use your custom callback function. It’s the same process as registering an auto-translate callback. For our example I’ll register the convert callback within NX startup User Exit, ufsta().

extern "C" DllExport 
void ufsta( char *param, int *returnCode, int rlen )
{
	UF_initialize();
 
 	// Tell NX to use our convert callback:
	UF_CLONE_register_cvt_callback(
 
		// Use it for setting item type
		UF_CLONE_part_type_convert, 
 
		// Our callback from above
		dojo_cvt_item_type, 
 
		// An identifying  name
		"Dojo's Set Item Type",
 
		// description
		"Infers item type from part number", 
 
		// These two arguments together tell NX to call 
		// our callback first,
		// before any other registered callbacks.
		NULL, 
		true);
 
	// You can register other callbacks here too, such as the 
	// clone-autotranslate callback we covered previously</a>
	UF_UGMGR_set_clone_auto_trans(dojo_autotranslate);
 
	UF_terminate();
}

Build this into shared library (DLL) and place it in where NX can find it when it launches. Now the import process will use your convert callback when an item type was not manually set.

Testing The Callback

Our convert callback is a simple C function. By declaring it as extern "C" DllExport we make it available for calling from an external program. I like writing unit-testing programs in Python using Python’s ctypes library.

Other Uses for Convert Callbacks

The value UF_CLONE_part_type_convert we passed to UF_CLONE_register_cvt_callback() configured our callback for use when NX needed to know the item type. Just so you know, there are other types of convert callbacks you can implement:

  • UF_CLONE_user_name_convert: called when a part has USER_NAME naming
  • UF_CLONE_part_type_convert: called when a part needs a type for the PDM system
  • UF_CLONE_part_name_convert: called when a part needs a PDM name
  • UF_CLONE_part_desc_convert: called when a part needs a PDM description
  • UF_CLONE_part_own_user_convert: called when a part needs a PDM owner user
  • UF_CLONE_part_own_group_convert: called when a part needs a PDM owner group
  • UF_CLONE_part_checkout_convert: called when a part needs a checkout comment
  • UF_CLONE_assoc_file_dir_convert: called when a part needs an associated file directory
  • Kannan Ramasamy

    How to re arrange File->New Menu. I need to have File->new->part, change to be on top with File->new->item

Optimization WordPress Plugins & Solutions by W3 EDGE