Message 1 of 46
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have written this lisp to populate all fields on the title block using data from a text file. The lisp is working, however every field is populated with the same piece of information. I'm not sure where I have gone wrong and would appreciate any advice/direction that you all may have.
Here is the lisp:
(defun C:GVTBIN (/ unit)
(PRINT "IN FTBIN")
(setq unit "1A5")
(GVTB UNIT)
)
(defun GVTB (UNIT / dwgnme homedir desclgth dwglen startpnt dwgnm len_dwgnm)
(setq dwgnme (getvar "DWGNAME"))
(setq homedir (getvar "DWGPREFIX"))
(setq ttlfil (strcat homedir "GVOSStitleblk.txt"))
(print "ttlfil is") (princ ttlfil)
(setq f (open ttlfil "r"))
(PRINT F)
(print "dwgname is ") (print dwgnme)
(print "homedir is ") (print homedir)
(setq len_dwgnm 3) ;; char needed for last digits to get drawing num -- 3 usually
;; 4 when you have an A, B or C in name
(setq desclgth (strlen DWGNME))
(setq dwglen (- desclgth 3)) ; length without .dwg -- 4 digits
(setq startpnt (- dwglen 3)) ; puts you at the start of the number part of drawing name
(setq DWGNM (substr DWGNME startpnt 2)) ;sheet number digits are usually 3
(setq len_unit 8) ; puts you at the start of the number part of drawing name
(setq unit_stpnt (- dwglen (- len_unit 1 ))) ; puts you at the start of the number part of drawing name
;; 12/2009 -- changed file name from the file name to just the last 8 digits with the .dwg extension
(setq UNITNM (strcase (substr DWGNME unit_stpnt len_unit))) ;sheet number digits are usually 3
(setq DWGNM (strcase (substr DWGNME startpnt len_dwgnm))) ;sheet number digits are usually 3
(print "before strip dwgnm") (print DWGNM)
(setq newv (read-line f))
(PRINT newv)
(PRINT F)
(TAGFIND "Job_no" newv)
(setq newv (read-line f))
(TAGFIND "NAME_COMPANY" newv)
(setq newv (read-line f))
(TAGFIND "MAIN_IDENTIFIER" newv)
(setq newv (read-line f))
(TAGFIND "LOC_1" newv)
(setq newv (read-line f))
(TAGFIND "ADDRESS_1" newv)
(setq newv (read-line f))
(TAGFIND "ADDRESS_2" newv)
(setq newv (read-line f))
(TAGFIND "STRUTURE_1" newv)
(setq newv (read-line f))
(TAGFIND "RELEASE_1" newv)
(setq newv (read-line f))
(TAGFIND "RELEASE_2" newv)
(setq newv (read-line f))
(TAGFIND "CREATOR_1" newv)
(setq newv (read-line f))
(TAGFIND "CREATOR_2" newv)
(setq newv (read-line f))
(TAGFIND "CUSTOMER_CODE" newv)
(print "before reading new variables and newv is ")(print newv)
(close f)
)
(defun TAGFIND (tagname newv / tagname ss1 len count bn en el found attstr)
(setq ss1 (ssget "X" '((2 . "Title Block GVOSS"))))
(setq len (sslength ss1))
(setq count 0)
(repeat len
(setq bn (ssname ss1 count)) ; Block Name
(print bn)
(print "")
(setq en (entnext bn)) ; Entity Name
(print en)
(print "")
(setq el (entget en)) ; Entity List
(print el)
(print "")
(while (and (= "ATTRIB" (dxf 0 el))
(/= "SEQEND" (dxf 0 el)))
(if (= (dxf 2 el) (strcat tagname))
(print tagname)
(progn
(print tagname)
(setq attstr (dxf 1 el))
(setq el (subst (cons 1 newv) (assoc 1 el) el))
(entmod el) ; Modify List
(entupd bn) ; Update Screen
(setq found "yes") ; Found Tag?
)
)
(setq en (entnext en)
;(while (and (entnext en) (/= "SEQEND" (dxf 0 el))))
;(print en) ; Add this line to print the entity handle
el (entget en)
)
)
(setq count (1+ count))
)
(if (/= found "yes")
(princ "\nTag Not Found.")
)
)
(defun dxf (code elist)
(cdr (assoc code elist))
)
Thanks in advance for your help and please let me know if there is anything additionally you may need to help diagnose.
Solved! Go to Solution.