Author Topic: Read-Line to Attribue Block  (Read 1901 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Read-Line to Attribue Block
« on: June 12, 2017, 08:31:21 PM »
I'm having a brain fart.
Need help reading a text file to the next line...


 
Code: [Select]
;; EN   entity name of insert
;; TAG  attribute tag
;; NEW  new attribute value [string]
;;
;; Replaces current attribute value stored in
;; drawing with the NEW string value.
;;
(defun ARCH:ATTUPDATE  (EN TAG NEW / EL)
  (setq EN (entnext EN)
        ;;skip INSERT
        EL (entget EN)
           ;;get ATTRIB
        )
  ;; Search attribs for match of tag name
  (while (and (= (cdr (assoc 0 EL)) "ATTRIB") (/= (cdr (assoc 2 EL)) TAG))
    (setq EN (entnext EN)
          ;;next ATTRIB
          EL (entget EN)))
  (if (= (cdr (assoc 0 EL)) "ATTRIB")
    (progn (entmod ;;modify entity data
                   (subst ;;substitute in list
                          (cons 1 NEW)
                          ;;new data
                          (assoc 1 EL)
                          ;;old data
                          EL
                          ;;list
                          ))
           (entupd EN)
           ;;force regen of entity
           )))
(defun C:test ()
  ;;(ARCH:LYR "A-SHTT-NAME")
  (setq ARCH:INDX 0)
  (setq readfile (open (strcat (getvar "dwgprefix") "SHT_ClnBlk.txt") "r"))
  (setq line (read-line readfile))

[b];;need help here[/b]

  (command
                       ".insert"
                       (strcat "SHT_ClnBlk" "=" ARCH#CUSF
                               "Builders Plan Service/Syms/Arch_syms/" "SHT_ClnBlk")
                       "0,0"
                       ""
                       ""
                       ""
                       "" "" "" "" "")
  (setq en (cdr (assoc -1 (entget (entlast)))))
  (ARCH:ATTUPDATE en "OWNER" line)
  (ARCH:ATTUPDATE en "SUB" line)
  (ARCH:ATTUPDATE en "LOTBLK" line)
  (ARCH:ATTUPDATE en "ADDRESS" line)
  (ARCH:ATTUPDATE en "CITY" line)
  (close readfile)
  (princ)
)
« Last Edit: June 12, 2017, 09:47:47 PM by GDF »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Read-Line to Attribue Block
« Reply #1 on: June 12, 2017, 09:47:22 PM »
I just hacked this to work...bad lisp

Code: [Select]
(defun C:SHT_ClnBlk (/ en line1 line2 line3 ?line4 line5 readfile)
  (ARCH:LYR "A-SHTT-NAME") 
  (setq readfile (open (strcat (getvar "dwgprefix") "SHT_ClnBlk.txt") "r"))
  (setq line1 (read-line readfile))
  (setq line2 (read-line readfile))
  (setq line3 (read-line readfile))
  (setq line4 (read-line readfile))
  (setq line5 (read-line readfile)) 
  (command
                       ".insert"
                       (strcat "SHT_ClnBlk" "=" ARCH#CUSF
                               "Builders Plan Service/Syms/Arch_syms/" "SHT_ClnBlk")
                       "0,0"
                       ""
                       ""
                       ""
                       "" "" "" "" "")
  (setq en (cdr (assoc -1 (entget (entlast)))))
  (ARCH:ATTUPDATE en "OWNER" line1)
  (ARCH:ATTUPDATE en "SUB" line2)
  (ARCH:ATTUPDATE en "LOTBLK" line3)
  (ARCH:ATTUPDATE en "ADDRESS" line4)
  (ARCH:ATTUPDATE en "CITY" line5)
  (close readfile)
  (princ)
)
;;;
(defun C:SHT_ClnBlkSite (/ en line1 line2 line3 ?line4 line5 readfile) 
  (ARCH:LYR "A-SHTT-NAME")
  (setq readfile (open (strcat (getvar "dwgprefix") "SHT_ClnBlk.txt") "r"))
  (setq line1 (read-line readfile))
  (setq line2 (read-line readfile))
  (setq line3 (read-line readfile))
  (setq line4 (read-line readfile))
  (setq line5 (read-line readfile))
  (command
                       ".insert"
                       (strcat "SHT_ClnBlkSite" "=" ARCH#CUSF
                               "Builders Plan Service/Syms/Arch_syms/" "SHT_ClnBlkSite")
                       "0,0"
                       ""
                       ""
                       ""
                       "" "" "" "" "" "" "" "" "" "")
  (setq en (cdr (assoc -1 (entget (entlast)))))
  (ARCH:ATTUPDATE en "OWNER" line1)
  (ARCH:ATTUPDATE en "OWNER2" line1)
  (ARCH:ATTUPDATE en "SUB" line2)
  (ARCH:ATTUPDATE en "SUB2" line2)
  (ARCH:ATTUPDATE en "LOTBLK" line3)
  (ARCH:ATTUPDATE en "LOTBLK2" line3)
  (ARCH:ATTUPDATE en "ADDRESS" line4)
  (ARCH:ATTUPDATE en "ADDRESS2" line4)
  (ARCH:ATTUPDATE en "CITY" line5)
  (ARCH:ATTUPDATE en "CITY2" line5)
  (princ)
)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Read-Line to Attribue Block
« Reply #2 on: June 13, 2017, 10:43:14 AM »
Maybe something like this?
Code - Auto/Visual Lisp: [Select]
  1. (defun c:sht_clnblk (/ en file)
  2.   (defun _readfile (fn / line of out)
  3.     (cond ((and (eq 'str (type fn)) (setq of (findfile fn)) (setq of (open of "r")))
  4.            (while (setq line (read-line of)) (setq out (cons line out)))
  5.            (close of)
  6.            (reverse out)
  7.           )
  8.     )
  9.   )
  10.   (arch:lyr "A-SHTT-NAME")
  11.   (if (setq file (_readfile (strcat (getvar "dwgprefix") "SHT_ClnBlk.txt")))
  12.     (progn (command
  13.              ".insert"
  14.              (strcat "SHT_ClnBlk" "=" arch#cusf "Builders Plan Service/Syms/Arch_syms/" "SHT_ClnBlk")
  15.              "0,0"
  16.              ""
  17.              ""
  18.              ""
  19.              ""
  20.              ""
  21.              ""
  22.              ""
  23.              ""
  24.            )
  25.            (setq en (cdr (assoc -1 (entget (entlast)))))
  26.            (arch:attupdate en "OWNER" (nth 0 file))
  27.            (arch:attupdate en "SUB" (nth 1 file))
  28.            (arch:attupdate en "LOTBLK" (nth 2 file))
  29.            (arch:attupdate en "ADDRESS" (nth 3 file))
  30.            (arch:attupdate en "CITY" (nth 4 file))
  31.     )
  32.   )
  33.   (princ)
  34. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

GDF

  • Water Moccasin
  • Posts: 2081
Re: Read-Line to Attribue Block
« Reply #3 on: June 13, 2017, 09:34:26 PM »
Thanks Ron
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Read-Line to Attribue Block
« Reply #4 on: June 13, 2017, 11:33:07 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC