Jump to content

Lisp lệnh BEAM trong chủ đề “VẼ DẦM (BV xây dựng)”

Chào mọi người!

Tình hình là em có vấn đề về autolisp nhờ mọi người giúp đỡ!Trong lúc tìm hiểu cách viết lisp thì có thằng bạn nó đang làm đồ án, muốn viết cho nó vẽ đỡ vất vả mà chưa đủ level, mong mọi người viết tiếp giúp em!

(defun C:BEAM()	  
; Chon va set cac diem thuoc dam
	(setq p1 (getpoint "\nChon diem dau tren ben trai dam: ")
		x1 (car p1)
		y1 (cadr p1))
	(setq p4 (getpoint p1 "\nChon diem dau tren ben phai dam: ")
		x4 (car p4))
	(setq p4 (list x4 y1))
	(setq x0T (+ x1 (* (- x4 x1) 0.5)))
	(setq p0T (list x0T y1))	
	(setq p0 (getpoint p0T "\nChon diem dat dim tren: "))  
	(setq L4 (* (- x4 x1) 0.25))
	(if (> L4 (float(* (fix (/ L4 100)) 100))) (setq L4 (* (+ (fix (/ L4 100)) 1) 100)))
	(setq x2 (+ x1 L4))
	(setq p2 (list x2 y1))
	(setq x3 (- x4 L4))
	(setq p3 (list x3 y1))
	(setq p5 (getpoint "\nChon diem dau duoi ben trai dam: ")
		x5 (car p5)
		y5 (cadr p5))
	(setq p8 (getpoint p5 "\nChon diem dau duoi ben phai dam: ")
		x8 (car p8))
	(setq p8 (list x8 y5))
	(setq x0D (+ x5 (* (- x8 x5) 0.5)))
	(setq y0D y5)
	(setq p0D (list x0D y0D))	
	(setq p0DD (getpoint p0D "\nChon diem dat dim tren: "))  
	(setq L6 (/ (- x8 x5) 6))
	(setq L6 (* (fix (/ L6 100)) 100))
	(setq x6 (+ x5 L6))
	(setq p6 (list x6 y5))
	(setq x7 (- x8 L6))
	(setq p7 (list x7 y5))
; Nhap chieu day lop be tong bao ve	
	(if (not abv0) (setq abv0 40))
	(setq abv (getreal (strcat "\nChieu day BTBV <" (rtos abv0) ">:")))
	(if abv (setq abv abv0))	
	(setq y9 (- y1 abv))
	(setq p9 (list x1 y9))	
	(setq p10 (list x2 y9))
	(setq p11 (list x3 y9))
	(setq p12 (list x4 y9))
	(setq y13 (+ y5 abv))
	(setq p13 (list x5 y13))
	(setq p14 (list x6 y13))
	(setq p15 (list x7 y13))
	(setq p16 (list x8 y13))
	(setq p100 (list (- x2 60) (- y9 30)))
	(setq p110 (list (+ x3 60) (- y9 30)))
	(setq p140 (list (+ x6 60) (+ y13 30)))
	(setq p150 (list (- x7 60) (+ y13 30)))
; Ve cot doc	
(if (= (cdr(assoc 2 (tblsearch "layer" "Rebar"))) nil)(COMMAND "LAYER" "M" "Rebar" "C" "1" "" ""))
	(setvar "clayer" "Rebar")
	(command "line" p9 p12 "")
	(command "line" p10 p100 "")
	(command "line" p11 p110 "")
	(command "line" p13 p16 "")
	(command "line" p140 p14 "")
	(command "line" p150 p15 "")
; Ve cot dai	
	(if (= (cdr(assoc 2 (tblsearch "layer" "Stirrups"))) nil)(COMMAND "LAYER" "M" "Stirrups" "C" "4" "" ""))
	(setvar "clayer" "Stirrups")
	;Dau dam ben trai
	(setq x-ag (+ x1 50))
	(repeat (fix (/ L4 100))
		(setq pG1 (list x-ag y9))
		(setq pG2 (list x-ag y13))
		(setq x-ag (+ 100 x-ag))
		(command "LINE" pG1 pG "")
	)
	;Doan giua dam	
	(setq x-ag x2)
	(repeat (fix (/ L4 200))
		(setq pG1 (list x-ag y9))
		(setq pG2 (list x-ag y13))
		(setq x-ag (+ 200 x-ag))
		(command "LINE" pG1 pG "")
	)
	;Dau dam ben phai
	(setq x-ag (- x4 50))
	(repeat (fix (/ L4 100))
		(setq pG1 (list x-ag y9))
		(setq pG2 (list x-ag y13))
		(setq x-ag (- 100 x-ag))
		(command "LINE" pG1 pG "")
	)
; Chi cac thong tin ve thep
	;Tao layer Text2.5 dung cho ghi chu
	(if (= (cdr(assoc 2 (tblsearch "layer" "Text2.5"))) nil)(COMMAND "LAYER" "M" "Text2.5" "C" "2" "" ""))
	;Chua biet viet tiep, nho cac cao thu tiep suc!!!
;Dim cac thong so dam
	(if (= (cdr(assoc 2 (tblsearch "layer" "Dim"))) nil)(COMMAND "LAYER" "M" "Dim" "C" "7" "" ""))
	(setvar "clayer" "Dim")
	(command "dimlinear" p5 p6 p0DD)
	(command "dimlinear" p6 p7 p0DD)
	(command "dimlinear" p7 p8 p0DD)
	(command "dimlinear" p1 p2 p0)
	(setq dim_obj (entlast))
	(setq str "8a100")
	(if (= str "") (setq str "8a100"))
	(command ".Dim1" "New" (strcat "<>\\X%%C" str) dim_obj "")
	(command "dimlinear" p2 p3 p0)
	(setq dim_obj (entlast))
	(setq str "8a200")
	(if (= str "") (setq str "8a200"))
	(command ".Dim1" "New" (strcat "<>\\X%%C" str) dim_obj "")
	(command "dimlinear" p3 p4 p0)
	(setq dim_obj (entlast))
	(setq str "8a100")
	(if (= str "") (setq str "8a100"))
	(command ".Dim1" "New" (strcat "<>\\X%%C" str) dim_obj "")
)
Trong lúc viết thì em nhận ra một số lỗi mà em chưa hiểu tại sao, mong các cao thủ hỗ trợ:
1. Phần vẽ cốt dọc: tại sao em set tọa độ điểm P9(x1-50, y1-abv) và P12(x1-50, y5+abv) mà tại sao khi vẽ line từ P9 đến P12, nó cứ vẽ từ P1 đến P4 và tương tự cho các điểm còn lại.
2. Phần vẽ cốt đai: em muốn sử dụng lệnh repeat để vẽ trong từng đoạn xong dường như nó không hiểu!
3. Và cuối dùng em muốn ghi chú như hình vẽ (mang tính minh họa).

132006_00_1.png132006_141216.png

Cho em gửi kèm file .dwg: https://www.cadviet.com/upfiles/4/132006_141216.dwg

Cảm ơn!

2. Phần vẽ cốt đai: em muốn sử dụng lệnh repeat để vẽ trong từng đoạn xong dường như nó không hiểu!
3. Và cuối dùng em muốn ghi chú như hình vẽ.

Cách dùng

  1. Tải tệp 326818_beam.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 BEAM để chạy lisp.

Mã nguồn 326818_beam.lsp

;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/116105-v%E1%BA%BD-d%E1%BA%A7m-bv-x%C3%A2y-d%E1%BB%B1ng/
(defun C:BEAM()	  
; Chon va set cac diem thuoc dam
	(setq p1 (getpoint "\nChon diem dau tren ben trai dam: ")
		x1 (car p1)
		y1 (cadr p1))
	(setq p4 (getpoint p1 "\nChon diem dau tren ben phai dam: ")
		x4 (car p4))
	(setq p4 (list x4 y1))
	(setq x0T (+ x1 (* (- x4 x1) 0.5)))
	(setq p0T (list x0T y1))	
	(setq p0 (getpoint p0T "\nChon diem dat dim tren: "))  
	(setq L4 (* (- x4 x1) 0.25))
	(if (> L4 (float(* (fix (/ L4 100)) 100))) (setq L4 (* (+ (fix (/ L4 100)) 1) 100)))
	(setq x2 (+ x1 L4))
	(setq p2 (list x2 y1))
	(setq x3 (- x4 L4))
	(setq p3 (list x3 y1))
	(setq p5 (getpoint "\nChon diem dau duoi ben trai dam: ")
		x5 (car p5)
		y5 (cadr p5))
	(setq p8 (getpoint p5 "\nChon diem dau duoi ben phai dam: ")
		x8 (car p8))
	(setq p8 (list x8 y5))
	(setq x0D (+ x5 (* (- x8 x5) 0.5)))
	(setq y0D y5)
	(setq p0D (list x0D y0D))	
	(setq p0DD (getpoint p0D "\nChon diem dat dim tren: "))  
	(setq L6 (/ (- x8 x5) 6))
	(setq L6 (* (fix (/ L6 100)) 100))
	(setq x6 (+ x5 L6))
	(setq p6 (list x6 y5))
	(setq x7 (- x8 L6))
	(setq p7 (list x7 y5))
; Nhap chieu day lop be tong bao ve	
	(if (not abv0) (setq abv0 40))
	(setq abv (getreal (strcat "\nChieu day BTBV <" (rtos abv0) ">:")))
	(if abv (setq abv abv0))	
	(setq y9 (- y1 abv))
	(setq p9 (list x1 y9))	
	(setq p10 (list x2 y9))
	(setq p11 (list x3 y9))
	(setq p12 (list x4 y9))
	(setq y13 (+ y5 abv))
	(setq p13 (list x5 y13))
	(setq p14 (list x6 y13))
	(setq p15 (list x7 y13))
	(setq p16 (list x8 y13))
	(setq p100 (list (- x2 60) (- y9 30)))
	(setq p110 (list (+ x3 60) (- y9 30)))
	(setq p140 (list (+ x6 60) (+ y13 30)))
	(setq p150 (list (- x7 60) (+ y13 30)))
; Ve cot doc	
(if (= (cdr(assoc 2 (tblsearch "layer" "Rebar"))) nil)(COMMAND "LAYER" "M" "Rebar" "C" "1" "" ""))
	(setvar "clayer" "Rebar")
	(command "line" p9 p12 "")
	(command "line" p10 p100 "")
	(command "line" p11 p110 "")
	(command "line" p13 p16 "")
	(command "line" p140 p14 "")
	(command "line" p150 p15 "")
; Ve cot dai	
	(if (= (cdr(assoc 2 (tblsearch "layer" "Stirrups"))) nil)(COMMAND "LAYER" "M" "Stirrups" "C" "4" "" ""))
	(setvar "clayer" "Stirrups")
	;Dau dam ben trai
	(setq x-ag (+ x1 50))
	(repeat (fix (/ L4 100))
		(setq pG1 (list x-ag y9))
		(setq pG2 (list x-ag y13))
		(setq x-ag (+ 100 x-ag))
		(command "LINE" pG1 pG "")
	)
	;Doan giua dam	
	(setq x-ag x2)
	(repeat (fix (/ L4 200))
		(setq pG1 (list x-ag y9))
		(setq pG2 (list x-ag y13))
		(setq x-ag (+ 200 x-ag))
		(command "LINE" pG1 pG "")
	)
	;Dau dam ben phai
	(setq x-ag (- x4 50))
	(repeat (fix (/ L4 100))
		(setq pG1 (list x-ag y9))
		(setq pG2 (list x-ag y13))
		(setq x-ag (- 100 x-ag))
		(command "LINE" pG1 pG "")
	)
; Chi cac thong tin ve thep
	;Tao layer Text2.5 dung cho ghi chu
	(if (= (cdr(assoc 2 (tblsearch "layer" "Text2.5"))) nil)(COMMAND "LAYER" "M" "Text2.5" "C" "2" "" ""))
	;Chua biet viet tiep, nho cac cao thu tiep suc!!!
;Dim cac thong so dam
	(if (= (cdr(assoc 2 (tblsearch "layer" "Dim"))) nil)(COMMAND "LAYER" "M" "Dim" "C" "7" "" ""))
	(setvar "clayer" "Dim")
	(command "dimlinear" p5 p6 p0DD)
	(command "dimlinear" p6 p7 p0DD)
	(command "dimlinear" p7 p8 p0DD)
	(command "dimlinear" p1 p2 p0)
	(setq dim_obj (entlast))
	(setq str "8a100")
	(if (= str "") (setq str "8a100"))
	(command ".Dim1" "New" (strcat "<>\\X%%C" str) dim_obj "")
	(command "dimlinear" p2 p3 p0)
	(setq dim_obj (entlast))
	(setq str "8a200")
	(if (= str "") (setq str "8a200"))
	(command ".Dim1" "New" (strcat "<>\\X%%C" str) dim_obj "")
	(command "dimlinear" p3 p4 p0)
	(setq dim_obj (entlast))
	(setq str "8a100")
	(if (= str "") (setq str "8a100"))
	(command ".Dim1" "New" (strcat "<>\\X%%C" str) dim_obj "")
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề VẼ DẦM (BV xây dựng). Xem đúng bài viết #326818 để đọc hướng dẫn và trao đổi thêm.

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