Jump to content

Lisp lệnh CXF trong chủ đề “Nhờ các bác giải thích dùm tai sao lisp không thể chuyển qua file .vlx”

Em mới mót được 1 số lisp mà không thể chuyển qua file .vlx được, mong các Bác giải thích dùm.



Tiện đây các Bác cho em hỏi thêm về lisp UnAnonall này là tại sao khi mình add vào coment của cad để khởi động mặc định thì nó báo lỗi như sau:
Loading UnAnon v1.0 .....; error: malformed list on input
Nhưng khi mình mở cad load file lisp thì nó lại chạy được. Mong nhận sự hồi âm của các Bác sớm. Thank các Bác nhiều.

Tệp .lsp gốc không còn trên máy chủ. Hãy chép mã nguồn bên dưới (lấy từ bài viết gốc) vào một tệp văn bản, lưu với đuôi .lsp.

Cách dùng

  1. Chép mã nguồn, lưu thành tệp 72377_cxf.lsp.
  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 CXF để chạy lisp.

Mã nguồn 72377_cxf.lsp (trích từ bài viết gốc)

;===============================================
; UnAnon.Lsp Jul 05, 1998
;======================================
(princ "\nCopyright © 1998, Fabricated Designs, Inc.")
(princ "\nLoading UnAnon v1.0 ")
(setq uan_ nil lsp_file "UnAnon")

;================== For Automated Calling From Another Program =========
(defun uan_auto (ar1) (UnAnon ar1))

;================== Macros =============================================
(defun PDot ()(princ "."))

(PDot);++++++++++++ Set Modes & Error ++++++++++++++++++++++++++++++++++
(defun uan_smd ()
(SetUndo)
(setq olderr *error*
*error* (lambda (e)
(and (/= e "quit / exit abort")
(princ (strcat "\nError: *** " e " *** ")))
(command "_.UNDO" "_END" "_.U")
(uan_rmd))
uan_var '(
("CMDECHO" . 0) ("MENUECHO" . 0) ("MENUCTL" . 0) ("MACROTRACE" . 0)
("OSMODE" . 0) ("SORTENTS" . 119)("MODEMACRO" . ".")
("BLIPMODE" . 0) ("EXPERT" . 0) ("SNAPMODE" . 1) ("PLINEWID" . 0.0)
("ORTHOMODE" . 1) ("GRIDMODE" . 0) ("ELEVATION" . 0) ("THICKNESS" . 0)
("FILEDIA" . 0) ("FILLMODE" . 0) ("SPLFRAME" . 0) ("UNITMODE" . 0)
("TEXTEVAL" . 0) ("ATTDIA" . 0) ("AFLAGS" . 0) ("ATTREQ" . 1)
("ATTMODE" . 1) ("UCSICON" . 1) ("HIGHLIGHT" . 1) ("REGENMODE" . 1)
("COORDS" . 2) ("DRAGMODE" . 2) ("DIMZIN" . 1) ("PDMODE" . 0)
("CECOLOR" . "BYLAYER") ("CELTYPE" . "BYLAYER")))
(foreach v uan_var
(setq m_v (cons (getvar (car v)) m_v)
m_n (cons (car v) m_n))
(setvar (car v) (cdr v)))
(princ (strcat (getvar "PLATFORM") " Release " (substr (ver) 18 2)
" - Convert To Anonymous Blocks ....\n"))
(princ))

(PDot);++++++++++++ Return Modes & Error +++++++++++++++++++++++++++++++
(defun uan_rmd ()
(setq *error* olderr)
(mapcar 'setvar m_n m_v)
(command "_.UNDO" "_END")
(prin1))

(PDot);++++++++++++ Set And Start An Undo Group ++++++++++++++++++++++++
(defun SetUndo ()
(and (zerop (getvar "UNDOCTL"))
(command "_.UNDO" "_ALL"))
(and (= (logand (getvar "UNDOCTL") 2) 2)
(command "_.UNDO" "_CONTROL" "_ALL"))
(and (= (logand (getvar "UNDOCTL") 8) 8)
(command "_.UNDO" "_END"))
(command "_.UNDO" "_GROUP"))

(PDot);++++++++++++ Get Entity Name ++++++++++++++++++++++++++++++++++++
(defun GetOne (/ st os)
(setq os (getvar "SNAPMODE") s nil)
(setvar "SNAPMODE" 0)
(while (not st)
(setq st (ssget)))
(while (> (sslength st) 1)
(setq st nil)
(princ "\nOnly 1 At A Time Please\n")
(while (not st)
(setq st (ssget))))
(setvar "SNAPMODE" os)
(setq s (ssname st 0)))

(PDot);++++++++++++ Convert An Anonymous Block To Named Block ++++++++++
(defun UnAnon (b / tdef en ed bc bn bd in) ;Supply ename
(setq bn "TEMP1" bc 1)
(while (tblsearch "BLOCK" bn)
(setq bc (1+ bc) bn (strcat "TEMP" (itoa bc))))
(and (= (type cool.gif 'ENAME)
(setq bd (entget cool.gif
in (cdr (assoc 2 bd))))
(if (or (not bd)
(not in)
(/= "INSERT" (cdr (assoc 0 bd)))
(/= "*U" (substr in 1 2))
(= (logand (cdr (assoc 70 (tblsearch "BLOCK" in))) 4) 4)
(= (logand (cdr (assoc 70 (tblsearch "BLOCK" in))) 16) 16)
(= (logand (cdr (assoc 70 (tblsearch "BLOCK" in))) 32) 32))
(progn
(princ "*** Not An Anonomymous Block *** ")
(setq bn nil bc nil bd nil in nil b nil)
(exit)))
(setq tdef (tblsearch "BLOCK" in)
en (cdr (assoc -2 tdef))
ed (entget en))
(entmake (list (cons 0 "BLOCK")
(cons 2 bn)
(cons 70 0)
(cons 10 (cdr (assoc 10 tdef)))))
(entmake ed)
(while (setq en (entnext en))
(setq ed (entget en))
(entmake ed))
(entmake (list (cons 0 "ENDBLK")))
(setq bd (subst (cons 2 bn) (assoc 2 bd) bd))
(entmod bd)
(entupd cool.gif
(princ (strcat "\n" bn)))

(PDot);************ Main Program ***************************************
(defun uan_ (/ m_v m_n olderr uan_var s)
(uan_smd)
(GetOne)
(UnAnon s)
(uan_rmd))

(defun c:UnAnonall (/ ss i)
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 67 (if (= (getvar "TILEMODE") 1) 0 1)))))
(and ss
(setq i (sslength ss))
(while (not (minusp (setq i (1- i))))
(setq en (ssname ss i))
(if (= "*U" (substr (cdr (assoc 2 (entget en))) 1 2))
(UnAnon en))))
(prin1))

(PDot);************ Load Program ***************************************
(defun C:UnAnon () (uan_))
(if uan_ (princ "\nUnAnon Loaded\n"))
(prin1)
;================== End Program ========================================

;Copy DT tu 1 XREF hay block
;;;--- CPYXREF - Copy any entity from an XREF or a block. 
;;;
;;;--- Legalities:
;;;    Copyright 2002-2004 by JefferyPSanders.com
;;;    All rights reserved.
;;;
;;;;   You may use this program for free.  You may not obtain profit without consent
;;;    from Jeffery P Sanders. You may make copies of this program and distribute as
;;;    long as the legalities remain in tact.
;;;
;;;    End of Legalities
;;;
;;;--- Created on 7/18/02
;;;

;;;--- Main application
(defun C:CXF()

;;;--- Turn the command echo off
(setvar "cmdecho" 0)

;;;--- Save some system variables
(setq origCmddia(getvar "cmddia"))
(setq origFiledia(getvar "filedia"))

;;;--- Set some system variables
(setvar "cmddia" 0)
(setvar "filedia" 0)

;;;--- Select an entity
(if (setq entselected(entsel "\n Select XRef or Block: "))                                           
  (progn

   ;;;--- Save the entity name
   (setq en(car entselected))

   ;;;--- Save the point selected
   (setq selectedPt(cadr entselected))

   ;;;--- Get entity's DXF group codes
   (setq enlist(entget en))                           

   ;;;--- If it is a block
   (if(= "INSERT" (cdr(assoc 0 enlist)))               
     (progn

       ;;;--- Get the dxf group codes for the first sub-entity
       (setq enlist2(tblNext "block" en))

       ;;;--- Save the file name of the block
       (setq shortFileName(cdr(assoc 2 enlist)))    ;thanks to Günther Bittner for fix

       ;;;--- Set a mark for the undo command
       (command "undo" "mark")

       ;;;--- Make the XREF part of the drawing temporarily
       (command "-xref" "bind" shortFileName)

       ;;;--- Explode the block temporarily
       (command "explode" en)

       ;;;--- Get the entity at the point selected originally if it exist
       (if (setq eset(ssget selectedPt))
         (progn

            ;;;--- Get the name of the entity selected
            (setq en(ssname eset 0))

            ;;;--- Get the DXF group codes of the entity
            (setq enlist(entget en))

            ;;;--- Make a wblock named "X2"
            (if(findfile "x2.dwg")
              (command "_wblock" "x2" "y" "" selectedPt en "")
              (command "_wblock" "x2" "" selectedPt en "")
            )

            ;;;--- Undo everything back to the marked position
            (command "undo" "Back")

            ;;;--- Insert the X2 block
            (setq pt1(getpoint selectedPt "\n Insertion Point: "))
            (command "insert" "*x2" pt1 "" "")

          )
          (alert "*Error* - Select a sub-entity.")
       )
     )
     (alert "*Error* - Select a block or an XREF.")
   )
  )
  (alert "*Error* - Select a block or an XREF please.")
)

;;;--- Reset system variables
(setvar "cmddia" origCmddia)
(setvar "filedia" origFiledia)

;;;--- Turn command echo back on
(setvar "cmdecho" 1)

;;;--- Inform the user
(princ "\n ...CPYXREF.lsp Complete.  ")
(princ "\n By: Jeffery P. Sanders  7/19/02 Copyright 2002-2004 by JefferyPSanders.com")

 ;;;--- Suppress last echo for a clean exit
(princ)
)

Thảo luận gốc

Lisp được chia sẻ trong chủ đề Nhờ các bác giải thích dùm tai sao lisp không thể chuyển qua file .vlx. Xem đúng bài viết #72377 để đọc hướng dẫn và trao đổi thêm.

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