明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3891|回复: 21

[求助]谁能帮我解决:如何编程使预览居中的问题?

  [复制链接]
发表于 2005-12-19 18:24:00 | 显示全部楼层 |阅读模式

下面是我的程序,选择两个举行区域,然后对两个区域内的图形进行预览,但是有时候预览的图形并不居中,不知为什么?

希望高手能够指点,帮忙看看.

 楼主| 发表于 2005-12-19 18:27:00 | 显示全部楼层

(defun c:test ()
  (vl-load-com)
  (vl-cmdf "_.ucs" "_world")
  (setq clayout
  (vla-item (vla-get-layouts
       (vla-get-activedocument (vlax-get-acad-object))
     )
     "Model"
  )
  )

  (vla-put-configname clayout "传真") ;此处应根据实际情况修改来设置打印设备

  (vla-put-centerplot clayout :vlax-true)
  (vla-put-CanonicalMediaName clayout "A4")
  (vla-put-plotwithplotstyles clayout :vlax-true)
  (vla-put-standardscale clayout acscaletofit)
  (setq cplot (vla-get-plot (vla-get-activedocument (vlax-get-acad-object))))
  ;
  (setq i 1 points '() pointsT '())
  (while (< i 8)
    (setq pt1 (getpoint "\n 1st point :"))
    (setq pt2 (getcorner pt1 "\n 2st point :"))
    (setq pointsT (list pt1 pt2))
    (setq points (cons pointsT points))
    (setq i (+ i 1))
  )
    ;
  (setq i 0)
  (while (< i 7)
    (setq pt1 (car (nth i points))
          pt2 (cadr (nth i points))
    )
    (setq p1 (vlax-make-safearray vlax-vbdouble '(1 . 2)))
    (setq pv1 (vlax-make-variant (vlax-safearray-fill p1 (list (car pt1) (cadr pt1)) )))
    (setq p2 (vlax-make-safearray vlax-vbdouble '(1 . 2)))
    (setq pv2 (vlax-make-variant (vlax-safearray-fill p2 (list (car pt2) (cadr pt2)) )))
    ;
    (vla-setwindowtoplot clayout pv1 pv2)
    (vla-put-plottype clayout acwindow )
    ;
    (if (> (abs (- (car pt1) (car pt2))) (abs (- (cadr pt1) (cadr pt2))) )
        (vla-put-plotrotation clayout ac90degrees)
        (vla-put-plotrotation clayout ac180degrees)
    )
    ;
    (princ "\n preview.....")
    ;(setq cplot (vla-get-plot (vla-get-activedocument (vlax-get-acad-object))))
    (vla-displayplotpreview  cplot acfullpreview)
    ;
    (setq i (+ i 1))
  )
  ;
  (vl-cmdf "_.ucs" "_P")
  (prin1)
);

 楼主| 发表于 2005-12-20 19:12:00 | 显示全部楼层
怎么没有人帮忙解决,斑竹帮帮我呀,急用!
发表于 2005-12-21 11:11:00 | 显示全部楼层

预览的图形并不居中.....AUTOCAD本身并没有在同一视窗框选就能居中的功能,

居中要另加处理,要先找出物件包围外框,再ZOOM包围外框,才能把物件居中预览

 楼主| 发表于 2005-12-21 18:00:00 | 显示全部楼层
请教斑竹,怎样才能用程序实现你说的呢?能否给个例子参考一下.
发表于 2005-12-22 07:54:00 | 显示全部楼层

;;找物件包围外框,看你如何用了!

;;程序改好再贴上来好吗?

(defun C:BOUND (/ BLK_BOUND PT1 PT2)
  (setq BLK_BOUND (ACET-GEOM-SS-EXTENTS (ssget) t))
  (setq PT1 (car BLK_BOUND))
  (setq PT2 (cadr BLK_BOUND))
  (command "_.RECTANG" PT1 PT2)
)

 楼主| 发表于 2005-12-22 19:20:00 | 显示全部楼层

谢谢龙龙仔,我先试试吧,看行不行.

有问题再向你请教:)

 

 楼主| 发表于 2005-12-23 21:42:00 | 显示全部楼层
龙龙仔,已经按你的方法做了,好像还是不行.我的想法是框选时选定的就是包围框,然后ZOOM包围外框,最后预览还是不能居中,为什么?我怀疑是不是与margin有关?
 楼主| 发表于 2005-12-23 21:44:00 | 显示全部楼层

以下是我的修改后的程序,请帮我看看对不对:

              (defun c:test ()
                (vl-load-com)
                (vl-cmdf "_.ucs" "_world")
                (setq clayout
                (vla-item (vla-get-layouts
                     (vla-get-activedocument (vlax-get-acad-object))
                   )
                   "Model"
                )
                )
                (vla-put-configname clayout "传真") ;此处应根据实际情况修改来设置打印设备
                (vla-put-centerplot clayout :vlax-true)
                (vla-put-CanonicalMediaName clayout "A4")
                (vla-put-plotwithplotstyles clayout :vlax-true)
                (vla-put-standardscale clayout acscaletofit)
                (setq cplot (vla-get-plot (vla-get-activedocument (vlax-get-acad-object))))
                ;
                (setq i 1 points '() pointsT '())
                (while (< i 8)
                  (setq pt1 (getpoint "\n 1st point :"))
                  (setq pt2 (getcorner pt1 "\n 2st point :"))
                  (setq pointsT (list pt1 pt2))
                  (setq points (cons pointsT points))
                  (setq i (+ i 1))
                )
                  ;
                (setq i 0)
                (while (< i 7)
                  (setq pt1 (car (nth i points))
                        pt2 (cadr (nth i points))
                  )
                  (setq p1 (vlax-make-safearray vlax-vbdouble '(1 . 2)))
                  (setq pv1 (vlax-make-variant (vlax-safearray-fill p1 (list
              (car pt1) (cadr pt1)) )))
                  (setq p2 (vlax-make-safearray vlax-vbdouble '(1 . 2)))
                  (setq pv2 (vlax-make-variant (vlax-safearray-fill p2 (list
              (car pt2) (cadr pt2)) )))
                  ;
                  (vla-setwindowtoplot clayout pv1 pv2)
                  (vla-put-plottype clayout acwindow )
                  ;
                  (if (> (abs (- (car pt1) (car pt2))) (abs (- (cadr pt1) (cadr
              pt2))) )
                      (vla-put-plotrotation clayout ac90degrees)
                      (vla-put-plotrotation clayout ac180degrees)
                  )
                  ;
                  ;-----------start 增加的-----------------
                  (setq p1 (vlax-make-safearray vlax-vbdouble '(1 . 3)))
                  (setq ll (vlax-make-variant (vlax-safearray-fill p1 (list (car pt1) (cadr pt1) (caddr pt1)) )))
                  (setq p2 (vlax-make-safearray vlax-vbdouble '(1 . 3)))
                  (setq ur (vlax-make-variant (vlax-safearray-fill p2 (list (car pt2) (cadr pt2) (caddr pt2)) )))

                  (vla-zoomwindow (vlax-get-acad-object) ll ur)
                  ;-----------end 增加的-----------------

                  (princ "\n preview.....")
 
                  (vla-displayplotpreview  cplot acfullpreview)
                  ;
                  (setq i (+ i 1))
                )
                ;
                (vl-cmdf "_.ucs" "_P")
                (prin1)
              );

发表于 2005-12-26 08:11:00 | 显示全部楼层

你根本没有照的说的改呀!物件包围外框---你没有找出来.....

 

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

本版积分规则

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

GMT+8, 2024-11-6 03:11 , Processed in 0.178568 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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