购买与咨询 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;
}