Proe5.0导出PDF至配置文件的相关方法,VC++

定义文件bcsMessage.txt

PLM
PLM
PLM
#

login
login
测试
#

Active messagebox menu
Active messagebox menu
激活菜单
#

将Menu文件放置与程序同级的text文件夹下

配置ini文件

[BCS]
Path=C:3

将配置文件放置Proe的工作目录下

代码如下:

C++

// bcsproe.cpp : 定义 DLL 的初始化例程。
//

#include "stdafx.h"
#include "bcsproe.h"
#include "afx.h"

#include "ProMenu.h"
#include "ProUtil.h"
#include "ProMenubar.h"
#include "ProPDF.h"

static uiCmdAccessState AccessDefault (uiCmdAccessMode);
void login();
void exportpdf();

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CbcsproeApp

BEGIN_MESSAGE_MAP(CbcsproeApp, CWinApp)
END_MESSAGE_MAP()


// CbcsproeApp 构造

CbcsproeApp::CbcsproeApp()
{
	// TODO: 在此处添加构造代码,
	// 将所有重要的初始化放置在 InitInstance 中
}


// 唯一的一个 CbcsproeApp 对象

CbcsproeApp theApp;


// CbcsproeApp 初始化

BOOL CbcsproeApp::InitInstance()
{
	CWinApp::InitInstance();

	return TRUE;
}
extern "C" int user_initialize()
{
     ProError     status;
     ProFileName  message_file;
     uiCmdCmdId   cmd_id1;
	
     ProFileName MsgFile;
     ProStringToWstring(MsgFile, "bcsMessage.txt");
     status=ProMenubarMenuAdd ("PLM", "PLM","Utilities", PRO_B_TRUE, MsgFile);

	 //login
     status = ProCmdActionAdd("ShowTest1",(uiCmdCmdActFn)login,uiCmdPrioDefault,AccessDefault,
              PRO_B_TRUE,PRO_B_TRUE,&cmd_id1);

     status = ProMenubarmenuPushbuttonAdd("PLM", "login", "login","Active messagebox menu", NULL,
              PRO_B_TRUE, cmd_id1, ProStringToWstring(message_file, "bcsMessage.txt"));
	
	      return status;
}

extern "C" void user_terminate()
{
   AFX_MANAGE_STATE(AfxGetStaticModuleState());
}

/*================================================================*
FUNCTION: AccessDefault()
*================================================================*/
static uiCmdAccessState AccessDefault (uiCmdAccessMode access_mode)
{
    return (ACCESS_AVAILABLE);
}

void login()/////////消息框
{
	exportpdf();return;
}

void exportpdf()
{
	ProError err;
    ProPath current_path;
    char c_p[200];
    err=ProDirectoryCurrentGet(current_path);
    if (err!=PRO_TK_NO_ERROR)
	{
		AfxMessageBox(_T("未获取到Proe起始目录"));
        return;
	}
    ProWstringToString(c_p,current_path);
    CString  strcurrent_path = current_path;

	////获取配置文件路径
	CString FileName =L"\bcsConfiguration.ini"; 
	LPTSTR lpPath = new TCHAR[MAX_PATH];
	LPWSTR Path = new TCHAR[MAX_PATH];
	strcurrent_path = strcurrent_path + FileName;

	//AfxMessageBox(strcurrent_path);
	GetPrivateProfileString(L"BCS",L"Path",L"",Path,MAX_PATH,strcurrent_path);
	//AfxMessageBox(Path);
	if (_tcslen(Path) < 1)
    {
		AfxMessageBox(L"未找到配置信息!");
		return;
	}
	delete [] lpPath;

	ProPDFOptions  ops;
    ProPDFoptionsAlloc(&ops);

    ProMdl mdl;
	//获取文件名
    err = ProMdlCurrentGet(&mdl);
    if (PRO_TK_NO_ERROR != err)
	{
		AfxMessageBox(_T("当前没有文件打开"));
        return;
	}

    ProMode  mode;
    err = ProModeCurrentGet(&mode);
    if (err != PRO_TK_NO_ERROR)
    {
		AfxMessageBox(_T("未获取到当前打开文件"));
        return;
    }

    if (mode != PRO_MODE_DRAWING)
    {
        AfxMessageBox(_T("当前只支持DRW文件导出pdf"));
        return;
    }

    ProName name;
    err = ProMdlNameGet(mdl, name);
    CString cstrName = name;
	CString outfilepathname = Path;
	outfilepathname = outfilepathname +L"\" + cstrName + L".pdf";
	//AfxMessageBox(outfilepathname.GetBuffer(0));

	//导出pdf
    ProPDFExport(mdl,outfilepathname.GetBuffer(0),ops);
    ProPDFoptionsFree(ops);
	AfxMessageBox(_T("导出完成!"));////弹出一个消息框
}

下面是关于在Proe客户端的配置

定义注册文件

 Protk.dat

内容如下:

NAME		pt_inst_test
STARTUP		DLL
ALLOW_STOP	TRUE
DELAY_START	FALSE
EXEC_FILE	C:/Documents and Settings/Administrator/My Documents/bcsproe.dll
TEXT_DIR	C:/Documents and Settings/Administrator/My Documents/text
REVISION	1000
END


若想实现Proe自动注册,则将此文件放置Proe的安装目录的text文件下,例如:C:Program FilesproeWildfire 5.0 ext,具体路径根据自己安装目录指定

注:文件名必须为Protk不能更换

作者:Joe.Fan
         
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/fanxingthink/p/4176152.html