[求助]谁能帮我解决:如何编程使预览居中的问题?
<P>下面是我的程序,选择两个举行区域,然后对两个区域内的图形进行预览,但是有时候预览的图形并不居中,不知为什么?</P><P>希望高手能够指点,帮忙看看.</P> <P>(defun c:test ()<BR> (vl-load-com)<BR> (vl-cmdf "_.ucs" "_world")<BR> (setq clayout<BR> (vla-item (vla-get-layouts<BR> (vla-get-activedocument (vlax-get-acad-object))<BR> )<BR> "Model"<BR> )<BR> )</P>
<P> (vla-put-configname clayout "传真") ;此处应根据实际情况修改来设置打印设备</P>
<P> (vla-put-centerplot clayout :vlax-true)<BR> (vla-put-CanonicalMediaName clayout "A4")<BR> (vla-put-plotwithplotstyles clayout :vlax-true)<BR> (vla-put-standardscale clayout acscaletofit)<BR> (setq cplot (vla-get-plot (vla-get-activedocument (vlax-get-acad-object))))<BR> ;<BR> (setq i 1 points '() pointsT '())<BR> (while (< i 8)<BR> (setq pt1 (getpoint "\n 1st point :"))<BR> (setq pt2 (getcorner pt1 "\n 2st point :"))<BR> (setq pointsT (list pt1 pt2))<BR> (setq points (cons pointsT points))<BR> (setq i (+ i 1))<BR> )<BR> ;<BR> (setq i 0)<BR> (while (< i 7)<BR> (setq pt1 (car (nth i points))<BR> pt2 (cadr (nth i points))<BR> )<BR> (setq p1 (vlax-make-safearray vlax-vbdouble '(1 . 2)))<BR> (setq pv1 (vlax-make-variant (vlax-safearray-fill p1 (list (car pt1) (cadr pt1)) )))<BR> (setq p2 (vlax-make-safearray vlax-vbdouble '(1 . 2)))<BR> (setq pv2 (vlax-make-variant (vlax-safearray-fill p2 (list (car pt2) (cadr pt2)) )))<BR> ;<BR> (vla-setwindowtoplot clayout pv1 pv2)<BR> (vla-put-plottype clayout acwindow )<BR> ;<BR> (if (> (abs (- (car pt1) (car pt2))) (abs (- (cadr pt1) (cadr pt2))) )<BR> (vla-put-plotrotation clayout ac90degrees)<BR> (vla-put-plotrotation clayout ac180degrees)<BR> )<BR> ;<BR> (princ "\n preview.....")<BR> ;(setq cplot (vla-get-plot (vla-get-activedocument (vlax-get-acad-object))))<BR> (vla-displayplotpreview cplot acfullpreview)<BR> ;<BR> (setq i (+ i 1))<BR> )<BR> ;<BR> (vl-cmdf "_.ucs" "_P")<BR> (prin1)<BR>);</P> 怎么没有人帮忙解决,斑竹帮帮我呀,急用! <P>预览的图形并不居中.....AUTOCAD本身并没有在同一视窗框选就能居中的功能,</P>
<P>居中要另加处理,要先找出物件包围外框,再ZOOM包围外框,才能把物件居中预览</P> 请教斑竹,怎样才能用程序实现你说的呢?能否给个例子参考一下. <P>;;找物件包围外框,看你如何用了!</P>
<P>;;程序改好再贴上来好吗?</P>
<P>(defun C:BOUND (/ BLK_BOUND PT1 PT2)<BR> (setq BLK_BOUND (ACET-GEOM-SS-EXTENTS (ssget) t))<BR> (setq PT1 (car BLK_BOUND))<BR> (setq PT2 (cadr BLK_BOUND))<BR> (command "_.RECTANG" PT1 PT2)<BR>)</P> <P>谢谢龙龙仔,我先试试吧,看行不行.</P>
<P>有问题再向你请教:)</P>
<P> </P> 龙龙仔,已经按你的方法做了,好像还是不行.我的想法是框选时选定的就是包围框,然后ZOOM包围外框,最后预览还是不能居中,为什么?我怀疑是不是与margin有关? <P>以下是我的修改后的程序,请帮我看看对不对:</P>
<P> (defun c:test ()<BR> (vl-load-com)<BR> (vl-cmdf "_.ucs" "_world")<BR> (setq clayout<BR> (vla-item (vla-get-layouts<BR> (vla-get-activedocument (vlax-get-acad-object))<BR> )<BR> "Model"<BR> )<BR> )<BR> (vla-put-configname clayout "传真") ;此处应根据实际情况修改来设置打印设备<BR> (vla-put-centerplot clayout :vlax-true)<BR> (vla-put-CanonicalMediaName clayout "A4")<BR> (vla-put-plotwithplotstyles clayout :vlax-true)<BR> (vla-put-standardscale clayout acscaletofit)<BR> (setq cplot (vla-get-plot (vla-get-activedocument (vlax-get-acad-object))))<BR> ;<BR> (setq i 1 points '() pointsT '())<BR> (while (< i 8)<BR> (setq pt1 (getpoint "\n 1st point :"))<BR> (setq pt2 (getcorner pt1 "\n 2st point :"))<BR> (setq pointsT (list pt1 pt2))<BR> (setq points (cons pointsT points))<BR> (setq i (+ i 1))<BR> )<BR> ;<BR> (setq i 0)<BR> (while (< i 7)<BR> (setq pt1 (car (nth i points))<BR> pt2 (cadr (nth i points))<BR> )<BR> (setq p1 (vlax-make-safearray vlax-vbdouble '(1 . 2)))<BR> (setq pv1 (vlax-make-variant (vlax-safearray-fill p1 (list <BR> (car pt1) (cadr pt1)) )))<BR> (setq p2 (vlax-make-safearray vlax-vbdouble '(1 . 2)))<BR> (setq pv2 (vlax-make-variant (vlax-safearray-fill p2 (list <BR> (car pt2) (cadr pt2)) )))<BR> ;<BR> (vla-setwindowtoplot clayout pv1 pv2)<BR> (vla-put-plottype clayout acwindow )<BR> ;<BR> (if (> (abs (- (car pt1) (car pt2))) (abs (- (cadr pt1) (cadr <BR> pt2))) )<BR> (vla-put-plotrotation clayout ac90degrees)<BR> (vla-put-plotrotation clayout ac180degrees)<BR> )<BR> ;<BR> ;-----------start 增加的-----------------<BR> (setq p1 (vlax-make-safearray vlax-vbdouble '(1 . 3)))<BR> (setq ll (vlax-make-variant (vlax-safearray-fill p1 (list (car pt1) (cadr pt1) (caddr pt1)) )))<BR> (setq p2 (vlax-make-safearray vlax-vbdouble '(1 . 3)))<BR> (setq ur (vlax-make-variant (vlax-safearray-fill p2 (list (car pt2) (cadr pt2) (caddr pt2)) )))</P>
<P> (vla-zoomwindow (vlax-get-acad-object) ll ur)<BR> ;-----------end 增加的-----------------</P>
<P> (princ "\n preview.....")<BR> <BR> (vla-displayplotpreview cplot acfullpreview)<BR> ;<BR> (setq i (+ i 1))<BR> )<BR> ;<BR> (vl-cmdf "_.ucs" "_P")<BR> (prin1)<BR> );</P> <P>你根本没有照的说的改呀!物件包围外框---你没有找出来.....</P>
<P> </P>