cancel
Showing results for 
Search instead for 
Did you mean: 

using ufusr parm parameter

Experimenter
Experimenter

Hello,

 

the ufusr entry point has a parameter (char* parm). Rumors tell that the name of the button, where the execution came from should be in that parm.

 

In all of my cases this is just simply empty, even though it's an allocated char array, which is empty.

 

I need this to address several functions in one DLL that should be triggered from different buttons.

 

I couldn't find anything useful, and help would be really appreciated.

 

Thank you,

Markus

8 REPLIES

Re: using ufusr parm parameter

Siemens Phenom Siemens Phenom
Siemens Phenom

 Here is a VB example from out GTAC examples online:

 

Sometimes you want to call the same .DLL from several custom buttons,
but you might want your program to beave differently depending on
which button launched it.

Save this text as report_button_name.men in a valid "startup" folder:

 VERSION 120

 EDIT UG_GATEWAY_MAIN_MENUBAR

 AFTER UG_APPLICATION
     CASCADE_BUTTON NEW_MENU
     LABEL Test Program
 END_OF_AFTER

 MENU NEW_MENU

     BUTTON CUSTOM_BUTTON_1
     LABEL  CUSTOM BUTTON 1
     ACTIONS report_button_name.dll

     BUTTON CUSTOM_BUTTON_2
     LABEL   CUSTOM BUTTON 2
     ACTIONS report_button_name.dll

     BUTTON CUSTOM_BUTTON_3
     LABEL  CUSTOM BUTTON 3
     ACTIONS report_button_name.dll

 END_OF_MENU

Then build the code below as report_button_name.dll and put the
.DLL into a valid "application" folder.

Then start NX and press TestProgram on the main menubar, and
select one of th custom buttons.  The program will report which
button you used.

If you run from File -> Execute -> NXOpen, it should report that it
was not launched from a custom button.

'============================ VB text starts here
Option Strict Off
Imports System
Imports NXOpen

Module report_button_name_from_which_dll_was_launched

    Dim s As Session = Session.GetSession()
    Dim lw As ListingWindow = s.ListingWindow

    Sub Main(Args() As String)

        If (Args(0).Length > 0) Then
            MsgBox("Called from: " & Args(0))
        Else
            MsgBox("This does not appear to have been launched from a custom button.")
        End If

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        Return Session.LibraryUnloadOption.Immediately

    End Function

End Module

================

 

Do you specifically need to do it in C?

 

Regards,

 

Steve

 

 

Re: using ufusr parm parameter

Experimenter
Experimenter

Hi Steve,

 

thank you for the code, but in C it is so easy that normally nothing could go wrong and I really do need it in C.

 

extern DllExport void ufusr( char *parm, int *returnCode, int rlen )

 

and if you Debug it, parm is always "" <- empty string and rlen is 0.

 

The only documentation existing about this -> header files Man Frustrated it says:

extern DllExport void ufusr (
    char   *param  ,         /* <I>
                   If this function is called from menuscript,
                   this argument will contain the name of the menu
                   button selected.  Otherwise this argument is unused.
                */
    int    *retcod ,        /* <O>
                   Return Code.  Not used by Internal
                   Open API.
                */
    int     param_len       /* <I>
                   Length of 'param' Argument.
                   NX handles this input for you.
                */
);

 

But in NX8 which I am using it doesn't come over.


Thank you very much and best regards,

Markus

Re: using ufusr parm parameter

Siemens Phenom Siemens Phenom
Siemens Phenom

Markus,

 

Thank you for explaining.  Please log an Incident Report with GTAC so that we can investigate this thoroughly, and refer it to development for resolution if appropriate.

 

Thanks!

 

Steve

 

Re: using ufusr parm parameter

Siemens Phenom Siemens Phenom
Siemens Phenom

Markus,

 

I just tested this in NX8.0.3, and it works fine for me using Open C.  Here is my Menuscript file, which goes in the "startup" folder:

 

VERSION 120

 EDIT UG_GATEWAY_MAIN_MENUBAR

 AFTER UG_APPLICATION
     CASCADE_BUTTON NEW_MENU
     LABEL Test Program using Open C
 END_OF_AFTER

 MENU NEW_MENU

     BUTTON CUSTOM_BUTTON_1
     LABEL  CUSTOM BUTTON 1
     ACTIONS report_button_name_OpenC_NX8.dll

     BUTTON CUSTOM_BUTTON_2
     LABEL   CUSTOM BUTTON 2
     ACTIONS report_button_name_OpenC_NX8.dll

     BUTTON CUSTOM_BUTTON_3
     LABEL  CUSTOM BUTTON 3
     ACTIONS report_button_name_OpenC_NX8.dll

 END_OF_MENU

 

And here is my Open C code.  The .DLL built from this goes in the "application" folder:


#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>

#include <stdarg.h>

static void ECHO(char *format, ...)
{
    char msg[UF_UI_MAX_STRING_LEN+1];
    va_list args;
    va_start(args, format);
    vsprintf(msg, format, args);
    va_end(args);
    UF_UI_open_listing_window();
    UF_UI_write_listing_window(msg);
    UF_print_syslog(msg, FALSE);
}

#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))

static int report_error( char *file, int line, char *call, int irc)
{
    if (irc)
    {
        char err[133];

        UF_get_fail_message(irc, err);
        ECHO("*** ERROR code %d at line %d in %s:\n",
            irc, line, file);
        ECHO("+++ %s\n", err);
        ECHO("%s;\n", call);
    }

    return(irc);
}

extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
    /* Initialize the API environment */
    if( UF_CALL(UF_initialize()) )
    {
        /* Failed to initialize */
        return;
    }
    
    ECHO("Called from Button: %s\n", parm);

 
    UF_terminate();
}

extern int ufusr_ask_unload( void )
{
    return( UF_UNLOAD_IMMEDIATELY );
}

 

Regards,

 

Steve

 

Re: using ufusr parm parameter

Experimenter
Experimenter

Hello Steve,

 

really thank you for your effort.


I was wondering why your example worked and mine not.

 

Ok, my problem was, that I used the same label for the menu entry as for the bitmap in the toolbar (in the tbr file).

 

So it seems like in this case when I press the menu item, the handle for the Toolbar Bitmap is called.

 

And the parameter isn't passed for toolbar buttons (I don't why, but it is like that), just only for real menu items. So always empty string has been passed to the ufusr.

 

Is there a possibility to make it work for toolbar buttons also, or another possibility to react different on different button entries? I've seen something with callbacks in the MenuBarCppApp Example, I will have a look into that.

 

Thank you very much again,

Markus

Re: using ufusr parm parameter

Siemens Phenom Siemens Phenom
Siemens Phenom

Markus,

 

You are correct, .tbr files do not behave exactly like .men buttons.  I do not know of a way to do it with toolbar buttons.  (Sorry!)

 

Steve

 

Re: using ufusr parm parameter

Esteemed Contributor
Esteemed Contributor

Try:

Define the button in a .MEN

Then add THAT button (as defined in the .MEN) to your TBR

 

e.g. .MEN file:

 

BUTTON Moog_Excel
LABEL Start Excel
BITMAP moog_excel.bmp
! NOTE: BITMAP must be BEFORE ACTIONS
ACTIONS "start excel.exe"

 .tbr or .rtb:

 

BUTTON Moog_Excel
LABEL Moog Excel
! Bitmap in .MEN 

 

I know defining buttons this way works for .rtb, I am assuming it works for .tbr

I haven't checked to see if the API thinks it is being called by a .tbr or a .men, (i.e. whether parameter is set or not)

(sorry for the edits, I keep seeing something I forgot to mention)

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: using ufusr parm parameter

Experimenter
Experimenter

Thank you very much for this information, it was very helpful. Now it works as it should.

 

Thank you all for your help,

Markus