Lisp lệnh TEST trong chủ đề “[Thư Viện] Tập hợp một số hàm entmake object”
Đây bạn, mình sưu tầm
- Tải lisp
- 164989_test.lsp
Cách dùng
- Tải tệp 164989_test.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 TEST để chạy lisp.
Mã nguồn 164989_test.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/52258-th%C6%B0-vi%E1%BB%87n-t%E1%BA%ADp-h%E1%BB%A3p-m%E1%BB%99t-s%E1%BB%91-h%C3%A0m-entmake-object/?tab=comments#comment-164947
;;-------------------=={ Add MLine Style }==------------------;;
;; ;;
;; Adds an MLine Style to the ACAD_MLINESTYLE dictionary ;;
;;------------------------------------------------------------;;
;; Author: Lee McDonnell, 2010 ;;
;; ;;
;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; data - a DXF list of MLineStyle data ;;
;;------------------------------------------------------------;;
;; Returns: MLineStyle Dictionary Entity, else nil ;;
;;------------------------------------------------------------;;
(defun LM:AddMLineStyle ( data / dic obj )
;; © Lee Mac 2010
(if (and (setq dic (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))
(not (dictsearch (setq dic (cdr (assoc -1 dic))) (cdr (assoc 2 data))))
(setq obj (entmakex data)))
(dictadd dic (cdr (assoc 2 data)) obj)
)
)
;;-----------------=={ Delete MLine Style }==-----------------;;
;; ;;
;; Removes an MLine Style from the ACAD_MLINESTYLE ;;
;; dictionary ;;
;;------------------------------------------------------------;;
;; Author: Lee McDonnell, 2010 ;;
;; ;;
;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; name - the name of an MLine Style to remove ;;
;;------------------------------------------------------------;;
;; Returns: Entity name of removed style, else nil ;;
;;------------------------------------------------------------;;
(defun LM:DeleteMLineStyle ( name / dic )
;; © Lee Mac 2010
(if (setq dic (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))
(dictremove (cdr (assoc -1 dic)) name)
)
)
;;------------------------------------------------------------;;
;; Test Function
(defun Example ( / lst )
(setq lst
(list
(cons 0 "MLINESTYLE")
(cons 100 "AcDbMlineStyle")
(cons 2 "Example") ; Name
(cons 70 (+ 272)) ; caps/fill/joints
(cons 3 "") ; Desc
(cons 51 (/ pi 2.)); Start ang
(cons 52 (/ pi 2.)); End ang
(cons 71 2) ; Number of lines
(cons 49 -0.5) ; Element Offset
(cons 62 256) ; Element Colour
(cons 6 "BYLAYER") ; Element Linetype
(cons 49 0.5)
(cons 62 256)
(cons 6 "BYLAYER")
)
)
(LM:AddMLineStyle lst)
)
;;----------------------=={ Add MLine }==---------------------;;
;; ;;
;; Adds a VLA MLine Object to the supplied Block container ;;
;; object, going through the supplied vertex list. ;;
;;------------------------------------------------------------;;
;; Author: Lee McDonnell, 2010 ;;
;; ;;
;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; space - VLA Block Object ;;
;; ptLst - List of 3D Points for MLine Vertices ;;
;;------------------------------------------------------------;;
;; Returns: VLA MLine Object, else nil ;;
;;------------------------------------------------------------;;
(defun LM:AddMLine ( space ptLst )
;; © Lee Mac 2010
(vla-AddMline space (LM:PointVariant ptLst))
)
;;------------------=={ Safearray Variant }==-----------------;;
;; ;;
;; Creates a populated Safearray Variant of a specified ;;
;; data type ;;
;;------------------------------------------------------------;;
;; Author: Lee McDonnell, 2010 ;;
;; ;;
;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; datatype - variant type enum (eg vlax-vbDouble) ;;
;; data - list of static type data ;;
;;------------------------------------------------------------;;
;; Returns: VLA Variant Object of type specified ;;
;;------------------------------------------------------------;;
(defun LM:SafearrayVariant ( datatype data )
;; © Lee Mac 2010
(vlax-make-variant
(vlax-safearray-fill
(vlax-make-safearray datatype
(cons 0 (1- (length data)))
)
data
)
)
)
;;--------------------=={ Point Variant }==-------------------;;
;; ;;
;; Creates a populated Safearray Variant of Double type. ;;
;;------------------------------------------------------------;;
;; Author: Lee McDonnell, 2010 ;;
;; ;;
;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; lst - list of 2D/3D Points to populate the Variant. ;;
;;------------------------------------------------------------;;
;; Returns: VLA Safearray Variant ;;
;;------------------------------------------------------------;;
(defun LM:PointVariant ( lst )
;; © Lee Mac 2010
(LM:SafearrayVariant vlax-VBDouble (apply 'append lst))
)
;;---------------------=={ Get Points }==---------------------;;
;; ;;
;; Returns a list of selected points. ;;
;;------------------------------------------------------------;;
;; Author: Lee McDonnell, 2010 ;;
;; ;;
;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
;;------------------------------------------------------------;;
;; Arguments: - None - ;;
;;------------------------------------------------------------;;
;; Returns: List of 3D Points ;;
;;------------------------------------------------------------;;
(defun LM:GetPoints ( / lst pt )
;; © Lee Mac 2010
(if (car (setq lst (list (getpoint "\nPick First Point: "))))
(while (setq pt (getpoint "\nPick Next Point: " (car lst)))
(mapcar
(function
(lambda ( from to ) (grdraw from to 3 1))
)
(cdr (reverse (setq lst (cons pt lst))))
(reverse (cdr lst))
)
)
)
(redraw) (reverse lst)
)
;;------------------------------------------------------------;;
;; Test Function
(defun c:test ( / lst )
(if (setq lst (LM:GetPoints))
(LM:AddMLine
(vla-get-ModelSpace
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
lst
)
)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề [Thư Viện] Tập hợp một số hàm entmake object. Xem đúng bài viết #164989 để đọc hướng dẫn và trao đổi thêm.