 ; Write selected entity data sublists to a file.
 ; Copyright 1994, 1996, 2011 by Rocket Software Ltd.
 ; Surprisingly useful - sort of like a slide hammer.

 (DEFUN SALMO (entt assocl / len numaso subb datlst)
  (setq len (1- (length assocl)))
  (while (>= len 0)
         (setq numaso (nth len assocl))
         (setq subb (assoc numaso entt))
         (if (null subb) (setq subb (list numaso ())))
         (setq datlst (cons subb datlst))
         (setq len (1- len)))
 datlst)

 (DEFUN C:LOX (/ aa ss assocl fn ff nnn bb follow datlst)
  (write-line "Select entities to file: ")
  (setq ss (ssget))
  (while (setq num (getint
          "\nAssociation Number, None = Write All, <Return> When Finished: "))
         (setq assocl (cons num assocl)))
  (setq assocl (reverse assocl))
  (if (= "" (setq fn (getstring "Filename: ")))
      (setq fn ())
      (progn
           (setq ff (open fn "w"))
           (close ff)
           (setq ff (open fn "a"))))
  (setq num 0)
  (while (and ff (setq enam (ssname ss num)))
         (setq entt (entget enam))                 ; get entity data
         (setq datlst (salmo entt assocl))
         (prin1 datlst ff)                         ; write data to file
         (write-line "" ff)                        ; insert cr-lf
         (if (= (cdr (assoc 66 entt)) 1)           ; if entities follow
             (while (/= (cdr (assoc 0 (setq entt (entget
                                       (setq enam (entnext enam)))))) "SEQEND")
                    (princ "  " ff)                ; indent subentities
                    (if assocl
                        (setq datlst (salmo entt assocl))
                        (setq datlst entt))
                    (prin1 datlst ff)              ; write data to file
                    (write-line "" ff)))           ; insert cr-lf
         (setq num (1+ num)))                      ; next entity in ss
  (if ff (close ff))
 (princ))