Jump to content

Lisp lệnh NB trong chủ đề “convert anonymous block to normal block”

....

P/s : đề nghị bạn cho đoạn mã vào thẻ Code

Vấn đề của bạn có thể xử lý bằng lisp này cũng được :

https://www.cadviet.com/forum/index.php?showtopic=53341&st=0&p=166931&&do=findComment&comment=166931

Nó sẽ copy block Anon bạn chọn thành 1 block mới, rồi bạn chèn vào đúng điểm chèn cũ của block đó ( trong ví dụ cảu bạn thì toàn '( 0 0 0).

Từ lisp này cũng có thể biến hóa thành lisp convert block anon -> block thường :

;| Change Anonymous Block to normal with new Name
@ Ketxu 27 - 9 - 2011
|;
(defun c:nb( / blkObj blkName blkNew_Name fn pt) 
(vl-load-com)
(defun ST:SS->List-Vla (ss / n e l)
 (setq n (sslength ss))
 (while (setq e (ssname ss (setq n (1- n))))
(setq l (cons (vlax-ename->vla-object e) l))
 )
)

(defun change_block(old new)
(foreach blkObj (setq ss (ST:SS->List-Vla (ssget "X" (list (cons 0 "INSERT")(cons 2 old)))))
(vla-put-name blkObj new);;change the name
(vla-update blkObj)
)
)
(grtext -1 "Free Lisp From Cadviet @Ketxu")
(setvar "cmdecho" 0)
(setq 
blkObj (vlax-ename->vla-object (car(entsel "\nBlock Source :")))
blkName (vlax-get-property blkObj
   (if (vlax-property-available-p blkObj 'EffectiveName) 'EffectiveName 'Name)
 )  
blkNew_Name (getstring "\n New Name :")
 fn (strcat (getenv "TEMP") "\\" blkNew_Name ".dwg")
)
(command ".-wblock" fn "_Y" blkName "")  
(command "._insert" (strcat blkNew_Name "=" fn) nil )
(if (wcmatch "`*" (substr blkName 1 1))(setq blkName (strcat "`*" (substr blkName 2))))
(change_block blkName blkNew_Name)
(vl-file-delete  fn)
)

Cách dùng

  1. Tải tệp 170557_nb.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 NB để chạy lisp.

Mã nguồn 170557_nb.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/416-convert-anonymous-block-to-normal-block/?page=2
;| Change Anonymous Block to normal with new Name
@ Ketxu 27 - 9 - 2011
|;
(defun c:nb( / blkObj blkName blkNew_Name fn pt) 
(vl-load-com)
(defun ST:SS->List-Vla (ss / n e l)
 (setq n (sslength ss))
 (while (setq e (ssname ss (setq n (1- n))))
(setq l (cons (vlax-ename->vla-object e) l))
 )
)

(defun change_block(old new)
(foreach blkObj (setq ss (ST:SS->List-Vla (ssget "X" (list (cons 0 "INSERT")(cons 2 old)))))
(vla-put-name blkObj new);;change the name
(vla-update blkObj)
)
)
(grtext -1 "Free Lisp From Cadviet @Ketxu")
(setvar "cmdecho" 0)
(setq 
blkObj (vlax-ename->vla-object (car(entsel "\nBlock Source :")))
blkName (vlax-get-property blkObj
   (if (vlax-property-available-p blkObj 'EffectiveName) 'EffectiveName 'Name)
 )  
blkNew_Name (getstring "\n New Name :")
 fn (strcat (getenv "TEMP") "\\" blkNew_Name ".dwg")
)
(command ".-wblock" fn "_Y" blkName "")  
(command "._insert" (strcat blkNew_Name "=" fn) nil )
(if (wcmatch "`*" (substr blkName 1 1))(setq blkName (strcat "`*" (substr blkName 2))))
(change_block blkName blkNew_Name)
(vl-file-delete  fn)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề convert anonymous block to normal block. Xem đúng bài viết #170557 để đọc hướng dẫn và trao đổi thêm.

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