Jump to content

Lisp lệnh SC2 trong chủ đề “scale theo trục x và y”

@ndtnv : Lưu cũng chẳng có ích gì vì sau khi explode, đối tượng sẽ mang tên (code -1) khác hoàn toàn, thậm chí sau khi scale chưa nổ nó cũng mang tên khác, chỉ có thể edit ngay khi nó còn trong block thôi.

 

@anpha3 : botay.com

Sau khi explode, thứ tự đối tượng sẽ không đổi.
Tôi sửa tạm như sau:
( Chưa test nhiều để chắc chắn thứ tự trong (ssget "p") có thay đổi hay không.
An toàn hơn thì nên sort ss theo dxf 5 )

(defun C:sc2(/ ss p tlx tly btp tenbl data obj)
  (defun BlockText (v tlx tly  / blks name def i)
    (setq blks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
      name (vla-get-effectivename (vlax-ename->vla-object v)) i 0)
 
    (if (not (vl-catch-all-error-p (setq def (vl-catch-all-apply 'vla-item (list blks name)))))
      (vlax-for obj def
    (if (= "AcDbText" (vla-get-objectname obj))
        (setq data (cons  (list (vla-get-Height obj)(vla-get-ScaleFactor obj)(vla-get-ObliqueAngle obj) i )data)))
        (setq i (1+ i))
  )))
  ;;;
  (prompt "\nChon doi tuong de scale :")
  (setq ss  (ssget)
    p   (getpoint "\nDiem goc:")
      tlx (getreal "\nTy le scale phuong X:")
    tly (getreal "\nTy le scale phuong Y:"))
  (if (not btp) (setq btp -1))
  (while (tblsearch "block" (setq tenbl (strcat "btmp" (itoa (setq btp (1+ btp)))))))
    (command ".undo" "be")
  (command "-block" tenbl p ss "")
  (command "-insert" tenbl p tlx tly 0)
  (BlockText (entlast) tlx tly)
  (command "explode" (entlast))
    (setq ss (ssget "p"))
    (foreach e data
        (setq obj(vlax-ename->vla-object (ssname ss (last e))))
        (vla-put-Height obj (car e))
        (vla-put-ScaleFactor obj (cadr e))
        (vla-put-ObliqueAngle obj (caddr e))
    )
    (command ".undo" "e")
  (princ)
)

Cách dùng

  1. Tải tệp 290409_sc2.lsp về máy.
  2. 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ẽ.
  3. Gõ lệnh SC2 để chạy lisp.

Mã nguồn 290409_sc2.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/8204-scale-theo-tr%E1%BB%A5c-x-v%C3%A0-y/?page=2
(defun C:sc2(/ ss p tlx tly btp tenbl data obj)
  (defun BlockText (v tlx tly  / blks name def i)
    (setq blks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
      name (vla-get-effectivename (vlax-ename->vla-object v)) i 0)
 
    (if (not (vl-catch-all-error-p (setq def (vl-catch-all-apply 'vla-item (list blks name)))))
      (vlax-for obj def
    (if (= "AcDbText" (vla-get-objectname obj))
        (setq data (cons  (list (vla-get-Height obj)(vla-get-ScaleFactor obj)(vla-get-ObliqueAngle obj) i )data)))
        (setq i (1+ i))
  )))
  ;;;
  (prompt "\nChon doi tuong de scale :")
  (setq ss  (ssget)
    p   (getpoint "\nDiem goc:")
      tlx (getreal "\nTy le scale phuong X:")
    tly (getreal "\nTy le scale phuong Y:"))
  (if (not btp) (setq btp -1))
  (while (tblsearch "block" (setq tenbl (strcat "btmp" (itoa (setq btp (1+ btp)))))))
    (command ".undo" "be")
  (command "-block" tenbl p ss "")
  (command "-insert" tenbl p tlx tly 0)
  (BlockText (entlast) tlx tly)
  (command "explode" (entlast))
    (setq ss (ssget "p"))
    (foreach e data
        (setq obj(vlax-ename->vla-object (ssname ss (last e))))
        (vla-put-Height obj (car e))
        (vla-put-ScaleFactor obj (cadr e))
        (vla-put-ObliqueAngle obj (caddr e))
    )
    (command ".undo" "e")
  (princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề scale theo trục x và y. Xem đúng bài viết #290409 để đọc hướng dẫn và trao đổi thêm.

Về Thư viện AutoLisp (trang 156)