这几天有空,想着把在用的批量打印程序修改下,之前用的是command plot,打算改成vl函数。
差不多改完的时候,在用旧图测试的时候,发现一个问题,有部分旧图的打印定位点发生了偏移。
检查了好几遍都没发现代码有什么问题,然后用CAD帮助文件里的示例程序测试了下,发现存在同样的情况。
示例程序代码如下。运行后,提示框里的坐标都是对的,但之后的预览就出现问题。检查发现,pointTemp1、pointTemp2这两个参数的坐标值,与vla-SetWindowToPlot及vla-GetWindowToPlot之后提取的point1、point2也都一致。但不知道为啥,最后预览或者打印出来就会出问题。
附件中的dwg分别是用有问题和正常的旧图,删除所有内容后,放了同一个图框,并清理了一遍。
两个dwg,基本上是一样的了,但不知道为啥,有问题的那个预览就是会偏移,另一个就是正常的。
求教,是不是还是什么参数要进行控制?
 - (defun c:Example_SetWindowToPlot( / acadObj doc point1 pointTemp1 point2 pointTemp2)
- ;; This example allows the user to define an area in the current layout to plot
- ;; and displays a plot preview of the defined area.
- ;;
- ;; * Note: You will have to exit the plot preview
- ;; before the VBA example will stop and control will be returned
- (setq acadObj (vlax-get-acad-object))
- (setq doc (vla-get-ActiveDocument acadObj))
- ;; Get first point in window
- (setq point1 (vlax-variant-value (vla-GetPoint (vla-get-Utility doc) nil "Click the lower-left of the window to plot.")))
- ;; Change this to a 2D array by removing the Z position
- (setq pointTemp1 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
- (vlax-safearray-put-element pointTemp1 0 (vlax-safearray-get-element point1 0))
- (vlax-safearray-put-element pointTemp1 1 (vlax-safearray-get-element point1 1))
-
- ;; Get second point in window
- (setq point2 (vlax-variant-value (vla-GetCorner (vla-get-Utility doc) point1 "Click the upper-right of the window to plot.")))
- ;; Change this to a 2D array by removing the Z position
- (setq pointTemp2 (vlax-make-safearray vlax-vbDouble '(0 . 1)))
- (vlax-safearray-put-element pointTemp2 0 (vlax-safearray-get-element point2 0))
- (vlax-safearray-put-element pointTemp2 1 (vlax-safearray-get-element point2 1))
-
- ;; Send information about window to current layout
- (vla-SetWindowToPlot (vla-get-ActiveLayout doc) pointTemp1 pointTemp2)
-
- ;; Read back window information
- (vla-GetWindowToPlot (vla-get-ActiveLayout doc) 'point1 'point2)
- (setq point1 (vlax-safearray->list point1)
- point2 (vlax-safearray->list point2))
-
- (alert (strcat "Press any key to plot the following window:"
- "\nLower Left: " (rtos (nth 0 point1) 2) ", " (rtos (nth 1 point1) 2)
- "\nUpper Right: " (rtos (nth 0 point2) 2) ", " (rtos (nth 1 point2) 2)))
-
- ;; Make sure the instruction is to plot a view, not some other plot style
- (vla-put-PlotType (vla-get-ActiveLayout doc) acWindow)
- ;; Send Plot To Window - A plot device must be set before a preview can be created
- (vla-put-ConfigName (vla-get-ActiveLayout doc) "DWG To PDF.pc3")
- (vla-DisplayPlotPreview (vla-get-Plot doc) acFullPreview)
- )
|