Jump to content

Lisp stretch nhóm đối tượng 2 phía vào giữa và xung quanh vào tâm


132006_question_20141013_04.jpg

 

(defun C:DTB()
	(if (not rea) (setq rea 100))
	(setq rea1 (getreal (strcat "\nInput distance of bulong <" (itoa rea) ">:"))) 
	(if rea1 (setq rea rea1))
	(while
		(if (setq net (nentsel "\nSelect  text of dimension!"))
			(setq
				etname (car net)
				etlist (entget etname)
				ettype (cdr (assoc 0 etlist))
				newtext (cdr (assoc 1 etlist))
			)
		)
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext (-(strlen newtext) 3) 1) ",")(setq newtext (strcat (substr newtext 1 (-(strlen newtext) 4)) (substr newtext (-(strlen newtext) 2) (-(strlen newtext) 2)))))
		(setq bl (rtos(/ (atof newtext) rea)))
		(setq reat (rtos rea))
		(princ "\nSelect dimension to add text override!")
		(setq dim_obj (ssget(list(cons 0 "DIMENSION"))))
		(command ".Dim1" "New" (strcat "<>(" bl "x" reat ")") dim_obj "")
	)
	(princ)
)

 

(defun C:DTB()
(if (not rea) (setq rea 100))
(setq rea1 (getreal (strcat "\nInput distance of bulong <" (itoa rea) ">:"))) 
(if rea1 (setq rea rea1))
(while
(if (setq net (nentsel "\nSelect  text of dimension!"))
(setq
etname (car net)
etlist (entget etname)
ettype (cdr (assoc 0 etlist))
newtext (cdr (assoc 1 etlist))
)
)
(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
(if (= (substr newtext (-(strlen newtext) 3) 1) ",")(setq newtext (strcat (substr newtext 1 (-(strlen newtext) 4)) (substr newtext (-(strlen newtext) 2) (-(strlen newtext) 2)))))
(setq bl (rtos(/ (atof newtext) rea)))
(setq reat (rtos rea))
(princ "\nSelect dimension to add text override!")
(setq dim_obj (ssget(list(cons 0 "DIMENSION"))))
(command ".Dim1" "New" (strcat "<>(" bl "x" reat ")") dim_obj "")
)
(princ)
)

 

1. Cho em hỏi: lỗi này là thế nào?

Command: DTB
; error: bad argument type: fixnump: 21.0

và nhờ các anh chị sửa giúp!

2. tại sao có lỗi ra nhiều số 0 như thế! bây giờ muốn bỏ các số 0 không có nghĩa đi, ta sẽ sửa lại đoạn code thế nào ah!

 

Command: DTB
; error: bad argument type: fixnump: 21.0

Cách dùng

  1. Tải tệp 316245_dtb.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 DTB để chạy lisp.

Mã nguồn 316245_dtb.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/66575-y%C3%AAu-c%E1%BA%A7u-lisp-stretch-nh%C3%B3m-%C4%91%E1%BB%91i-t%C6%B0%E1%BB%A3ng-2-ph%C3%ADa-v%C3%A0o-gi%E1%BB%AFa-v%C3%A0-xung-quanh-v%C3%A0o-t%C3%A2m/
(defun C:DTB()
	(if (not rea) (setq rea 100))
	(setq rea1 (getreal (strcat "\nInput distance of bulong <" (itoa rea) ">:"))) 
	(if rea1 (setq rea rea1))
	(while
		(if (setq net (nentsel "\nSelect  text of dimension!"))
			(setq
				etname (car net)
				etlist (entget etname)
				ettype (cdr (assoc 0 etlist))
				newtext (cdr (assoc 1 etlist))
			)
		)
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext 1 4) "\\A1;")(setq newtext (vl-string-subst "" "\\A1;" newtext)))
		(if (= (substr newtext (-(strlen newtext) 3) 1) ",")(setq newtext (strcat (substr newtext 1 (-(strlen newtext) 4)) (substr newtext (-(strlen newtext) 2) (-(strlen newtext) 2)))))
		(setq bl (rtos(/ (atof newtext) rea)))
		(setq reat (rtos rea))
		(princ "\nSelect dimension to add text override!")
		(setq dim_obj (ssget(list(cons 0 "DIMENSION"))))
		(command ".Dim1" "New" (strcat "<>(" bl "x" reat ")") dim_obj "")
	)
	(princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề [yêu cầu] Lisp stretch nhóm đối tượng 2 phía vào giữa và xung quanh vào tâm. Xem đúng bài viết #316245 để đọc hướng dẫn và trao đổi thêm.

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