CAD如何直接打印,不出现打印对话框?

Posted yzy0224

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CAD如何直接打印,不出现打印对话框?相关的知识,希望对你有一定的参考价值。

主要用到函数说明:

 

MxDrawXCustomFunction::Mx_Print

 

直接打印,不出现打印对话框,详细说明如下:

 

参数说明

double ptLBx

打印的范围左下角x

double ptLBy

打印的范围左下角y

double ptRTx

打印的范围右上角x

double ptRTy

打印的范围右上角y

LPCTSTR pszPrintName

打印机名,如果传为空,取系统默认打印机

LPCTSTR pszPaperName

打印的图纸名,如果传为空,取系统默认打印机设置

LONG iPrintDirection

打印的方向,2 为横向,1为纵向,默认取1

LONG iLeftMargin

打印的页边的左边距离,如果为-1,取打印机默认的页边距

LONG iRightMargin

打印的页边的右边距离,如果为-1,取打印机默认的页边距

LONG iTopMargin

打印的页边的上边距离,如果为-1,取打印机默认的页边距

LONG iBottomMargin

打印的页边的下边距离,如果为-1,取打印机默认的页边距

LPCTSTR pszLayoutName

打印的布局,为NULL就是模型Model中的内容

LPCTSTR pszPrintConfig

打印配制,暂没有使用

LPCTSTR pszDocName

打印的文档名称,在用pdf虚拟打印机时,指定打印的pdf文件的缺省文件名

LONG lIsPrintLineWdith

是否打印线宽,默认值为1,表示打印,传0表示不打印

iFlag

pRectPageMargin参数的含义,iFlag = 0表示页边距,iFlag = 1表示打印区域矩形框位置

 

js代码实现如下:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
            function  myprint()
            
                var axMxDrawX = document.getElementById("MxDrawXCtrl");
                var viewBound  = axMxDrawX.Call("Mx_GetViewCoord","");
 
                var printParam =  axMxDrawX.Call("Mx_NewResbuf","");                
                // 打印范围取当前视区显示内容                
                printParam.AddDouble(viewBound.AtDouble(1));
                printParam.AddDouble(viewBound.AtDouble(2));
                printParam.AddDouble(viewBound.AtDouble(3));
                printParam.AddDouble(viewBound.AtDouble(4));
 
                 var jpgWidth = viewBound.AtDouble(3) - viewBound.AtDouble(1);
                var jpgHeight = viewBound.AtDouble(4) - viewBound.AtDouble(2);                
                // 把jpg的宽度,高度,求文档坐标变成象素宽高.
                //var jpgWidth = axMxDrawX.CallDoubleParam1("Mx_DocLongToViewCoord",jpgWidth);
                // jpgWidth = jpgWidth.AtLong(1);
                //var jpgHeight = axMxDrawX.CallDoubleParam1("Mx_DocLongToViewCoord",jpgHeight);
                //jpgHeight = jpgHeight.AtLong(1);
 
                var printWidth = 50;
                var printHeight = 50;                
                if(jpgWidth > 1)
                    printHeight = printWidth * jpgHeight / jpgWidth;                
                    // 打印机名,取空就取系统默认的。                
                    printParam.AddString("");                
                    // 图纸名,取空就取系统默认的                
                    printParam.AddString("");                
                    // 打印的方向,2 为横向,1为纵向,默认取1
                printParam.AddLong(1);                
                // 打印区域的左上角X坐标,图纸单为mm
                printParam.AddLong(50);                
                // 打印区域的右下角X坐标,图纸单为mm
                printParam.AddLong(50 + printWidth );                
                // 打印区域的左上角Y坐标,图纸单为mm
                printParam.AddLong(50);                
                // 打印区域的右下角Y坐标,图纸单为mm
                printParam.AddLong(50 + printHeight);                
                // 打印的布局,为NULL就是模型Model中的内容
                printParam.AddString("");                
                // 打印配制,暂没有使用
                printParam.AddString("");                
                // 打印的文档名称,在用pdf虚拟打印机时,指定打印的pdf文件的缺省文件名
                printParam.AddString("");                
                // 前面打印参数说明:iFlag = 0表示页边距,iFlag = 1表示打印区域矩形框位置                printParam.AddLong(1);                // 开始打印                var ret = axMxDrawX.CallEx("Mx_Print",printParam);                if(ret.AtString(0) == "Ok")
                    alert("打印成功");
            

以上是关于CAD如何直接打印,不出现打印对话框?的主要内容,如果未能解决你的问题,请参考以下文章

CAD布局中怎么批量打印

CAD中的PLOT命令如何使用?

cad打印如何打印A3尺寸

cad如何批量打印?

CAD图纸,图块图纸怎么切割出一部分?

pdf文件不大但打印时非常大,打印很慢,如何解决