 ; Write selected entity data sublists to a file.
 ; Copyright 1994  Rocket software
 ; Surprisingly useful - sort of like a slide hammer.
 (defun C:LOX (/ aa ss fn ff nnn bb follow)
  (write-line "Select entities to file: ")
  (setq ss (ssget))
  (setq assocl ())
  (while (setq num (getint "\nAssociation number or <Return>: "))
         (setq assocl (cons num assocl)))
  (setq assocl (reverse assocl))
  (setq fn (getstring T "Filename or <Return> to write to screen: "))
  (if (= fn "")
      (setq fn ())
      (progn
           (setq ff (open fn "w"))
           (close ff)))
  (setq nnn 0)
  (setq aa (ssname ss nnn))
  (while aa
         (setq bb aa)                             ; save entity name to bb
         (setq aa (entget aa))                    ; get entity data
         (setq orig aa)                           ; copy of aa to work from
         (setq aa ())                             ; empty aa
         (setq len (1- (length assocl)))
         (while (>= len 0)
                (setq numaso (nth len assocl))
                (Setq subb (assoc numaso orig))
                (if (null subb) (setq subb (list numaso ())))
                (Setq aa (cons subb aa))
                (setq len (1- len)))
         (if (and fn (setq ff (open fn "a")))     ; if filename & can be opened
             (progn
                  (if follow (princ "  " ff))     ; indent subentities
                  (prin1 aa ff)                   ; then write data to file
                  (write-line "" ff)              ; insert cr-lf
                  (close ff))                     ; and close it.
             (print aa))                          ; else write data to screen.
         (if (= (cdr (assoc 66 (entget bb))) 1)   ; if entities follow
                  (setq follow T))                ; set flag.
         (if (= (cdr (assoc 0 (entget bb))) "SEQEND") ; if end of ent
             (setq follow ()))                    ; clear flag.
         (if follow                               ; if flag set
             (setq aa (entnext bb))               ;   get next entity
             (progn                               ; if flag not set
                  (setq nnn (1+ nnn))             ;   increment counter
                  (setq aa (ssname ss nnn)))))    ;   and get next entity.
  (princ))