AutoCAD LISP 建立配置與設置配置相關設定

快速介紹:
1.刪除已有"Test"的配置
2.增加一個叫"Test"的配置
3.設置出圖型式表(圖筆指定)
4.設置繪圖機
5.設置紙張大小
6.指定為當前配置
7.返回當前的出圖型式表(圖筆指定)和繪圖機

程式碼:
(defun c:addTheLayout  ( / acadApp acadDoc layouts layoutObj currPStyle currConfig)
    (vl-load-com)
    (setq acadApp (vlax-get-Acad-object))
    (setq acadDoc (vla-get-ActiveDocument acadApp))
    (setq layouts (vla-get-Layouts acadDoc))

    ;; Delete the layout named "Test" if it exists
    ;; 刪除已有"Test"的配置
    (vlax-for objLayout  layouts
 (if (= (vla-get-name objLayout) "Test")
     (progn
  (princ
      (strcat "\n 刪除已有配置 "
       (vla-get-name objLayout)
       " ..."
       )
      )
  (vla-delete objLayout) ;_刪除配置
  (vlax-release-object objLayout) ;_ 釋放配置物件
  ) ;_progn
     ) ;_if
 ) ;_vlax-for
    
    ;; 增加一個叫"Test"的配置
    (setq layoutObj (vla-add layouts "Test"))

    ;; Assign Grayscale.CTB to the Layout
    ;; 給配置設置出圖型式表(圖筆指定)
    (vla-put-StyleSheet layoutObj "Grayscale.ctb")

    ;; Assign DWF configuration to the Layout
    ;; 給配置設置繪圖機
    (vla-put-configname layoutObj "DWG TO PDF.pc3")

    ;; Assign Paper Size B to the Layout
    ;; 給配置設置紙張大小
    (vla-put-canonicalmedianame
 layoutObj
 "ANSI_expand_B_(11.00_x_17.00_Inches)"
 )

    ;; Make the new Layout Active
    ;; 指定為當前配置
    (vla-put-activelayout acadDoc layoutObj)

    ;; Example getting StyleSheet and Configname
    ;; 返回當前的出圖型式表(圖筆指定)和繪圖機
    (setq currPStyle (vla-Get-StyleSheet layoutObj))
    (setq currConfig (vla-Get-configname layoutObj))
    (princ)
    );_結束

留言

這個網誌中的熱門文章

AutoCAD 填充線(剖面線)樣式簡易製作產生器

AutoCAD 如何自訂線型教學

AutoCAD 動態圖塊-如何在所有可見性顯示或隱藏