Jump to content

Lisp lệnh TEST trong chủ đề “Nhờ Viết Lisp Chuyển Layer Cho Leader Và Text”

không được bác ah, cad nó báo Command: test
; error: ActiveX Server returned the error: unknown name: Name
Command:

Thay "*TEXT" trong code bằng "AcDbText" là ngon. ^_^

(defun c:test ()
  (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  (vlax-for blks (vla-get-blocks acdoc)
    (vlax-for obj blks
      (if (wcmatch (vla-get-ObjectName obj) "AcDbLeader")
	(progn
	  (if (wcmatch (vla-get-ArrowheadBlock obj) "")
	    (vla-put-Layer obj "14.Dimhh")
	    )
	  (if (wcmatch (vla-get-ArrowheadBlock obj) "DotBlank")
	    (vla-put-Layer obj "15.Dimct")
	    )
	  )
	)
      (if (and (wcmatch (vla-get-ObjectName obj) "AcDbText")
	       (or (wcmatch (vla-get-StyleName obj) "Text 1.5")
		   (wcmatch (vla-get-StyleName obj) "Text 1.8")
		   )
	       )
	(vla-put-Layer obj "06.Text1.8")
	)
      (if (and (wcmatch (vla-get-ObjectName obj) "AcDbText")
	       (or (wcmatch (vla-get-StyleName obj) "Text 2.5")
		   (wcmatch (vla-get-StyleName obj) "Text 3.0")
		   )
	       )
	(vla-put-Layer obj "07.Text3.0")
	)
      );vlax-for obj
    );vlax-for blks
  (princ)
  )

Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.

Cách dùng

  1. Chép mã nguồn, lưu thành tệp 408461_test.lsp.
  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 TEST để chạy lisp.

Mã nguồn 408461_test.lsp (trích từ bài viết gốc)

(defun c:test ()
  (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  (vlax-for blks (vla-get-blocks acdoc)
    (vlax-for obj blks
      (if (wcmatch (vla-get-ObjectName obj) "AcDbLeader")
	(progn
	  (if (wcmatch (vla-get-ArrowheadBlock obj) "")
	    (vla-put-Layer obj "14.Dimhh")
	    )
	  (if (wcmatch (vla-get-ArrowheadBlock obj) "DotBlank")
	    (vla-put-Layer obj "15.Dimct")
	    )
	  )
	)
      (if (and (wcmatch (vla-get-ObjectName obj) "AcDbText")
	       (or (wcmatch (vla-get-StyleName obj) "Text 1.5")
		   (wcmatch (vla-get-StyleName obj) "Text 1.8")
		   )
	       )
	(vla-put-Layer obj "06.Text1.8")
	)
      (if (and (wcmatch (vla-get-ObjectName obj) "AcDbText")
	       (or (wcmatch (vla-get-StyleName obj) "Text 2.5")
		   (wcmatch (vla-get-StyleName obj) "Text 3.0")
		   )
	       )
	(vla-put-Layer obj "07.Text3.0")
	)
      );vlax-for obj
    );vlax-for blks
  (princ)
  )

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ Viết Lisp Chuyển Layer Cho Leader Và Text. Xem đúng bài viết #408461 để đọc hướng dẫn và trao đổi thêm.

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