Lisp to Populate Title Block is populating the same value in all fields

Lisp to Populate Title Block is populating the same value in all fields

raceharder
Enthusiast Enthusiast
3,587 Views
45 Replies
Message 1 of 46

Lisp to Populate Title Block is populating the same value in all fields

raceharder
Enthusiast
Enthusiast

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.
0 Likes
Accepted solutions (2)
3,588 Views
45 Replies
Replies (45)
Message 41 of 46

raceharder
Enthusiast
Enthusiast

I got ya.  So let me ask you this.......is there a limit to the number of title block names that I can have in this line of code:

(if(setq ss1 (ssget "x" '((2 . "Title Block GVOSS,FRAME") (66 . 1))))(setq sclx(cdr(assoc 41(entget(ssname ss1 0))))scly(cdr(assoc 42(entget(ssname ss1 0))))))


There are over 1500 sheets in these drawing sets and I have not opened each individual sheet and checked the name of the title blocks so I may in fact end up with more than the 4 I currently have.

0 Likes
Message 42 of 46

paullimapa
Mentor
Mentor

You should be able to enter many block names separated by a comma. The limit in this case may be the total character length AutoCAD can read in a single line. So just keep adding to it til it fails. Then we can always design code to accomplish the same


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 43 of 46

raceharder
Enthusiast
Enthusiast

I apologize.  It is not actually the scale that is off.  It is the unit of measurement I believe.  It seems some were done in inches while others were done in millimeters.  At least that is what I believe the problem to be.  I looked at the x and y scale in the properties for each block, and they are set to 1 in both Title Block GVOSS and FRAME.

0 Likes
Message 44 of 46

paullimapa
Mentor
Mentor

In this case then it may be easier to deal with assuming all the drawings you receive are supposed to be drawn using the same units of measurement.

If you're always drawing in inches which I assume your title block is then include in your script at the top these lines:

INSUNITS
1

If in millimeters then:

INSUNITS
4

This sets the current drawings measurement units to match with your title block so when it's inserted AutoCAD scales it accordingly.

You can see this setting visually under the UNITS command:

paullimapa_0-1715799008055.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 45 of 46

raceharder
Enthusiast
Enthusiast

The measurement variable is set to 1 in the 8A_C000_1 Title and Reference Page.dwg.  the measurement variable is set to 0 in TitleBlockGVOSS.dwg.

 

I don't know......I guess I am grabbing at straws.

 

Going to be real honest.....  I am having some health issues today and I don't believe I am thinking straight.  I'm sorry if I am not giving you good information today.

0 Likes
Message 46 of 46

paullimapa
Mentor
Mentor

The key is that in your new title block you need to have the proper insunits setting.

So if that's in inches then just make sure your new title block has that setting.

But then you'll have to manually open the other drawings and do a measurement of a familiar geometry to confirm what the drawing units ought to be. Then set the insunits accordingly.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes