Lisp lệnh MGCO CCOT trong chủ đề “Xin lisp ghi được cao độ cụ thể các điểm trên mặt cắt dọc”
Code đây sẽ làm được điều bạn cần :
Cách thức hoạt động của đoạn code trên :
Bạn giải nén file tue.zip (Có chứa file ghicot.lsp và file cot.dwg) vào trong ổ đĩa C:\tue mà mình sẽ upload dưới đây
Sau đó vào CAD ->gõ option ->File -> Bạn chọn Support file Search path -> Add vào đường dẫn C:\tue ->OK.
Nếu bạn không làm những bước trên thì chương trình sẽ không chạy.
Bạn appload file ghicot.lsp lên và bắt đầu sử dụng :
Đơn vị ghi cot là đơn vị mm
Ở đây có thêm lệnh Ccot là lệnh copy cao độ từ cao độ có sẵn. Bạn ngâm cứu nhé. hay lắm
Mình sẽ làm ví dụ trong file của bạn
Command: mgco
Nhap: "T" neu xac dinh cot theo moc tuong doi.
-> Diem goc xac dinh cot /T/: _from Base point: (Pick vào điểm gốc xác định tọa độ tương đối) : @0,-368550 (đây là tọa độ điểm gốc 0,0 được xác định theo chế độ bắt điểm from từ điểm gốc xác định tọa độ tương đối)
->> Ghi cot vao diem goc ?/Y/: n
Cot cao do tinh bang "Milimet" !
->> Cot cao do : Enter
->> Diem ghi cot tiep theo: Pick vào điểm ghi cot
Cot cao do tinh bang "Milimet" !
->> Cot cao do :
->> Diem ghi cot tiep theo: Pick vào điểm ghi cot
Cot cao do tinh bang "Milimet" !
->> Cot cao do :
->> Diem ghi cot tiep theo: Pick vào điểm ghi cot
Cot cao do tinh bang "Milimet" !
->> Cot cao do :
->> Diem ghi cot tiep theo: Pick vào điểm ghi cot
Cot cao do tinh bang "Milimet" !
->> Cot cao do :
----Còn nữa
File Tue.zip đây bạn : TueZip
File ví dụ mình sửa đây bạn : Coc_12Zip
Nhớ thanks đấy nhé.
À quên : Ứng dụng file líp ghi cot bạn có thể ghi tọa độ của sợi cáp trong phần bê tông ứng lực trước bằng cách thay cái file cot.dwg có chứa đối tượng block thành một file cot.dwg có chứa đối tượng là một point(đối tượng điểm)
Chúc vui.
- Tải lisp
- 41411_mgco_ccot.lsp
Cách dùng
- Tải tệp 41411_mgco_ccot.lsp về máy.
- 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ẽ.
- Gõ lệnh MGCO CCOT để chạy lisp.
Mã nguồn 41411_mgco_ccot.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/7770-xin-lisp-ghi-%C4%91%C6%B0%E1%BB%A3c-cao-%C4%91%E1%BB%99-c%E1%BB%A5-th%E1%BB%83-c%C3%A1c-%C4%91i%E1%BB%83m-tr%C3%AAn-m%E1%BA%B7t-c%E1%BA%AFt-d%E1%BB%8Dc/
;--------------------------------------------------------
(defun gc_err (s)
(if (/= s "Function cancelled")
(princ (strcat "\nError: " s))
)
(setvar "Osmode" old_osmode)
(setq *error* old_err)
(princ)
)
;;; Main Function:
(defun C:Mgco (/ block_in cot_base dim_scl dim_txt old_base_ data_base cot_in
text_h text_clr text_point next_p ghi_base old_ortho cao_do
old_ortho c_base n_base c_unit moc_st lim_out)
(setq old_osmode(getvar "Osmode")
old_ortho(getvar "Orthomode"))
(setvar "Osmode" (+ 1 8 512)); End Node Near
(setvar "Orthomode" 0)
(setvar "Cmdecho" 0)
(setq old_error *error* *error* gc_err)
(prompt "\nNhap: \"T\" neu xac dinh cot theo moc tuong doi.")
(command "_.Ucs" "W")
(initget 9 "T");(+ 1 8)
(setq c_base(getpoint "\n-> Diem goc xac dinh cot /T/: ")
block_in "C:\\Tue\\cot.dwg"
next_p 0
c_unit 0
dim_txt(getvar "Dimtxt")
dim_scl(getvar "Dimscale"))
(if(= c_base "T")
(progn
(initget 8)
(setq c_base NIL c_unit NIL
c_base(getpoint "\n-> Diem goc xac dinh cot tuong doi: "))
(initget 8)
(if c_base
(setq c_unit(getdist "\n->> Nhap cao do moc tuong doi : "))
)
(if(= c_unit NIL)(setq c_unit 0.000))
)
(setq c_unit 0.0)
)
(if(= dim_scl 0.0)
(setq dim_scl dim_txt dim_txt NIL)
(setq dim_scl (* dim_scl dim_txt) dim_txt NIL))
(setq dim_scl (* dim_scl 2.0))
(if(not(findfile block_in))
(progn(alert (strcat "\n Thieu file: \""block_in"\" ! "))(setq next_p NIL c_base NIL)))
(if (and c_base c_unit)
(while next_p
(if(= next_p 0);ghi cot moc
(progn
(if(/= c_unit 0)(setq moc_st c_unit c_unit 0)(setq moc_st 0.0))
(initget "Y N")
(setq ghi_base(getkword "\n->> Ghi cot vao diem goc ?/Y/: "))
(if(or(= ghi_base "Y")(/= ghi_base NIL))
(pro_cot c_base moc_st);Ghi cot vao vi tri moc
)
(setq ghi_base NIL)
)
)
(setvar "Osmode" 1);(+ 1 8 128)) End Node Per
(initget 8)
(if (setq n_point(getpoint "\n->> Diem ghi cot tiep theo: " c_base))
(progn
;Pack for Out-size Limits:
(if( (progn
(if( (cond
(( (setq lim_out -1.0) )
((> (cadr c_base)(cadr n_point))
(setq lim_out -1.0) )
((= (cadr c_base)(cadr n_point))
(setq lim_out 1.0) )
)
)
(if(>= (cadr n_point) 0)
(setq lim_out 1) )
)
);if c_base (if(> (cadr c_base) 0)
(setq lim_out 1) )
;End Pack
(setq cao_do(* lim_out (- (abs(cadr n_point)) (abs(cadr c_base))) )
next_p (+ next_p 1))
(pro_cot n_point (+ cao_do c_unit))
)
(setq next_p NIL cao_do NIL c_base NIL n_point NIL)
);if
);while
);if c_base
(setq cot_in NIL text_point NIL text_h NIL text_clr NIL dim_scl NIL cao_do NIL
moc_st NIL c_unit NIL)
(setvar "Osmode" old_osmode)
(setvar "Orthomode" old_ortho)
(setq *error* old_err)
(princ)
)
;;;
(defun pro_cot (cot_base old_base)
(if (and cot_base (findfile block_in))
(progn
(if(not old_base)
(setq old_base 0.000 old_base_ "0.000")
(progn
(if( (progn
(if(>= (abs old_base) 1000)
(setq old_base_(strcat "-" (rtos (/ old_base -1000.000) 2 3)))
(progn
(if(/= (substr (rtos (/ old_base 1000.000) 2 3) 1 3) "-0.")
(setq old_base_(strcat "-0" (rtos (/ old_base -1000.000) 2 3)))
(setq old_base_(strcat "-" (rtos (/ old_base -1000.000) 2 3)))
)
)
)
)
(progn
(if(>= old_base 1000)
(setq old_base_(strcat "+" (rtos (/ old_base 1000.000) 2 3)))
(progn
(if(/= (substr (rtos (/ old_base 1000.000) 2 3) 1 2) "0.")
(setq old_base_(strcat "+0" (rtos (/ old_base 1000.000) 2 3)))
(setq old_base_(strcat "+" (rtos (/ old_base 1000.000) 2 3)))
)
)
)
)
)
(if(= old_base 0)(setq old_base 0.000 old_base_ "0.000"))
);progn
);if
(prompt "\nCot cao do tinh bang \"Milimet\" !")
(initget 8)
(setq data_base(getint(strcat "\n->> Cot cao do :")))
(if(not data_base)
(setq data_base old_base)
(setq old_base data_base)
);if
(if data_base
(progn
(if(> data_base 0)
(if(>= data_base 1000)
(setq cot_in(strcat "+" (rtos (/ data_base 1000.000) 2 3)))
(progn
(if(/= (substr (rtos (/ data_base 1000.000) 2 3) 1 2) "0.")
(setq cot_in(strcat "+0" (rtos (/ data_base 1000.000) 2 3)))
(setq cot_in(strcat "+" (rtos (/ data_base 1000.000) 2 3)))
)
)
)
(if(; (setq cot_in(strcat "-0" (rtos (/ data_base -1000.000) 2 3)))
(progn
(if(/= (substr (rtos (/ data_base 1000.000) 2 3) 1 3) "-0.")
(setq cot_in(strcat "-0" (rtos (/ data_base -1000.000) 2 3)))
(setq cot_in(strcat "-" (rtos (/ data_base -1000.000) 2 3)))
)
)
(setq cot_in(strcat "-" (rtos (/ data_base -1000.000) 2 3)))
)
)
(if(= data_base 0)(setq cot_in "%%p0.000"))
(if (and cot_in cot_base dim_scl (findfile block_in))
(progn
(setvar "Osmode" 0); Non Osmode
(command "_.Insert" block_in cot_base dim_scl "" "0")
(setq text_point(list (+ (car cot_base) (* 0.2 dim_scl))
(+ (cadr cot_base)(* 0.6 dim_scl)) )
text_h (* 0.4 dim_scl)
text_clr 4)
(setq old_text_st(getvar "TextStyle"))
(MT_style "SYMBOL_TEXT" "Arial.ttf" "0.7")
(command "_.Text" text_point text_h "0.0" cot_in
"_.Chprop" "L" "" "C" text_clr "")
(setvar "TextStyle" old_text_st)
(setq old_text_st NIL text_point NIL text_h NIL text_clr NIL)
)
)
);progn
);if old_base
);progn cot_base
);if cot_base
(setvar "Osmode" old_osmode)
(setq *error* old_err)
(princ)
)
;;; Find and Make TextStyle: Symbol_Text
(defun MT_style(textst_name f_name wide_fit / tbl t1 t2 key)
(setq tbl(tblnext "STYLE" 1) key NIL)
(while tbl
(setq t1 textst_name t2 (cdr(car(cdr tbl))) )
(if (equal t1 t2) (setq key 1))
(setq tbl(tblnext "STYLE"))
)
(if(/= key 1)
(progn (setq tbl NIL )
(command "_.STYLE" textst_name f_name "" wide_fit "" "" "")
(princ (strcat "\nText Style: " textst_name " was created !"))
)
(setvar "TextStyle" textst_name)
)
(setq textst_name NIL f_name NIL wide_fit NIL key NIL)
(princ)
)
;;; Copy cot cao do:
(defun Ccot (/ op_cot op_pro_c moc_cot np_cot op_p op_text text_pro
stt_c npc str_text cot_ins cot_new div_in num_text)
(setvar "Cmdecho" 0)
(setq old_osmode(getvar "Osmode")
old_ortho(getvar "Orthomode"))
(setvar "Orthomode" 1)
(setq old_error *error* *error* gc_err lim_out NIL)
(setq op_cot(ssget) stt_c NIL npc NIL op_text NIL)
(if (and op_cot (> (sslength op_cot) 1))
(progn
(setvar "Osmode" (+ 1 8 512)); End Node Near
(initget 8)
(setq moc_cot(getpoint "\n-> Diem moc copy: ") npc 1)
(if moc_cot
(progn
(while npc
(setvar "Osmode" (+ 128 512));Per Ner
(initget 8)
(if(setq np_cot(getpoint "\n->> Diem dat cot tiep theo: " moc_cot))
(progn
(pack_out_lm moc_cot np_cot)
; (setq lim_out 1)
(setq op_p NIL str_text NIL text_pro NIL op_text NIL
op_pro_c NIL stt_c 0 cot_new NIL div_in NIL cot_ins NIL)
(while (> (sslength op_cot) stt_c)
(setq op_pro_c(ssname op_cot stt_c))
(setvar "Osmode" 0)
(command "_.Copy" op_pro_c "" moc_cot np_cot)
(setq op_cot_c(entlast))
(setq op_p op_cot_c
op_text(cdr(assoc 0 (setq text_pro(entget op_p)))) )
(if (and(= op_text "TEXT")
(= "SYMBOL_TEXT" (cdr(assoc 7 (entget op_p)))) )
(progn
(setq str_text(assoc 1 text_pro))
(if (or (= (substr (cdr str_text) 1 1) "+") (= (substr (cdr str_text) 1 1) "-")(= (substr (cdr str_text) 1 3) "%%p"))
(progn
(if (or(= (substr (cdr str_text) 1 1) "+")
(= (substr (cdr str_text) 1 1) "-"))
(setq num_t 2)(setq num_t 4))
; (setq div_in (- (abs(cadr np_cot)) (abs(cadr moc_cot)))
(setq div_in (- (cadr np_cot) (cadr moc_cot))
num_text(atof (substr (cdr str_text) num_t))
num_t NIL
cot_new(+ num_text (/ div_in 1000.000)))
(if cot_new
(progn
(if(= div_in 0)(setq cot_ins "%%p0.000"))
(if(and( (if(>= (abs cot_new) 1)
(setq cot_ins(strcat "-" (rtos (* cot_new -1) 2 3)))
(progn
(if(/= (substr (rtos cot_new 2 3) 1 3) "-0.")
(setq cot_ins(strcat "-0"(rtos (* cot_new -1) 2 3)))
(setq cot_ins(strcat "-"(rtos (* cot_new -1) 2 3)))
)
)
)
(if(>= cot_new 1)
(setq cot_ins(strcat "+" (rtos cot_new 2 3)))
(progn
(if(/= (substr (rtos cot_new 2 3) 1 2) "0.")
(setq cot_ins(strcat "+0"(rtos cot_new 2 3)))
(setq cot_ins(strcat "+"(rtos cot_new 2 3)))
)
)
)
)
(if(= cot_new 0)(setq cot_ins "%%p0.000"))
(setq text_pro(subst (cons '1 cot_ins) str_text text_pro))
(entmod text_pro)
);progn
);if cot_new
)
);if str_text
)
);if op_text
(setq stt_c (+ 1 stt_c))
);while
)
(setq npc NIL)
);if np_cot
);While npc
)
);if moc_cot
)
);if op_cot
(setq *error* old_err)
(setvar "Osmode" old_osmode)
(princ)
)
;;;Pack for Out-size Limits:
(defun pack_out_lm (c_base_p n_point_p)
(if(and c_base_p n_point_c)
(progn
(if( (progn
(if( (cond
(( (setq lim_out 1.0) )
((> (cadr c_base_p)(cadr n_point_p))
(setq lim_out 1.0) )
((= (cadr c_base_p)(cadr n_point_p))
(setq lim_out -1.0) )
)
)
(if(>= (cadr n_point_p) 0)
(setq lim_out -1) )
)
);if c_base_p (if(> (cadr c_base_p) 0)
(setq lim_out -1) )
)
)
)
;End Pack
;;;
(defun C:Ccot ()
(setq old_error *error* *error* gc_err)
(ccot) (setq *error* old_err)
(princ))
;;; Load OK
;;;(princ "\nMCOT.lsp Loading... OK")Thảo luận gốc
Lisp được chia sẻ trong chủ đề Xin lisp ghi được cao độ cụ thể các điểm trên mặt cắt dọc. Xem đúng bài viết #41411 để đọc hướng dẫn và trao đổi thêm.