admin 发表于 2013-11-6 19:00:16

NX二次开发源码分享:NXManager中,获取用户的组和角色

在集成环境中,NX和teamcenter的集成中,获取当前用户的组group 和角色 role。

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

#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/LogFile.hxx>
#include <NXOpen/PDM_SessionSettings.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Session.hxx>

using namespace NXOpen; // <== Very Important!

#include <stdarg.h>

static void ECHO(char *format, ...)
{
    char msg;
    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;

      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);
}


static void do_it(void)
{
    Session *theSession = Session::GetSession();
    Part *workPart(theSession->Parts()->Work());
    Part *displayPart(theSession->Parts()->Display());
   
    PDM::SessionSettings *sessionSettings1;
    sessionSettings1 = theSession->NewDatabaseSessionOptions();
   
    NXString CurrentGroup;
    CurrentGroup = sessionSettings1->Group();
   
    NXString CurrentRole;
    CurrentRole = sessionSettings1->Role();

    theSession->ListingWindow()->Open();
   
    theSession->ListingWindow()->WriteLine("Current Group: ");
    theSession->ListingWindow()->WriteLine(CurrentGroup);
      
    theSession->ListingWindow()->WriteLine("Current Role: ");   
    theSession->ListingWindow()->WriteLine(CurrentRole);

}

/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
    if (UF_CALL(UF_initialize())) return;
    do_it();
    UF_terminate();
}

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

yuleihz 发表于 2016-4-16 23:42:58

主要体现在哪些地方吗

licxsw 发表于 2019-12-10 17:53:21

为什么拷贝代码 会产生一连串乱码呢?是防止拷贝吗?
页: [1]
查看完整版本: NX二次开发源码分享:NXManager中,获取用户的组和角色