点击查看详细介绍

NXopenC++ 批量打印源代码

haolin2008 9年前 11719 90

购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008  QQ号:85585969  


NXOpenC++

using namespace NXOpen;
using namespace std;
extern "C" DllExport int ufusr_ask_unload()
{
        return (int)Session::LibraryUnloadOptionImmediately;
}
NXOpen::PrintBuilder::PaperSize get_page_size(Drawings::DrawingSheet *drawingSheet1)
{
        NXOpen::PrintBuilder::PaperSize paper =PrintBuilder::PaperSizeA4;
double height=drawingSheet1->Height();
        double length=drawingSheet1->Length();
        string pagesize="";
        if(height==210&&length==297){pagesize="A4";}
pagesize="打印纸张大小:"+pagesize;
char aa[14][38]={"A1","A2","A3","A4"};
char  title[132]="提示";
        UF_UI_MESSAGE_DIALOG_TYPE dialog_type=UF_UI_MESSAGE_QUESTION; 
        char * mess[5];        
        char tmp[132];
        strcpy(tmp,pagesize.c_str());
        mess[0]=tmp;
        
        int num_messages=1; 
        logical translate=true; 
        UF_UI_message_buttons_t buttons;
        int response=0;
char ms1[132]="打印";char ms2[132]="重新选择纸张";
        buttons.button1=true;
        buttons.button2=false;
        buttons.button3=true;
        buttons.label1=ms1;;
        buttons.label2=ms2;
        buttons.label3=ms2;
        buttons.response1=1;
        buttons.response2=2;
        buttons.response3=3;
UF_UI_message_dialog
                (title, dialog_type, mess, num_messages, translate, & buttons, &response );
if (response==3)
        {
                UF_UI_lock_ug_access( UF_UI_FROM_CUSTOM );
                char title[132]="选择纸张";
                response =uc1603(title,0,aa,4);
UF_UI_unlock_ug_access( UF_UI_FROM_CUSTOM );
                if(response==5)
                {        paper =PrintBuilder::PaperSizeCustom;
                }
                if(response==6)
                {

                paper =PrintBuilder::PaperSizeA2;//       
 printBuilder1->SetPaper( PrintBuilder::PaperSizeA2);       
 needprint=true;
                }
                if(response==7)
                {

                paper =PrintBuilder::PaperSizeA3;//       
 printBuilder1->SetPaper( PrintBuilder::PaperSizeA3);       
 needprint=true;
                }
                if(response==8)
                {

                        paper 
=PrintBuilder::PaperSizeA4;//printBuilder1->SetPaper( 
PrintBuilder::PaperSizeA4);        needprint=true;
                }
        
        }
        return paper;
}
void print_curent_dwg(std::string printname )
{
        Session *theSession = Session::GetSession();
        Part *workPart(theSession->Parts()->Work());
PrintBuilder *printBuilder1;
        printBuilder1 = workPart->PlotManager()->CreatePrintBuilder();
printBuilder1->SetCopies(1);
        printBuilder1->SetThinWidth(4.0);
        printBuilder1->SetNormalWidth(5.0);
        printBuilder1->SetThickWidth(6.0);
        printBuilder1->SetRasterImages(true);
        printBuilder1->SetOutput(PrintBuilder::OutputOptionWireframeBlackWhite);
std::vectorsheets1(1);
        Drawings::DrawingSheet *drawingSheet1(workPart->DrawingSheets()->CurrentDrawingSheet());
        sheets1[0] = drawingSheet1;
        printBuilder1->SourceBuilder()->SetSheets(sheets1);
        printBuilder1->SetPrinterText(printname.c_str());
        printBuilder1->SetOrientation(PrintBuilder::OrientationOptionLandscape);
        NXOpen::PrintBuilder::PaperSize paper = get_page_size(drawingSheet1);
        printBuilder1->SetPaper(paper);
        if(        paper ==PrintBuilder::PaperSizeCustom){printBuilder1->SetCustomPaper(271);}
        NXObject *nXObject1= printBuilder1->Commit();
        printBuilder1->Destroy();
}

●●●请先 登陆注册 后查看●●●

extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
{
        UF_initialize();
        do_print();
        uc1601("Finish",0);
        return;
}


2

最新回复 (90)
  • yccong 9年前
    1

    学习中,谢谢楼主分享!

  • q1355188058 9年前
    2

    这个批量打印出来的效果怎样??期待编译成功

  • q1355188058 8年前
    3

    编译成功,打印提示错误信息........

  • leader_ld 8年前
    4

    学习。。。。。。。。。。。。

  • wucrew 8年前
    5

    谢谢分享,学习,辛苦了

  • lvrendos 8年前
    6

    欢迎您使用本贴吧发帖

  • pengfujun VIP会员 8年前
    7

    这个批量打印出来的效果怎样??

  • lzhyi VIP会员 8年前
    8

    谢谢分享,学习,辛苦了

  • YING140526 8年前
    9

    学习中,任何代码都不放过

  • wgp1109 8年前
    10

    谢谢分享谢谢分享谢谢分享

  • alen_923 8年前
    11

    谢谢分享谢谢分享谢谢分享

  • liuchanglin 8年前
    12

    编译成功,打印提示错误信息......

  • tong3261826 8年前
    13

    11111111111111

  • WHY0007 8年前
    14

    谢谢分享,谢谢楼主,好东西

  • bbs1860 8年前
    15

    学习中,谢谢分享!!!

请登录后发表新帖