Chuyển đến nội dung
Diễn đàn CADViet
Đăng nhập để thực hiện theo  
matngot

Nhờ các bác giúp sửa lisp ah

Các bài được khuyến nghị

E chào các bác ah! Hôm nay e xin nhờ các bác sửa giúp e cái lisp vẽ mặt cắt dọc này với ah chả là e muốn lisp vẽ mặt cắt dọc khi đánh lệnh để chạy sẽ xuất hiện hộp thoại DCl để điền các thông số song nhấn thực hiện lệnh vẽ. e có tìm hiểu và tự tạo ra file DCL như này

mc_dialog : dialog {
  label = "NHAP THONG SO MAT CAT DOC";

  : edit_box { label = "Ty le ngang 1/?"; key = "hf"; }
  : edit_box { label = "Ty le dung 1/?"; key = "vf"; }
  : edit_box { label = "Cao do so sanh (m)"; key = "level"; }
  : edit_box { label = "Ly trinh diem dau (m)"; key = "st"; }
  : edit_box { label = "Chieu cao Text Title"; key = "th"; }
  : edit_box { label = "Chieu cao Text cao do"; key = "th1"; }

  : edit_box { label = "File du lieu TXT"; key = "file"; }
  : button { label = "Chon File..."; key = "chonfile"; }

  spacer;
  : row {
    : button { label = "Ve"; is_default = true; key = "accept"; }
    : button { label = "Thoat"; key = "cancel"; }
  }
}

nhưng giờ bên lisp mặt cắt dọc e không biết phải sửa như nào để nó hoạt động được với hộp thoại DCL trên ah mong các bác sửa giúp e với. Đây là lisp vẽ mặt cắt dọc e đính kèm ah rất mong các bác sửa giúp e với ah. Em chân thành cảm ơn mọi người ah

 

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Bạn tham khảo lisp này của mình nhé, cái này mình cũng tham khảo từ Leemac.

 

Tóm tắt trình tự các bước:

1. Khởi tạo biến: tên biến trùng với tên key; kiểu biến tùy vào cách quản lý của người code, trong bài này mình đang để tất cả là string.

2. Tạo file DCL: tạo trực tiếp trong file lisp chứ không cần tạo thông qua notepad

3. Set_tile: Tự động điền theo giá trị nhập trước đó (hoặc mặc định)

4. Lưu giá trị nhập vào biến khi người dùng bấm OK.

 

Phiên bản đơn giản

;Mo hop thoai DCL
(defun C:tl ( / DCH DCL DIALOG TITLE)
  (setq title "DCL Sample v1.00")
  (setq dialog "DCL_SAMPLE")
  (setq dcl (vl-filename-mktemp nil nil ".dcl"))
  ;(setq dcl "C:\\Users\\duongnhatduy\\Desktop\\DCLSample.dcl");Sua dcl thanh duong dan bat ky neu muon xem file dcl
  (cond
    ((not (LM:dcl_write dcl dialog title))
     (princ "\nDCL file could not be written.")
     )
    ((<= (setq dch (load_dialog dcl)) 0)
     (princ "\nDCL file could not be loaded.")
     )
    ((not (new_dialog dialog dch))
     (princ "\nProgram dialog could not be loaded.")
     )
    (t
     (setq LM-VAR-DEFAULT
	    '(
	      (LM-EDBOX1 . "1")
	      (LM-EDBOX2 . "2")
	      (LM-TOGGLE1 . "1")
	      (LM-TOGGLE2 . "0")
	      (LM-TOGGLE3 . "0")
	      (LM-RADIO1 . "1")
	      (LM-RADIO2 . "0")
	      (LM-RADIO3 . "0")
	      )
	   )
     (mapcar '(lambda (lst) (if (not (eval (car lst))) (set (car lst) (cdr lst)))) LM-VAR-DEFAULT)
     (mapcar '(lambda (sym) (set_tile (vl-symbol-name sym) (eval sym))) (mapcar 'car LM-VAR-DEFAULT))
     (action_tile "accept"
       (vl-prin1-to-string
	 '(progn
	   (mapcar '(lambda (sym) (set sym (get_tile (vl-symbol-name sym)))) (mapcar 'car LM-VAR-DEFAULT))
	   (done_dialog)
	   )))
     (action_tile "cancel" "(done_dialog)")
     (start_dialog)
     (unload_dialog dch)
     )
    )
  (princ)
  )

;Tao file DCL
(defun LM:dcl_write (dcl dialog title / des lst)
  (setq des (open dcl "w"))
  (setq lst
	 (list
	   dialog
	   ": dialog"
	   "	{"
	   (strcat "\tlabel = \"" title "\";")
	   "	: column"
	   "		{"
	   "		: boxed_column"
	   "			{"
	   "			label = \"Edit box\";"
	   "			: edit_box { key = \"LM-EDBOX1\"; label = \"Edit box 1\"; edit_width = 8; }"
	   "			: edit_box { key = \"LM-EDBOX2\"; label = \"Edit box 2\"; edit_width = 8; }"
	   "			}"
	   "		: boxed_column"
	   "			{"
	   "			label = \"Toggle\";"
	   "			: toggle { key = \"LM-TOGGLE1\"; label = \"Toggle 1\"; }"
	   "			: toggle { key = \"LM-TOGGLE2\"; label = \"Toggle 2\"; }"
	   "			: toggle { key = \"LM-TOGGLE3\"; label = \"Toggle 3\"; }"
	   "			}"
	   "		: boxed_column"
	   "			{"
	   "			label = \"Radio button\";"
	   "			: radio_button { key = \"LM-RADIO1\"; label = \"Radio 1\"; }"
	   "			: radio_button { key = \"LM-RADIO2\"; label = \"Radio 2\"; }"
	   "			: radio_button { key = \"LM-RADIO3\"; label = \"Radio 3\"; }"
	   "			}"
	   "		ok_cancel;"
	   "		}"
	   "	}"
	   ))
  (foreach x lst (write-line x des))
  (setq des (close des))
  (while (not (findfile dcl)))
  dcl
  )

 

Phiên bản đầy đủ hơn (có popup list và list box)

;Mo hop thoai DCL
(defun C:tl ( / DCH DCL DIALOG TITLE)
  (setq title "DCL Sample v1.00")
  (setq dialog "DCL_SAMPLE")
  (setq dcl (vl-filename-mktemp nil nil ".dcl"))
  ;(setq dcl "C:\\Users\\duongnhatduy\\Desktop\\DCLSample.dcl");Sua dcl thanh duong dan bat ky neu muon xem file dcl
  (cond
    ((not (LM:dcl_write dcl dialog title))
     (princ "\nDCL file could not be written.")
     )
    ((<= (setq dch (load_dialog dcl)) 0)
     (princ "\nDCL file could not be loaded.")
     )
    ((not (new_dialog dialog dch))
     (princ "\nProgram dialog could not be loaded.")
     )
    (t
     (LM:dcl_settile)
     (action_tile "LM-DEFAULT" "(LM:dcl_default)")
     (action_tile "accept" "(LM:dcl_savevar)")
     (action_tile "cancel" "(done_dialog)")
     (start_dialog)
     (unload_dialog dch)
     )
    )
  (princ)
  )

;Tu dong dien theo bien
(defun LM:dcl_settile ()
  (start_list "LM-POPUP1" 3)
  (mapcar 'add_list LM-POPUP1-LIST)
  (end_list)

  (start_list "LM-LISTBOX1" 3)
  (mapcar 'add_list LM-LISTBOX1-LIST)
  (end_list)
  
  (mapcar '(lambda (sym) (set_tile (vl-symbol-name sym) (eval sym))) (mapcar 'car LM-VAR-DEFAULT))
  )

;Khoi phuc cai dat mac dinh
(defun LM:dcl_default ()
  (mapcar '(lambda (lst) (set_tile (vl-symbol-name (car lst)) (cdr lst))) LM-VAR-DEFAULT)
  )

;Luu gia tri dien vao bien
(defun LM:dcl_savevar ()
  (mapcar '(lambda (sym) (set sym (get_tile (vl-symbol-name sym)))) (mapcar 'car LM-VAR-DEFAULT))
  (done_dialog)
  )

;Khoi tao bien
(defun LM:dcl_setvar ()
  (setq LM-VAR-DEFAULT
	 '(
	   (LM-EDBOX1 . "1")
	   (LM-EDBOX2 . "2")
	   (LM-TOGGLE1 . "1")
	   (LM-TOGGLE2 . "0")
	   (LM-TOGGLE3 . "0")
	   (LM-RADIO1 . "1")
	   (LM-RADIO2 . "0")
	   (LM-RADIO3 . "0")
	   (LM-POPUP1 . "0")
	   (LM-LISTBOX1 . "")
	   )
	)
  (setq LM-POPUP1-LIST
	 '(
	   "Choice 1"
	   "Choice 2"
	   "Choice 3"
	   "Choice 4"
	   "Choice 5"
	   )
	)
  (setq LM-LISTBOX1-LIST
	 '(
	   "Choice 1"
	   "Choice 2"
	   "Choice 3"
	   "Choice 4"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   )
	)
  (mapcar '(lambda (lst) (if (not (eval (car lst))) (set (car lst) (cdr lst)))) LM-VAR-DEFAULT)
  (princ)
  )
(LM:dcl_setvar)

;Tao file DCL
(defun LM:dcl_write (dcl dialog title / des lst)
  (setq des (open dcl "w"))
  (setq lst
	 (list
	   dialog
	   ": dialog"
	   "	{"
	   (strcat "\tlabel = \"" title "\";")
	   "	: column"
	   "		{"
	   "		: row"
	   "			{"
	   "			: column"
	   "				{"
	   "				fixed_width = true ;"
	   "				width = 30 ;"
	   "				: boxed_column"
	   "					{"
	   "					label = \"Edit box\";"
	   "					: edit_box { key = \"LM-EDBOX1\"; label = \"Edit box 1\"; edit_width = 8; }"
	   "					: edit_box { key = \"LM-EDBOX2\"; label = \"Edit box 2\"; edit_width = 8; }"
	   "					}"
	   "				: boxed_column"
	   "					{"
	   "					label = \"Toggle\";"
	   "					: toggle { key = \"LM-TOGGLE1\"; label = \"Toggle 1\"; }"
	   "					: toggle { key = \"LM-TOGGLE2\"; label = \"Toggle 2\"; }"
	   "					: toggle { key = \"LM-TOGGLE3\"; label = \"Toggle 3\"; }"
	   "					}"
	   "				: boxed_column"
	   "					{"
	   "					label = \"Radio button\";"
	   "					: radio_button { key = \"LM-RADIO1\"; label = \"Radio 1\"; }"
	   "					: radio_button { key = \"LM-RADIO2\"; label = \"Radio 2\"; }"
	   "					: radio_button { key = \"LM-RADIO3\"; label = \"Radio 3\"; }"
	   "					}"
	   "				}"
	   "			: column"
	   "				{"
	   "				fixed_width = true ;"
	   "				width = 35 ;"
	   "				: boxed_column"
	   "					{"
	   "					label = \"Popup list\";"
	   "					: popup_list { key = \"LM-POPUP1\"; label = \"Popup list 1\"; edit_width = 15; }"
	   "					}"
	   "				: boxed_column"
	   "					{"
	   "					label = \"List box\";"
	   "					: list_box { key = \"LM-LISTBOX1\"; label = \"List box 1\"; multiple_select = true; height = 10; width = 15; }"
	   "					}"
	   "				}"
	   "			}"
	   "		: boxed_column"
	   "			{"
	   "			label = \"Text\";"
	   "			: text { key = \"LM-TEXT1\"; value = \"Text 1\"; }"
	   "			: text { key = \"LM-TEXT2\"; value = \"Text 2\"; }"
	   "			: text { key = \"LM-TEXT3\"; value = \"Text 3\"; }"
	   "			}"
	   "		: row"
	   "			{"
	   "			: spacer { width = 5 ; }"
	   "			: button { key = \"LM-DEFAULT\"; label = \"Default\"; fixed_width = true; width = 12 ; }"
	   "			: button { key = \"accept\"; label = \"OK\"; is_default = true; fixed_width = true; width = 12 ; }"
	   "			: button { key = \"cancel\"; label = \"Cancel\"; is_default = false; is_cancel = true; fixed_width = true; width = 12 ; }"
	   "			: spacer { width = 5 ; }"
	   "			}"
	   "		}"
	   "	}"
	   ))
  (foreach x lst (write-line x des))
  (setq des (close des))
  (while (not (findfile dcl)))
  dcl
  )

 

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Trình độ DCL của bạn gần như chưa có gì nên là tốt nhất tham khảo những code đã có.

Mình từng đăng 1 dcl tặng mọi người có thể xem tại đây: 

 

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác
1 giờ} trướ}c, Duong Nhat Duy đã nói:

Bạn tham khảo lisp này của mình nhé, cái này mình cũng tham khảo từ Leemac.

 

Tóm tắt trình tự các bước:

1. Khởi tạo biến: tên biến trùng với tên key; kiểu biến tùy vào cách quản lý của người code, trong bài này mình đang để tất cả là string.

2. Tạo file DCL: tạo trực tiếp trong file lisp chứ không cần tạo thông qua notepad

3. Set_tile: Tự động điền theo giá trị nhập trước đó (hoặc mặc định)

4. Lưu giá trị nhập vào biến khi người dùng bấm OK.

 

Phiên bản đơn giản


;Mo hop thoai DCL
(defun C:tl ( / DCH DCL DIALOG TITLE)
  (setq title "DCL Sample v1.00")
  (setq dialog "DCL_SAMPLE")
  (setq dcl (vl-filename-mktemp nil nil ".dcl"))
  ;(setq dcl "C:\\Users\\duongnhatduy\\Desktop\\DCLSample.dcl");Sua dcl thanh duong dan bat ky neu muon xem file dcl
  (cond
    ((not (LM:dcl_write dcl dialog title))
     (princ "\nDCL file could not be written.")
     )
    ((<= (setq dch (load_dialog dcl)) 0)
     (princ "\nDCL file could not be loaded.")
     )
    ((not (new_dialog dialog dch))
     (princ "\nProgram dialog could not be loaded.")
     )
    (t
     (setq LM-VAR-DEFAULT
	    '(
	      (LM-EDBOX1 . "1")
	      (LM-EDBOX2 . "2")
	      (LM-TOGGLE1 . "1")
	      (LM-TOGGLE2 . "0")
	      (LM-TOGGLE3 . "0")
	      (LM-RADIO1 . "1")
	      (LM-RADIO2 . "0")
	      (LM-RADIO3 . "0")
	      )
	   )
     (mapcar '(lambda (lst) (if (not (eval (car lst))) (set (car lst) (cdr lst)))) LM-VAR-DEFAULT)
     (mapcar '(lambda (sym) (set_tile (vl-symbol-name sym) (eval sym))) (mapcar 'car LM-VAR-DEFAULT))
     (action_tile "accept"
       (vl-prin1-to-string
	 '(progn
	   (mapcar '(lambda (sym) (set sym (get_tile (vl-symbol-name sym)))) (mapcar 'car LM-VAR-DEFAULT))
	   (done_dialog)
	   )))
     (action_tile "cancel" "(done_dialog)")
     (start_dialog)
     (unload_dialog dch)
     )
    )
  (princ)
  )

;Tao file DCL
(defun LM:dcl_write (dcl dialog title / des lst)
  (setq des (open dcl "w"))
  (setq lst
	 (list
	   dialog
	   ": dialog"
	   "	{"
	   (strcat "\tlabel = \"" title "\";")
	   "	: column"
	   "		{"
	   "		: boxed_column"
	   "			{"
	   "			label = \"Edit box\";"
	   "			: edit_box { key = \"LM-EDBOX1\"; label = \"Edit box 1\"; edit_width = 8; }"
	   "			: edit_box { key = \"LM-EDBOX2\"; label = \"Edit box 2\"; edit_width = 8; }"
	   "			}"
	   "		: boxed_column"
	   "			{"
	   "			label = \"Toggle\";"
	   "			: toggle { key = \"LM-TOGGLE1\"; label = \"Toggle 1\"; }"
	   "			: toggle { key = \"LM-TOGGLE2\"; label = \"Toggle 2\"; }"
	   "			: toggle { key = \"LM-TOGGLE3\"; label = \"Toggle 3\"; }"
	   "			}"
	   "		: boxed_column"
	   "			{"
	   "			label = \"Radio button\";"
	   "			: radio_button { key = \"LM-RADIO1\"; label = \"Radio 1\"; }"
	   "			: radio_button { key = \"LM-RADIO2\"; label = \"Radio 2\"; }"
	   "			: radio_button { key = \"LM-RADIO3\"; label = \"Radio 3\"; }"
	   "			}"
	   "		ok_cancel;"
	   "		}"
	   "	}"
	   ))
  (foreach x lst (write-line x des))
  (setq des (close des))
  (while (not (findfile dcl)))
  dcl
  )

 

Phiên bản đầy đủ hơn (có popup list và list box)


;Mo hop thoai DCL
(defun C:tl ( / DCH DCL DIALOG TITLE)
  (setq title "DCL Sample v1.00")
  (setq dialog "DCL_SAMPLE")
  (setq dcl (vl-filename-mktemp nil nil ".dcl"))
  ;(setq dcl "C:\\Users\\duongnhatduy\\Desktop\\DCLSample.dcl");Sua dcl thanh duong dan bat ky neu muon xem file dcl
  (cond
    ((not (LM:dcl_write dcl dialog title))
     (princ "\nDCL file could not be written.")
     )
    ((<= (setq dch (load_dialog dcl)) 0)
     (princ "\nDCL file could not be loaded.")
     )
    ((not (new_dialog dialog dch))
     (princ "\nProgram dialog could not be loaded.")
     )
    (t
     (LM:dcl_settile)
     (action_tile "LM-DEFAULT" "(LM:dcl_default)")
     (action_tile "accept" "(LM:dcl_savevar)")
     (action_tile "cancel" "(done_dialog)")
     (start_dialog)
     (unload_dialog dch)
     )
    )
  (princ)
  )

;Tu dong dien theo bien
(defun LM:dcl_settile ()
  (start_list "LM-POPUP1" 3)
  (mapcar 'add_list LM-POPUP1-LIST)
  (end_list)

  (start_list "LM-LISTBOX1" 3)
  (mapcar 'add_list LM-LISTBOX1-LIST)
  (end_list)
  
  (mapcar '(lambda (sym) (set_tile (vl-symbol-name sym) (eval sym))) (mapcar 'car LM-VAR-DEFAULT))
  )

;Khoi phuc cai dat mac dinh
(defun LM:dcl_default ()
  (mapcar '(lambda (lst) (set_tile (vl-symbol-name (car lst)) (cdr lst))) LM-VAR-DEFAULT)
  )

;Luu gia tri dien vao bien
(defun LM:dcl_savevar ()
  (mapcar '(lambda (sym) (set sym (get_tile (vl-symbol-name sym)))) (mapcar 'car LM-VAR-DEFAULT))
  (done_dialog)
  )

;Khoi tao bien
(defun LM:dcl_setvar ()
  (setq LM-VAR-DEFAULT
	 '(
	   (LM-EDBOX1 . "1")
	   (LM-EDBOX2 . "2")
	   (LM-TOGGLE1 . "1")
	   (LM-TOGGLE2 . "0")
	   (LM-TOGGLE3 . "0")
	   (LM-RADIO1 . "1")
	   (LM-RADIO2 . "0")
	   (LM-RADIO3 . "0")
	   (LM-POPUP1 . "0")
	   (LM-LISTBOX1 . "")
	   )
	)
  (setq LM-POPUP1-LIST
	 '(
	   "Choice 1"
	   "Choice 2"
	   "Choice 3"
	   "Choice 4"
	   "Choice 5"
	   )
	)
  (setq LM-LISTBOX1-LIST
	 '(
	   "Choice 1"
	   "Choice 2"
	   "Choice 3"
	   "Choice 4"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   "Choice 5"
	   )
	)
  (mapcar '(lambda (lst) (if (not (eval (car lst))) (set (car lst) (cdr lst)))) LM-VAR-DEFAULT)
  (princ)
  )
(LM:dcl_setvar)

;Tao file DCL
(defun LM:dcl_write (dcl dialog title / des lst)
  (setq des (open dcl "w"))
  (setq lst
	 (list
	   dialog
	   ": dialog"
	   "	{"
	   (strcat "\tlabel = \"" title "\";")
	   "	: column"
	   "		{"
	   "		: row"
	   "			{"
	   "			: column"
	   "				{"
	   "				fixed_width = true ;"
	   "				width = 30 ;"
	   "				: boxed_column"
	   "					{"
	   "					label = \"Edit box\";"
	   "					: edit_box { key = \"LM-EDBOX1\"; label = \"Edit box 1\"; edit_width = 8; }"
	   "					: edit_box { key = \"LM-EDBOX2\"; label = \"Edit box 2\"; edit_width = 8; }"
	   "					}"
	   "				: boxed_column"
	   "					{"
	   "					label = \"Toggle\";"
	   "					: toggle { key = \"LM-TOGGLE1\"; label = \"Toggle 1\"; }"
	   "					: toggle { key = \"LM-TOGGLE2\"; label = \"Toggle 2\"; }"
	   "					: toggle { key = \"LM-TOGGLE3\"; label = \"Toggle 3\"; }"
	   "					}"
	   "				: boxed_column"
	   "					{"
	   "					label = \"Radio button\";"
	   "					: radio_button { key = \"LM-RADIO1\"; label = \"Radio 1\"; }"
	   "					: radio_button { key = \"LM-RADIO2\"; label = \"Radio 2\"; }"
	   "					: radio_button { key = \"LM-RADIO3\"; label = \"Radio 3\"; }"
	   "					}"
	   "				}"
	   "			: column"
	   "				{"
	   "				fixed_width = true ;"
	   "				width = 35 ;"
	   "				: boxed_column"
	   "					{"
	   "					label = \"Popup list\";"
	   "					: popup_list { key = \"LM-POPUP1\"; label = \"Popup list 1\"; edit_width = 15; }"
	   "					}"
	   "				: boxed_column"
	   "					{"
	   "					label = \"List box\";"
	   "					: list_box { key = \"LM-LISTBOX1\"; label = \"List box 1\"; multiple_select = true; height = 10; width = 15; }"
	   "					}"
	   "				}"
	   "			}"
	   "		: boxed_column"
	   "			{"
	   "			label = \"Text\";"
	   "			: text { key = \"LM-TEXT1\"; value = \"Text 1\"; }"
	   "			: text { key = \"LM-TEXT2\"; value = \"Text 2\"; }"
	   "			: text { key = \"LM-TEXT3\"; value = \"Text 3\"; }"
	   "			}"
	   "		: row"
	   "			{"
	   "			: spacer { width = 5 ; }"
	   "			: button { key = \"LM-DEFAULT\"; label = \"Default\"; fixed_width = true; width = 12 ; }"
	   "			: button { key = \"accept\"; label = \"OK\"; is_default = true; fixed_width = true; width = 12 ; }"
	   "			: button { key = \"cancel\"; label = \"Cancel\"; is_default = false; is_cancel = true; fixed_width = true; width = 12 ; }"
	   "			: spacer { width = 5 ; }"
	   "			}"
	   "		}"
	   "	}"
	   ))
  (foreach x lst (write-line x des))
  (setq des (close des))
  (while (not (findfile dcl)))
  dcl
  )

 

 

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Tạo một tài khoản hoặc đăng nhập để nhận xét

Bạn cần phải là một thành viên để lại một bình luận

Tạo tài khoản

Đăng ký một tài khoản mới trong cộng đồng của chúng tôi. Điều đó dễ mà.

Đăng ký tài khoản mới

Đăng nhập

Bạn có sẵn sàng để tạo một tài khoản ? Đăng nhập tại đây.

Đăng nhập ngay
Đăng nhập để thực hiện theo  

×