乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 118|回复: 9

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

[复制链接]

2

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
17
发表于 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
        )
回复

使用道具 举报

37

主题

297

帖子

15

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
449
发表于 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,凭记忆答一下吧)实施的。
回复

使用道具 举报

37

主题

297

帖子

15

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

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

使用道具 举报

2

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
17
发表于 2004-3-17 23:23:00 | 显示全部楼层
不对呀。v1 ,v2应该既不是符号也不是值,是变体才对啊。不知道加上‘算什么了。
如果按你的意思,setWindowToPlot到底有什么用,难道不能实现 1 框选 2 预览 3 打印 。在实际中 2 和3 是连在一起的。而1的过程可以通过另外的方式得到 两个角点点位(比如直接输入,或者通过封闭pline得到。)
activex的帮助上却说能用setwindowtoplot做到。
回复

使用道具 举报

37

主题

297

帖子

15

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
449
发表于 2004-3-17 23:31:00 | 显示全部楼层
setWindowToPlot仅仅是设定一组数值。
getWindowToPlot仅仅是返回一组数值。
它们都不直接执行打印。
提供符号是指把这个符号提供给Vlisp,让它用这个符号存储你得到的那个变体。在你这个程序中,应该用SetWindowToPlot。如果用getWindowToPlot, 那么你前面的赋值将会被get来的数取代(前提是你能正确使用Get……)
如果你不懂为什么getWindowToPlot的参数为什么要加单引号,建议你回头再去看看AutoLISP的基础知识。
单引号相当于Quote函数。
回复

使用道具 举报

37

主题

297

帖子

15

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
449
发表于 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都加了单引号,用来取得返回值。
回复

使用道具 举报

2

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
17
发表于 2004-3-17 23:57:00 | 显示全部楼层
谢谢,谢谢。还要努力学习。其实我想做的是一个批量打印程序。在dcl的对话框中象autocad本身的plot命令那样用popup_list列出一些基本参数,比如:plotdevice ;plotstylesheet;papersize,图框名(图框是以外框为封闭多段线画成然后做成块)。然后用户可以直接选择,然后就可以批量打印了。
因为在实际中(比如画加工图),在一个layout空间中,往往用户是用一个或者一两个图框然后实施放大缩小绘制的。所以会以几个图框名字画几十张图。单用plot来完成就要逐个的框选,十分麻烦。所以我就写了那样的一个程序。其他都实现了(其中框选过程是用(tblnext "block") 然后过滤出*a3* *a4* *图框*这样的块)。
但就是在完善的过程中,我觉得应该加上预览过程,就有了上面的问题。谢谢你的帮助。还有个“过分”的要求,能把那个程序的所有代码看看吗?activex刚自学不久:)
回复

使用道具 举报

2

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
17
发表于 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)
         )
回复

使用道具 举报

2

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
17
发表于 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;                 
                                                                                 }                 
                                                                                 
回复

使用道具 举报

2

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
17
发表于 2004-3-18 00:36:00 | 显示全部楼层
秋枫老师,请帮忙啊。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-8-15 11:13 , Processed in 2.508610 second(s), 73 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表