明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 6225|回复: 13

[求助]关于getWindowToPlot和setWindowToPlot的问题

  [复制链接]
发表于 2004-3-17 22:45:00 | 显示全部楼层 |阅读模式
我想直接调用预览打印,然后就用了activex中的getwindowtoplot,但调试结果总是nil。后来看开发帮助中getwindowtoplot和setwindowtoplot的用法居然是一样的。我不知道怎么错了。请斑竹帮一把。(另外,DisplayPlotPreview能预览打印,但不能实现框选过程,所以不实用!) 下面是调试有错的代码。请斧正。 (setq p1 (vlax-make-safearray vlax-vbdouble '(1 . 2)))
(setq s1 (vlax-safearray-fill p1 '(271.16 192.83)))
(setq v1 (vlax-make-variant s1))
(setq p2 (vlax-make-safearray vlax-vbdouble '(2 . 3)))
(setq s2 (vlax-safearray-fill p2 '(693.85 456.52)))
(setq v2 (vlax-make-variant s2))
(VLA-getWindowToPlot
(vla-item(vla-get-LAYOUTs
(vla-get-activedocument (vlax-get-acad-object))) "model")
v1 v2
)
发表于 2004-3-17 23:10:00 | 显示全部楼层
(VLA-getWindowToPlot
(vla-item(vla-get-LAYOUTs
(vla-get-activedocument (vlax-get-acad-object))) "model")
' v1 'v2
) getWindowToPlot是得到当前的框选范围,而不是实施打印。返回值需要存入两个点变量,所以你参数V1,V2应该提供提供符号而不是值。 setWindowToPlot也不是实施打印的,它是设定当前的打印框选范围。然后你设定打印方式为Window后,再用plot方法打印。 总之,真正的打印都是由那个Plot(或者叫PlotToDevice吧,方法的名称记不清了,我手头没有安装AutoCAD,凭记忆答一下吧)实施的。
发表于 2004-3-17 23:14:00 | 显示全部楼层

另,找一段我以前写的代码给你参考参考

这里只是片断,前后都省略了,虽然我并不清楚你需要实现什么,这段代码也许对你有参考价值。
  1.        ……       (vla-getpapersize clayout 'pWidth 'pHeight)
  2.        ;; 取得当前纸张的长边长度
  3.        (if  (< pwidth pheight)
  4.            (setq paperWidth pHeight)
  5.            (setq paperwidth pWidth)
  6.        )
  7.        (if  (and (= mode "FILE") (= "1" (getvalue 'DeletePlotFile)))
  8.            (foreach pltfile (GetPlotFileList)
  9.   (princ "\n删除已有打印文件:")
  10.   (princ (strcat (getvalue 'PlotFileFolder) pltfile))
  11.   (vl-file-delete (strcat (getvalue 'PlotFileFolder) pltfile))
  12.            )
  13.        )
  14.        ;; 对每个图框循环
  15.        (foreach bounding bdlist
  16.            (vla-put-paperunits clayout acMilliMeters)
  17.            ;;(vla-put-plotorigin clayout (ax:2dpoint '(0 0)))
  18.            ;; 设置打印方向
  19.            (if (= (islandscape bounding) (> pWidth pHeight))
  20.   (vla-put-plotrotation clayout ac0degrees)
  21.   (vla-put-plotrotation clayout ac90degrees)
  22.            )
  23.            ;; 设置打印范围
  24.            (vla-SetWindowToPlot
  25.   clayout
  26.   (ax:2dpoint (car bounding))
  27.   (ax:2dpoint (cadr bounding))
  28.            )
  29.            ;; (apply 'vl-cmdf (cons "rectang" bounding))
  30.            ;; 设置打印方式为window
  31.            (vla-put-plottype clayout acWindow)
  32.            ;; 设置打印比例
  33.            (cond ((= plotscale "ScaleToFit")
  34.            (progn (vla-put-standardscale clayout acScaleToFit)
  35.            (princ "\n当前打印比例: 适合可打印区域\n")
  36.            )
  37.          )
  38.          ((= plotscale "Auto")
  39.            (progn (setq scale (fix (+ 0.5 (/ (getwidth bounding) paperwidth))))
  40.            (vla-put-standardscale clayout acVpCustomScale)
  41.            (vla-setcustomscale clayout 1 scale)
  42.            (princ "\n当前打印比例 = 1:")
  43.            (princ scale)
  44.            (princ "\n")
  45.            )
  46.          )
  47.          ('T
  48.            (progn (vla-put-standardscale clayout acVpCustomScale)
  49.            (vla-setcustomscale clayout 1 plotscale)
  50.            (princ "\n当前打印比例 = 1:")
  51.            (princ plotscale)
  52.            (princ "\n")
  53.            )
  54.          )
  55.            )
  56.            ;; 设置自动居中打印
  57.            (vla-put-centerplot clayout :vlax-true)
  58.            ;; 打印或览
  59.            (cond ((= mode "PLOT")
  60.            (progn
  61.                (princ "\n打印份数: ")
  62.                (princ (getvalue 'Copies))
  63.                (princ "\n")
  64.                (vla-put-NumberofCopies plot (read (getvalue 'Copies)))
  65.                (if (= :vlax-false (vla-plotToDevice plot))
  66.      (exit)
  67.                )
  68.            )
  69.          )
  70.          ((= mode "PREVIEW")
  71.            (if (= :vlax-false (vla-displayplotpreview plot acfullpreview))
  72.                (exit)
  73.            )
  74.          )
  75.          ((= mode "FILE")
  76.            (progn (setq pltfilebaselist (mapcar 'vl-filename-base (GetPlotFileList)))
  77.            (setq plotfile (GetNewAutoNumName (getvalue 'PlotFilePrefix) 2 pltfilebaselist))
  78.            (setq plotfile (strcat (GetValue 'PlotFileFolder) plotfile ".plt"))
  79.            (princ "\n生成打印文件: ")
  80.            (princ plotfile)
  81.            (princ "\n")
  82.            (vla-plottofile plot plotfile)
  83.            )
  84.          )
  85.            )
  86.            (if (and (= mode "PREVIEW") (/= bounding (last bdlist)))
  87.   (progn (initget "Yes No")
  88.                (setq key (getkword "是否继续预览下一张? [Yes/No]<Yes>"))
  89.                (if (= key "No")
  90.      (exit)
  91.                )
  92.   )
  93.            )……
 楼主| 发表于 2004-3-17 23:23:00 | 显示全部楼层
不对呀。v1 ,v2应该既不是符号也不是值,是变体才对啊。不知道加上‘算什么了。


如果按你的意思,setWindowToPlot到底有什么用,难道不能实现 1 框选 2 预览 3 打印 。在实际中 2 和3 是连在一起的。而1的过程可以通过另外的方式得到 两个角点点位(比如直接输入,或者通过封闭pline得到。)


activex的帮助上却说能用setwindowtoplot做到。
发表于 2004-3-17 23:31:00 | 显示全部楼层
setWindowToPlot仅仅是设定一组数值。


getWindowToPlot仅仅是返回一组数值。


它们都不直接执行打印。


提供符号是指把这个符号提供给Vlisp,让它用这个符号存储你得到的那个变体。在你这个程序中,应该用SetWindowToPlot。如果用getWindowToPlot, 那么你前面的赋值将会被get来的数取代(前提是你能正确使用Get……)


如果你不懂为什么getWindowToPlot的参数为什么要加单引号,建议你回头再去看看AutoLISP的基础知识。


单引号相当于Quote函数。
发表于 2004-3-17 23:36:00 | 显示全部楼层
关于参数加单引号的例子,我举一个吧,也许能帮你。
  1. ;;;返回一个单独图元的范围 (取得物体的包围盒, 实际应用中可以用来取图框范围等等)
  2. (defun ax:GetBoundingBox (ent / ll ur)
  3.    (vla-getboundingbox (vlax-ename->vla-object ent) 'll 'ur)
  4.    (mapcar 'vlax-safearray->list (list ll ur))
  5. )
在上面这个函数中,参数ll与ur都加了单引号,用来取得返回值。
 楼主| 发表于 2004-3-17 23:57:00 | 显示全部楼层
谢谢,谢谢。还要努力学习。其实我想做的是一个批量打印程序。在dcl的对话框中象autocad本身的plot命令那样用popup_list列出一些基本参数,比如:plotdevice ;plotstylesheet;papersize,图框名(图框是以外框为封闭多段线画成然后做成块)。然后用户可以直接选择,然后就可以批量打印了。


因为在实际中(比如画加工图),在一个layout空间中,往往用户是用一个或者一两个图框然后实施放大缩小绘制的。所以会以几个图框名字画几十张图。单用plot来完成就要逐个的框选,十分麻烦。所以我就写了那样的一个程序。其他都实现了(其中框选过程是用(tblnext "block") 然后过滤出*a3* *a4* *图框*这样的块)。


但就是在完善的过程中,我觉得应该加上预览过程,就有了上面的问题。谢谢你的帮助。还有个“过分”的要求,能把那个程序的所有代码看看吗?activex刚自学不久:)
 楼主| 发表于 2004-3-18 00:13:00 | 显示全部楼层
下面是草草的lisp源代码 (defun c:qplot ()
;;;;;;;;返回图框角点;;;;;;;;
(defun get_block_corner ( en )
(setq entlist (entget en '("*")))
(setq c_scale (cdr (assoc 41 entlist))
c_to_ucs (trans (cdr (assoc 10 entlist) ) 0 1)
)
(if (>= (- c_scale (fix c_scale)) 0.5)
(setq c_scale(itoa (1+ (fix c_scale))))
(setq c_scale (itoa (fix c_scale)))
)
(setq dict_block_name (cdr(assoc 2 entlist))
dict_block_list (tblsearch "block" dict_block_name)
dict_block_xobject(cdr (assoc -2 dict_block_list))
block_xlist '()
)
(while (setq block_xlist (cons (entget dict_block_xobject) block_xlist)
dict_block_xobject (entnext dict_block_xobject)
)
)
(setq block_xlist (reverse block_xlist))
(setq len_th (length block_xlist)
list1 '()
)
(repeat len_th
(if(and
(vl-position '(0 . "LWPOLYLINE") (nth 0 block_xlist))
(vl-position '(70 . 1) (nth 0 block_xlist))
)
(setq list1 (cons (nth 0 block_xlist) list1 )
block_xlist (vl-remove (nth 0 block_xlist) block_xlist))
(setq block_xlist (vl-remove (nth 0 block_xlist) block_xlist))
)
)
(setq list1 (car list1)
counter 0
p_list '()
)
(while (setq bb (nth counter list1))
(if (= (car bb) 10)
(setq point (nth counter list1)
p_list (cons point p_list)
counter (1+ counter)
)
(setq counter (1+ counter))
)
)

(setq scale_l (list (read c_scale)(read c_scale)(read c_scale)))
(setq dp(cdr(nth 0 p_list))
p0 (mapcar '+ (mapcar '* scale_l
(reverse(cons '0.0 (reverse dp)))) c_to_ucs))
(setq dp(cdr(nth 1 p_list))
p1 (mapcar '+ (mapcar '* scale_l
(reverse(cons '0.0 (reverse dp)))) c_to_ucs))
(setq dp(cdr(nth 2 p_list))
p2 (mapcar '+ (mapcar '* scale_l
(reverse(cons '0.0 (reverse dp)))) c_to_ucs))
(setq dp(cdr(nth 3 p_list))
p3 (mapcar '+ (mapcar '* scale_l
(reverse(cons '0.0 (reverse dp)))) c_to_ucs))
(setq p_l(list p0 p1 p2 p3))
)
;;;;;;;;;;;;框选打印;;;;;;;;;;;;
(defun plot_by_window (de paper point1 point2 table)
(command ".plot" "y" "" de paper "" "" "" "w" point1 point2 "" "" "" table "" "" "" "" "")
)
;;;;;;;;;;;返回打印设备字符串;;;;;;;
(defun get_device ()
(setq plotdevice_list
(vlax-safearray->list
(vlax-variant-value
(vla-getplotdevicenames
(vla-item (vla-get-layouts
(vla-get-activedocument (vlax-get-acad-object))
) "Model"
)
)
)
)
)
)
;;;;;;返回笔样式字符串;;;;;;;
(defun get_table()
(setq plottable_list
(vlax-safearray->list
(vlax-variant-value
(vla-getplotstyletablenames
(vla-item (vla-get-layouts
(vla-get-activedocument (vlax-get-acad-object))
) "Model"
)
)
)
)
)
(setq plottable_list (cons "None" plottable_list))
)
;;;;;;;;;返回图框字符串;;;;;;;;
(defun get_drawing_outline_border ()
(setq block_list '())
(tblnext "block" 0)
(while (setq block_fh (tblnext "block"))
(if (wcmatch (cdr (assoc 2 block_fh)) "*a4*,*a3*,*A3*,*A4*,*图框*")
(setq block_list (cons (cdr (assoc 2 block_fh)) block_list))
T
)
)
(setq block_list (cons "None" block_list))
)
;;;;;;;;;;;main function;;;;;;;;
(vl-load-com)
(setvar "cmdecho" 0)
(setq paper_list '("None" "A3" "A4" "A5"))
(get_device)
(get_table)
(get_drawing_outline_border)
(new_dialog "qplot" (load_dialog "qplot-dcl"))
;;;;papersize
(start_list "Psize")
(foreach v paper_list
(add_list v)
)
(end_list)
(set_tile "Psize" "0")
(action_tile "Psize"
"(setq pa_num $Value) " )
;;;;plotdevice
(start_list "Pdevice")
(foreach v plotdevice_list
(add_list v)
)
(end_list)
(set_tile "Pdevice" "0")
(action_tile "Pdevice"
"(setq de_num $Value) ")
;;;;plottable
(start_list "Pstyle")
(foreach v plottable_list
(add_list v)
)
(end_list)
(set_tile "Pstyle" "0")
(action_tile "Pstyle"
"(setq tab_num $Value) ")
;;;;drawing outline border
(start_list "Tmane")
(foreach v block_list
(add_list v)
)
(end_list)
(set_tile "Tmane" "0")
(action_tile "Tmane"
"(setq T_num $Value) ")

;;;;
(set_tile "Pnumber" "1")
;;;;
(if(= 1 (start_dialog))
(progn
(setq device (nth (read de_num) plotdevice_list ))
(setq paper (nth (read pa_num) paper_list ))
(setq table (nth (read tab_num) plottable_list ))
(setq tk (nth (read T_num) block_list ))
(if (not (setq ss (ssget "x" (list(cons 2 tk)))))
(progn (alert (strcat "No Matching Drawing-Outline-Border " " \nFunction Will Exit...") ) (exit))
t)
(setq ss_l (sslength ss)
cou 0)
(while (setq ename (ssname ss cou))
(progn
(get_block_corner ename)
(plot_by_window device paper p0 p2 table)
(setq cou (1+ cou))
)
)
)
(princ "\nCant Load Dcl")
)
(setvar "cmdecho" 1)
)
 楼主| 发表于 2004-3-18 00:14:00 | 显示全部楼层
下面是草草的dcl代码 qplot : dialog
{label = "QuickPlot Verion 1.0 By lq 2004.3.15";
: column
{: row
{
: popup_list
{label = "PlotDevice";
width = 40;
key = "Pdevice";
}
: popup_list
{ label = "StyleTable";
edit_width = 16;
height = 3;
key = "Pstyle";
}
}
: row
{
: popup_list
{label = "Papersize";
edit_width = 16;
height = 3;
key = "Psize";
}
: popup_list
{ label = "OutlineBorder";
width = 30;
height = 3;
key = "Tmane";
}
}
: row
{
: edit_box
{label = "NumberOfCopy";
height = 1;
width = 3;
fixed_height = true;
fixed_width = true;
key = "Pnumber";
}
}
}

ok_cancel;
}

 楼主| 发表于 2004-3-18 00:36:00 | 显示全部楼层
秋枫老师,请帮忙啊。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-10-1 19:34 , Processed in 0.192411 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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