Hi,
For a long time I have been using the Lisp file below, which ran well on AutoCad. Recently my company switched from Acad to DraftSight. Unfortunately, Draftsight does not support this Lisp code. Can anyone help me fix the file so that it can be used in DraftSight?
The Lisp code is used to copy the text from the file name and add it to the sketch in DXF format.
(vl-load-com)
(defun ChangeVisibleTo0 ()
;; Change all entities from "Visible" layer to "0" layer
(setq ss (ssget "X" '((8 . "Visible")))) ; Select all entities on the "Visible" layer
(if ss
(repeat (sslength ss)
(setq ent (ssname ss 0)) ; Get the first entity in the selection set
(setq entData (entget ent)) ; Get entity data
(setq entData (subst (cons 8 "0") (assoc 8 entData) entData)) ; Change layer to "0"
(entmod entData) ; Modify the entity with updated layer
(ssdel ent ss) ; Remove it from the selection set
)
(princ "\\nNo entities found on layer 'Visible'.")
)
(princ)
)
(defun get_active_file_path ()
;; Get the folder path of the currently active drawing file
(if (getvar "DWGPREFIX")
(getvar "DWGPREFIX") ; Get the path of the active drawing
(alert "No active drawing file found!") ; Alert if no drawing is open
)
)
(defun get_dxf_file_lst ()
;; Retrieves the list of DXF files in the active drawing's directory
(if (setq DXF_Path_Name (get_active_file_path))
(progn
(setq fil_lst (vl-directory-files DXF_Path_Name "*.dxf" 1))
(if (/= fil_lst nil)
(setq fil_lst (acad_strlsort fil_lst))
(setq fil_lst (list ""))
) ; end if
) ; progn
) ; if
(princ)
) ; end function get_dxf_file_list
;; Local Functions to process each DXF, add text, save in Finished folder
(defun save_the_dxf ( fname )
(setq FOLDER (strcat DXF_Path_Name "Final DXF For Programming"))
(vl-mkdir FOLDER) ; Nil if folder exists
(setq OUTPATH (strcat FOLDER "\\\\"))
(setq dxfname (strcat OUTPATH out_fil))
(command "_DXFOUT" dxfname 16)
) ; end function save_the_dxf
(defun get_project_string ( fname )
(setq str fname FLAG 0) ; blanked string
;; Returns the intact filename, IF it doesn't find a "_" delimiter.
(if fname
(progn
(setq N 1)
(repeat (strlen fname)
(if (= FLAG 0)
(progn
(setq chk (substr fname N 1))
(if (= chk "_")
(progn
(setq FLAG 1)
(setq str (substr fname 1 (- N 1)))
) ; progn
) ; if
) ; progn
) ; if
(setq N (+ N 1))
) ; repeat
) ; progn
) ; if
str
) ; end function get_project_string
(defun add_text_to_dxf ( DXFList )
(setq olay (getvar "clayer")) ; get current layer
(setq L 0)
(repeat (length DXFList)
(setq dx_fil (nth L DXFList)) ; get a file at a time
(setq out_fil dx_fil) ; Save existing File Name
(setq dx_fil (strcat DXF_Path_Name dx_fil))
(command "_erase" "all" "")
(command "_purge" "ALL" "" "N")
(command "_DXFIN" dx_fil) ; load the DXF
(command "_zoom" "E") ; zoom
;; Call the layer change function
(ChangeVisibleTo0)
;; Add text to the DXF file
(setq txt (get_project_string out_fil))
(if (/= txt "")
(progn
(command "_layer" "M" "YELLOW" "C" "Yellow" "YELLOW" "") ; Added to Make/Set Layer
(setvar "TEXTSIZE" 10) ; or whatever text height you need.
(command "_Text" (list 0.0 0.0 0.0) (getvar "textsize") "0" (strcat txt MatCode))
) ; progn
) ; if
;; Save the DXF file
(save_the_dxf dx_fil)
(setq L (+ L 1))
) ; repeat
(princ "\\n")
(alert (strcat "Engraving text added, DXF Files saved in " OUTPATH))
(setvar "clayer" olay) ; reset to current layer
(princ)
) ; end function add_text_to_dxf
;; Begin
(setq fil_lst nil)
(setq MatCode (getstring 1 "\\nEnter the Material Code: "))
(get_dxf_file_lst)
(if fil_lst
(add_text_to_dxf fil_lst)
) ; if
(if (= fil_lst nil)
(alert "Did Not Find any .dxf Files in that Folder ?")
) ; if
(princ)
