找回密码
 立即注册

QQ登录

只需一步,快速开始

微信扫码登录

搜索
查看: 1872|回复: 1

[求助] UG的二次开发之批量导出pdf图出现错误

[复制链接]

5

主题

8

回帖

187

积分

上等兵

积分
187
发表于 2022-3-30 14:33:43 | 显示全部楼层 |阅读模式
参考阿飞的C++多线程批量导出pdf,为什么,会出现如下错误啊

错误:
====================================================
'D:\2\NXBINNXOpenCPP_Wizard5.exe' 不是内部或外部命令,也不是可运行的程序



这个也没有空格啊,其实就是两个exe,但出现了以上错误


//主程序
extern "C" DllExport int ufusr_ask_unload()
{
// Unloads the image when the application completes
return (int)Session::LibraryUnloadOptionImmediately;

}
DWORD WINAPI ThreadProc1(LPVOID lpParameter)
{
    printf("线程1开始\n");
    int* p = (int*)lpParameter;//传入参数转换
    for (int i = 0; i < 10; i++)
    {
        printf(".\n");
        char msg[256];
        sprintf_s(msg, "D:\\2\\NXBINNXOpenCPP_Wizard5.exe %d", *p);
        system(msg);
        (*p)++;
    }
    printf("线程1结束\n");
    return 0;
}

DWORD WINAPI ThreadProc2(LPVOID lpParameter)
{
    printf("线程2开始\n");
    int* p = (int*)lpParameter;//传入参数转换
    for (int i = 0; i < 10; i++)
    {
        printf(".\n");
        char msg[256];
        sprintf_s(msg, "D:\\2\\NXOpenCPP_Wizard5.exe %d", *p + 10);
        system(msg);
        (*p)++;
    }
    printf("线程2结束\n");
    return 0;
}

void main()
{
    int a = 0;//传入线程函数的参数,不需传递参数时为NULL
    int b = 0;
    //创建线程1
    DWORD lpThreadId1 = 0;//传出参数,用于获得线程ID,如果为NULL则不返回
    HANDLE hThread1 = CreateThread(NULL, 0, ThreadProc1, &a, 0, &lpThreadId1);
    //WaitForSingleObject(hThread1, INFINITE);//等待单个对象
    //创建线程2
    DWORD lpThreadId2 = 0;
    HANDLE hThread2 = CreateThread(NULL, 0, ThreadProc2, &b, 0, &lpThreadId2);
    getchar();
}


//封装exe
extern void main(char argc, char* argv[])
{
    /* Initialize the API environment */
    UF_initialize();
    /* TODO: Add your application code here */
    //调exe传入参数
    LPWSTR* szArglist = NULL;
    int nArgs = 0;
    szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
    if (nArgs > 1)
    {
        CString str1 = szArglist[1];
        //打开prt
        tag_t PartTag = NULL_TAG;
        UF_PART_load_status_t ErrorStatus;
        UF_PART_open("D:\\_asm1_dwg1.prt", &PartTag, &ErrorStatus);
        NXOpen::Session* theSession = NXOpen::Session::GetSession();
        NXOpen::Part* workPart(theSession->Parts()->Work());
        NXOpen::Part* displayPart(theSession->Parts()->Display());
        NXOpen::PrintPDFBuilder* printPDFBuilder1;
        printPDFBuilder1 = workPart->PlotManager()->CreatePrintPdfbuilder();
        printPDFBuilder1->SetScale(1.0);
        printPDFBuilder1->SetSize(NXOpen::PrintPDFBuilder::SizeOptionScaleFactor);
        printPDFBuilder1->SetUnits(NXOpen::PrintPDFBuilder::UnitsOptionEnglish);
        printPDFBuilder1->SetXDimension(8.5);
        printPDFBuilder1->SetYDimension(11.0);
        printPDFBuilder1->SetOutputText(NXOpen::PrintPDFBuilder::OutputTextOptionPolylines);
        printPDFBuilder1->SetRasterImages(true);
        printPDFBuilder1->SetWatermark("");
        std::vector<NXOpen::NXObject*> sheets1(1);
        NXOpen::Drawings::DrawingSheet* drawingSheet1(dynamic_cast<NXOpen::Drawings::DrawingSheet*>(workPart->DrawingSheets()->FindObject("Sheet 1")));
        sheets1[0] = drawingSheet1;
        printPDFBuilder1->SourceBuilder()->SetSheets(sheets1);
        char msg[256];
        sprintf_s(msg, "D:\\%s.pdf", (LPSTR)(LPCTSTR)str1);
        printPDFBuilder1->SetFilename(msg);
        NXOpen::NXObject* nXObject1;
        nXObject1 = printPDFBuilder1->Commit();
        printPDFBuilder1->Destroy();

        //关闭prt
        UF_PART_close(PartTag, 1, 1);
    }
    //取得参数后,释放CommandLineToArgvW申请的空间
    LocalFree(szArglist);
    /* Terminate the API environment */
    UF_terminate();
}



3

主题

67

回帖

653

积分

三级士官

积分
653
发表于 2022-11-18 15:10:17 | 显示全部楼层
解决了吗
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

咨询QQ:1359218528|发帖须知!|Archiver|手机版|小黑屋|UG爱好者论坛 ( 京ICP备10217105号-2 )

GMT+8, 2024-12-22 21:20

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表