Lisp lệnh PAGESETUPS trong chủ đề “Hỏi về Lisp (thuật toán, ý tưởng, coding,...)”
1 giờ} trướ}c, Duong Nhat Duy đã nói:Cảm ơn bạn nhé, nhưng vẫn không phải ý mình :((
Hàm addPageSetup là hàm thêm 1 pagesetup mới.
Hàm sát với ý mình nhất là hàm SetCurrentPageSetup, ví dụ:
Hàm này chuyển Page setup về "Setup2", ý mình muốn chuyển về None, mình đã thử đổi số thành None, "", nil nhưng vẫn ko đc :((
Bạn chỉ cần tạo pagesetup trên layout (cài đặt máy in, giấy, ....) sau đó coupyform cho các layout khác thì tất cả là None. Bạn tham khảo code sau
;;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/using-and-characters-in-vla-put-canonicalmedianame/td-p/4842089
(defun c:pagesetups()
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq plotCfgs (vla-get-ActiveLayout doc))
(vla-RefreshPlotDeviceInfo plotCfg)
;; Set the plot device
(vla-put-ConfigName plotCfg "DWG To PDG.pc3")
;; Set the paper size
(vla-put-CanonicalMediaName plotCfg "ANSI B \(11.00 x 17.00 Inches\)")
(vla-put-PaperUnits plotCfg acMillimeters)
(setq PLOT_BL (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 1)) '(-53.540381 -6.990000))
PLOT_TR (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 1)) '(814.00000000 537.00000000))
)
(vla-SetWindowToPlot plotCfg PLOT_BL PLOT_TR)
(vla-put-PlotType plotCfg acWindow)
(vla-put-UseStandardScale plotCfg :vlax-true)
(vla-put-StandardScale plotCfg ac1_2)
(vla-put-CenterPlot plotCfg :vlax-false)
;; Hide paperspace objects
(vla-put-PlotHidden plotCfg :vlax-false)
;; Set the plot offset
(setq origin (vlax-make-safearray vlax-vbDouble '(0 . 1)))
(vlax-safearray-fill origin (list 0.0 0.0))
(vla-put-PlotOrigin plotCfg origin)
(vla-put-PlotRotation plotCfg ac90degrees)
(vla-put-PlotViewportBorders plotCfg :vlax-false)
(vla-put-PlotViewportsFirst plotCfg :vlax-false)
(vla-put-PlotWithLineweights plotCfg :vlax-true)
(vla-put-ScaleLineweights plotCfg :vlax-false)
(vla-put-PlotWithPlotStyles plotCfg :vlax-true)
(vla-put-ShowPlotStyles plotCfg :vlax-true)
(vla-put-StyleSheet plotCfg "MTO_monochrome_Half_Size.ctb")
(vla-RefreshPlotDeviceInfo plotCfg)
;http://forums.augi.com/showthread.php?44555-Apply-page-setup-to-multiple-layouts
(vlax-map-collection
(vla-get-layouts doc)
'(lambda (x)
(if (eq (vla-get-modeltype x) :vlax-false)
(vl-catch-all-error-p (vl-catch-all-apply 'vla-copyfrom (list x plotCfgs)))
)
)
)
(princ)
)
- Tải lisp
- 447925_pagesetups.lsp
Cách dùng
- Tải tệp 447925_pagesetups.lsp về máy.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh PAGESETUPS để chạy lisp.
Mã nguồn 447925_pagesetups.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/14210-h%E1%BB%8Fi-v%E1%BB%81-lisp-thu%E1%BA%ADt-to%C3%A1n-%C3%BD-t%C6%B0%E1%BB%9Fng-coding/?page=134
;;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/using-and-characters-in-vla-put-canonicalmedianame/td-p/4842089
(defun c:pagesetups()
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq plotCfgs (vla-get-ActiveLayout doc))
(vla-RefreshPlotDeviceInfo plotCfg)
;; Set the plot device
(vla-put-ConfigName plotCfg "DWG To PDG.pc3")
;; Set the paper size
(vla-put-CanonicalMediaName plotCfg "ANSI B \(11.00 x 17.00 Inches\)")
(vla-put-PaperUnits plotCfg acMillimeters)
(setq PLOT_BL (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 1)) '(-53.540381 -6.990000))
PLOT_TR (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 1)) '(814.00000000 537.00000000))
)
(vla-SetWindowToPlot plotCfg PLOT_BL PLOT_TR)
(vla-put-PlotType plotCfg acWindow)
(vla-put-UseStandardScale plotCfg :vlax-true)
(vla-put-StandardScale plotCfg ac1_2)
(vla-put-CenterPlot plotCfg :vlax-false)
;; Hide paperspace objects
(vla-put-PlotHidden plotCfg :vlax-false)
;; Set the plot offset
(setq origin (vlax-make-safearray vlax-vbDouble '(0 . 1)))
(vlax-safearray-fill origin (list 0.0 0.0))
(vla-put-PlotOrigin plotCfg origin)
(vla-put-PlotRotation plotCfg ac90degrees)
(vla-put-PlotViewportBorders plotCfg :vlax-false)
(vla-put-PlotViewportsFirst plotCfg :vlax-false)
(vla-put-PlotWithLineweights plotCfg :vlax-true)
(vla-put-ScaleLineweights plotCfg :vlax-false)
(vla-put-PlotWithPlotStyles plotCfg :vlax-true)
(vla-put-ShowPlotStyles plotCfg :vlax-true)
(vla-put-StyleSheet plotCfg "MTO_monochrome_Half_Size.ctb")
(vla-RefreshPlotDeviceInfo plotCfg)
;http://forums.augi.com/showthread.php?44555-Apply-page-setup-to-multiple-layouts
(vlax-map-collection
(vla-get-layouts doc)
'(lambda (x)
(if (eq (vla-get-modeltype x) :vlax-false)
(vl-catch-all-error-p (vl-catch-all-apply 'vla-copyfrom (list x plotCfgs)))
)
)
)
(princ)
)Thảo luận gốc
Lisp được chia sẻ trong chủ đề Hỏi về Lisp (thuật toán, ý tưởng, coding,...). Xem đúng bài viết #447925 để đọc hướng dẫn và trao đổi thêm.