Showing results for 
Search instead for 
Do you mean 
Reply

What is the best way to change the default clone action for certain parts?

I want to change the default clone action for certain parts automatically, so I was delfing into the area of clone notify callbacks.

Using .NET I got a operating system exception, which seems to be reported already, so I changed back to good old C Smiley Embarassed

I tried multiple callbacks with success for small assemblies, but they crashed NX to desktop with assemblies consisting of more than 1000 parts.

I finally found a callback that doesn'T crash NX to desktop, but in the end all parts end up with the special default cloning action set, instead of just a few.

So the question is which callback is best suited for this kind of action?

Thanks in advance for any pointers, find my current code below.

/*****************************************************************************
 **
 ** NXOpenDLL.c
 **
 ** Description:
 **    Contains Unigraphics entry points for the application.
 **
 *****************************************************************************/

/* Include files */
#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_clone.h>
#include "NXOpenDLL.h"

/* global variables */
static char CallBackName[] = "HaiCloneAutoRetain";
static UF_CLONE_notify_cb_t CallBackType[] = { UF_CLONE_beg_apply_defs_cb, UF_CLONE_end_apply_defs_cb };
static char drawn_suffix[10];
static char mirrored_suffix[10];

/* set to 1 for lite debug, 2 for full debug */
static int debug = 1;

/*****************************************************************************
 ** Activation Methods
 *****************************************************************************/
/*  Explicit Activation
 **     This entry point is used to activate the application explicitly, as in
 **     "File->Execute UG/Open->User Function..." */
extern DllExport void ufusr(char *parm, int *returnCode, int rlen)
{
	/* Initialize variables */
	char msg[133], *drawn_suffix_var, *mirrored_suffix_var;
	int i;

	/* Initialize the API environment */
	if (UF_CALL(UF_initialize()))
	{
		/* Failed to initialize */
		return;
	}

	/* TODO: Add your application code here */
	UF_CALL(UF_translate_variable("HAI_DRAWN_SUFFIX", &drawn_suffix_var));
	UF_CALL(UF_translate_variable("HAI_MIRRORED_SUFFIX", &mirrored_suffix_var));

	sprintf(drawn_suffix, "%s/", drawn_suffix_var);
	sprintf(mirrored_suffix, "%s/", mirrored_suffix_var);

	sprintf(msg, "HaiCloneAutoRetain ... drawn: %s ... mirrored: %s\n", drawn_suffix, mirrored_suffix);
	UF_print_syslog(msg, FALSE);

	for (i = 0; i < 2; i++)
		UF_CALL(UF_CLONE_register_ntfy_callback(CallBackType[i], HaiCloneAutoRetain, CallBackName, "Sets the default action to retain", NULL, true));

	/* Terminate the API environment */
	UF_CALL(UF_terminate());
}

/*  Unigraphics Startup
 **      This entry point activates the application at Unigraphics startup */
extern DllExport void ufsta(char *param, int *returnCode, int rlen)
{
	/* Initialize variables */
	int i;

	/* Initialize the API environment */
	if (UF_CALL(UF_initialize()))
	{
		/* Failed to initialize */
		return;
	}

	/* TODO: Add your application code here */
	for (i = 0; i < 2; i++)
		UF_CALL(UF_CLONE_register_ntfy_callback(CallBackType[i], HaiCloneAutoRetain, CallBackName, "Sets the action to retain for certain part files", NULL, false));

	/* Terminate the API environment */
	UF_CALL(UF_terminate());
}

/* clone callback */
static UF_CLONE_notify_response_t HaiCloneAutoRetain(UF_CLONE_notify_cb_t cb, const char *input_part_specifier, const void *data)
{
	char *my_part_name;
	char msg[133];
	UF_CLONE_operation_class_t current_operation;

	UF_CALL(UF_CLONE_ask_operation_class(&current_operation));

	if (current_operation != UF_CLONE_clone_operation)
		return UF_CLONE_continue;

	sprintf(msg, "Starting part iteration ...\n");
	UF_print_syslog(msg, FALSE);

	UF_CALL(UF_CLONE_start_iteration());

	UF_CALL(UF_CLONE_iterate(&my_part_name));

	if (cb == UF_CLONE_beg_apply_defs_cb)
	{
		while (my_part_name != NULL)
		{
			if (debug == 1)
			{
				sprintf(msg, "Applying default action for part ... %s\n", my_part_name);
				UF_print_syslog(msg, FALSE);
			}
			UF_CALL(UF_CLONE_set_action(my_part_name, UF_CLONE_clone, NULL));

			UF_CALL(UF_CLONE_iterate(&my_part_name));
		}
	}
	else
	{
		while (my_part_name != NULL)
		{
			if (debug == 1)
			{
				sprintf(msg, "Processing part ... %s\n", my_part_name);
				UF_print_syslog(msg, FALSE);
			}
			if (strstr(my_part_name, drawn_suffix) != NULL || strstr(my_part_name, mirrored_suffix) != NULL)
			{
				if (debug == 1)
				{
					sprintf(msg, "    Setting retained for part ... %s\n", my_part_name);
					UF_print_syslog(msg, FALSE);
				}
				UF_CALL(UF_CLONE_set_action(my_part_name, UF_CLONE_retain, NULL));
			}
			UF_CALL(UF_CLONE_iterate(&my_part_name));
		}
	}
	sprintf(msg, "Finished part iteration ...\n");
	UF_print_syslog(msg, FALSE);

	return UF_CLONE_continue;
}

/*****************************************************************************
 ** Utilities
 *****************************************************************************/
/* Unload Handler
 **    This function specifies when to unload your application from Unigraphics.
 **    If your application registers a callback (from a MenuScript item or a
 **    User Defined Object for example), this function MUST return
 **    "UF_UNLOAD_UG_TERMINATE". */
extern int ufusr_ask_unload(void)
{
	if (debug == 0)
	{
		return (UF_UNLOAD_UG_TERMINATE);
	}
	else
	{
		return (UF_UNLOAD_SEL_DIALOG);
	}
}

/* Cleanup Handler
 **    This function cleans up before the DLL is unloaded. */
extern void ufusr_cleanup(void)
{
	/* Initialize variables */
	int i;
	UF_CLONE_notify_callback_t CallBackFunction;

	for (i = 0; i < 2; i++)
		UF_CALL(UF_CLONE_remove_ntfy_callback(CallBackType[i], CallBackName, &CallBackFunction));
}
Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community