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,617 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,618 Views
45 Replies
Replies (45)
Message 21 of 46

paullimapa
Mentor
Mentor

You can continue to repeat the lines as I showed before when you have different tag names. It'll still work.

But if you want to differentiate using code then for example do this:

  (setq blknam "GVOSS")

  (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))
(if (tblsearch "BLOCK" blknam)
  (TAGFIND "LOC_1" newv)
  (TAGFIND "Location" 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))
(if (tblsearch "BLOCK" blknam)
  (TAGFIND "C_1" newv)
  (TAGFIND "CUSTOMER_CODE" newv)
)

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

raceharder
Enthusiast
Enthusiast

@paullimapa My problem is more with the lisp I created to pull the data out of the drawing that we manually update.  To review, We open the 1st drawing in the drawing set and manually update the appropriate fields.  We then run the lisp "FD_GV_TB_OUT" to pull the data from the necessary fields and save them to a text file.  We can then use the "FD_GV_TB_IN" lisp to grab the data from the text file and populate the appropriate field on the rest of the sheets in the drawing set.  Since there could be different blocks on the sheet and the fields in those blocks have different names, the field names that we will be looking for will be dependent upon which block is on the page.

 

I hope that makes sense.

 

Here is a copy of the FD_GV_TB_OUT lisp:

;; This code writes out all the
;; tag values that we want repeated
;; through the drawing package to
;; a file called titleblk.txt in the home directory
;; of the drawing
;; I would fix sheet 1, run Ford_TB_Out,
;; then run Ford_TB_In  to get the rest of the
;; attributes for file_name and sheet number set

(defun C:GVO ( / dwgnme homedir desclgth dwglen startpnt dwgnm)
;(print "you are in K: ftbout")

        (setq dwgnme (getvar "DWGNAME"))
    (setq homedir (getvar "DWGPREFIX"))
        (setq ttlfil (strcat homedir "\\GVOSStitleblk.txt")
        ttlfil (open ttlfil "w")
    )

    ; These are the tags that we want
    ; variables copied to each drawing the in package
    ;(print "before TAGSOUT")
    ;(print "before TAGSOUT")
  (TAGSOUT "JOB_NO")
  (TAGSOUT "NAME_COMPANY")
  (TAGSOUT "MAIN_IDENTIFIER")
  ;(TAGSOUT "MOUNTING")
  ;(TAGSOUT "PAGE_PROP")
  ;(TAGSOUT "COLOMN")
  ;(TAGSOUT "DRAWING_NO")
  ;(TAGSOUT "COLOMN_1")
  ;(TAGSOUT "COLOMN_2")
  ;(TAGSOUT "COLOMN_3")
  ;(TAGSOUT "COLOMN_4")
  ;(TAGSOUT "COLOMN_5")
  ;(TAGSOUT "COLOMN_6")
  ;(TAGSOUT "PAGE_TOTAL")
  ;(TAGSOUT "NEXT")
  ;(TAGSOUT "COLOMN_7")
  (TAGSOUT "LOC_1,LOCATION")
  ;(TAGSOUT "PAGE_NO")
  ;(TAGSOUT "COLOMN_8")
  ;(TAGSOUT "COLOMN_9")
  ;(TAGSOUT "PAGE_INFO")
  ;(TAGSOUT "PAGE_COUNTER")
  (TAGSOUT "ADDRESS_1")
  (TAGSOUT "ADDRESS_2")
  ;(TAGSOUT "PLANT_2")
  (TAGSOUT "C_1")
  (TAGSOUT "STRUTURE_1")
  ;(TAGSOUT "SPECIAL_REMARKS")
  ;(TAGSOUT "DESCRIPTION_1")
  ;(TAGSOUT "APP_BY")
  (TAGSOUT "RELEASE_1")
  (TAGSOUT "RELEASE_2")
  (TAGSOUT "CREATOR_1")
  (TAGSOUT "CREATOR_2")
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (close ttlfil)


) ; end FTBout




;;
;;Finds Tag Values, All Blocks
;;===========================================================
(defun TAGSOUT (tagname / newv ss1 len count bn en el found attstr)
;=================create selection set=======================
(print "at top of TAGSOUT tagname is ") (print tagname)
  (setq ss1 (ssget "x" '((2 . "Title Block GVOSS,FRAME") (66 . 1)))
  ;(setq ss1 (ssget "x" '((2 . "Title Block GVOSS")))
         len (sslength ss1)
         count 0
    )
 (print "len is ")(princ len)
  (PRINT SS1)

   (repeat len
        ;(print "in repeat len")
        (setq bn (ssname ss1 count)             ;Block Name
              en (entnext bn)                   ;Entity Name
              el (entget en))                   ;Entity List


;=================loop thru block entities===================

      (while(and (= "ATTRIB" (dxf 0 el)) (/= "SEQEND" (dxf 0 el)))
       
        ;(print "(dxf 2 el) before if is ")(print (dxf 2 el))
        (if (= (strcase (dxf 2 el)) (strcat tagname))
            (progn

            ;(print "(dxf 2 el) is ")(print (dxf 2 el))
            (setq attstr (dxf 1 el))
            ;(print "(dxf 1 el) is ")(print (dxf 1 el))
         (print "attstr is ")(print attstr)

            (write-line attstr ttlfil)
    ;(setq el (subst (cons 1 newv) (assoc 1 el) el))

            ;(entmod el)                    ;Modify List
            ;(entupd bn)                    ;Update Screen
            (setq found "yes")             ;Found Tag?
            );progn
        ) ;if
         
        (setq en (entnext en) el (entget en))
      );while
      (setq count (1+ count))
    ;(print "before repeat")
      ) ;repeat
 (if (/= found "yes")
     (princ "\nTag Not Found.")
 )

  (princ "at end of TAGSOUT")
);defun TAGSOUTout.lsp







;======================dxf function==========================
(defun dxf (code elist)
      (cdr (assoc code elist))
);dxf
(princ)
;============================================================
0 Likes
Message 23 of 46

paullimapa
Mentor
Mentor

Similar to what I posted with GVTBIN the GVTBOUT can contain the same tblsearch function check for the found block name to TAGSOUT the designated tagname.

But these are the corrections I made to your code to make it work:

1. no need to add "\\" before txt file since homedir already has "\\" at end:

;                (strcat homedir "\\GVOSStitleblk.txt")
    (setq ttlfil (strcat homedir "GVOSStitleblk.txt") 

2. you need to include strcase not strcat for tagname:

;              (= (strcase (dxf 2 el)) (strcat tagname))        
        (if (= (strcase (dxf 2 el)) (strcase tagname))

3. added name of block to find/match before calls to TAGSOUT:

    (setq blknam "Title Block GVOSS")
    ; These are the tags that we want
    ; variables copied to each drawing the in package
    ;(print "before TAGSOUT")

4. if statements to search for corresponding tagname:

(if (tblsearch "BLOCK" blknam)
  (TAGSOUT "LOC_1")
  (TAGSOUT "LOCATION")
)
  ;(TAGSOUT "PAGE_NO")
  ;(TAGSOUT "COLOMN_8")
  ;(TAGSOUT "COLOMN_9")
  ;(TAGSOUT "PAGE_INFO")
  ;(TAGSOUT "PAGE_COUNTER")
  (TAGSOUT "ADDRESS_1")
  (TAGSOUT "ADDRESS_2")
  ;(TAGSOUT "PLANT_2")
  (TAGSOUT "C_1")
  (TAGSOUT "STRUTURE_1")
  ;(TAGSOUT "SPECIAL_REMARKS")
  ;(TAGSOUT "DESCRIPTION_1")
  ;(TAGSOUT "APP_BY")
  (TAGSOUT "RELEASE_1")
  (TAGSOUT "RELEASE_2")
  (TAGSOUT "CREATOR_1")
  (TAGSOUT "CREATOR_2")
(if (tblsearch "BLOCK" blknam)
  (TAGSOUT "C_1")
  (TAGSOUT "CUSTOMER_CODE")
)  

and then the typical reshuffling of functions so they're all included in main.

 

 


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

raceharder
Enthusiast
Enthusiast

Thank you.  Exactly what I needed as usual.  😁

0 Likes
Message 25 of 46

paullimapa
Mentor
Mentor

Glad to have helped…cheers!!!


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

raceharder
Enthusiast
Enthusiast

I am having some issues still with this process.  When I run the GVTBIN, it just gives me "Tag not found".  I have tried to troubleshoot to no avail.  Any assistance would be appreciated.  Sorry to bother again.  Here is the current code:

(defun C:GVI ()
; localize functions and variables            
 
 
  (setq dwgnme (getvar "DWGNAME"))
  (setq homedir (getvar "DWGPREFIX"))
  (setq ttlfil (strcat homedir "GVOSStitleblk.txt"))
  (print "ttlfil is") (princ ttlfil)
  (setq f (open ttlfil "r"))
  (setq blknam "Title Block GVOSS")
  (print "BEFORE IF")
  (if (tblsearch "BLOCK" blknam)
    (TBGV)
    (FRAME)
   )
)  
(defun GVTB
; localize functions and variables alphabetically            
  ( / desclgth dwglen dwgnm dwgnme dxf f homedir len_dwgnm len_unit
   newv startpnt TAGFIND ttlfil unit_stpnt UNITNM
  )
(defun dxf (code elist)
  (cdr (assoc code elist))
) ; defun dxf
(defun TAGFIND (tagname newv / ss1 len count bn en el found attstr)
;  (setq ss1 (ssget "X" '((2 . "Title Block GVOSS"))))
  ;(setq ss1 (ssget "X" '((2 . "GVOSSTITLEBLOCK"))))  ; title block name
  (setq ss1 (ssget "X" '((2 . "Title Block GVOSS,FRAME,GVOSSTITLEBLOCK"))))  ; title block name
  (setq len (sslength ss1))
  (setq count 0)

  (repeat len
    (setq bn (ssname ss1 count)) ; Block entity Name
       (print bn)
    (print "")
    (setq en (entnext bn)) ; Entity Name of attribute
    (print en)
    (print "")
   
    (setq el (entget en)) ; Entity List of first attribute
       (print el)
    (print "")

    (while (and (= "ATTRIB" (dxf 0 el))
                (/= "SEQEND" (dxf 0 el)))
      (if (= (strcase (dxf 2 el)) (strcase tagname)) ; convert everything to uppercase to perform proper match
        ; (= (dxf 2 el) (strcat tagname))
;        (print tagname) ; this should not be here when there's a match
          (progn ; then do the following when there's a match
            (print tagname)
            (setq attstr (dxf 1 el)) ; no need to get current attribute value
            (setq el (subst (cons 1 newv) (assoc 1 el) el))
            (entmod el) ; Modify List
            (entupd bn) ; Update Screen
            (setq found "yes") ; Found Tag?
          )
        (print tagname) ; this should be placed here if you want to see when no match
      )

      (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 TAGFIND
)
  ;(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)
(defun TBGV ()
  (GVTB)
  (print "AFTER IF 1")
  (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 "C_1" 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 "LOCATION" newv)

  (print "before reading new variables and newv is ")(print newv)

  (close f)
)  
(defun FRAME ()
  (GVTB)
  (print "AFTER IF 2")
  (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 "LOCATION" 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 "CUSTOMER_CODE" 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)

  (print "before reading new variables and newv is ")(print newv)

  (close f)
)  
0 Likes
Message 27 of 46

paullimapa
Mentor
Mentor

Could you also share the dwg when you got this error


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

raceharder
Enthusiast
Enthusiast

Here ya go. 

0 Likes
Message 29 of 46

paullimapa
Mentor
Mentor

and the txt file if that changed?


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

raceharder
Enthusiast
Enthusiast

I don't believe it has changed and I am not near my counter at the moment.  I will attach a new copy of the text file in about 20 minutes.  Sorry for the delay. 

0 Likes
Message 31 of 46

raceharder
Enthusiast
Enthusiast

Here is the latest text file.

0 Likes
Message 32 of 46

paullimapa
Mentor
Mentor
Accepted solution

So the problem is that you are localizing functions/variables when you should not and then not localizing functions/variables when & where they should be localized.

Again like before I've moved your code around so that they're at least localizing functions/variables where they should go which in this case should be under the main command function GVI.

I also purposefully renamed the sub functions so they're all prefixed with "sub_"

This way you can clearly see what they are and not accidentally get them mixed up with the variable names.

If sub functions are shared/used by other sub functions you should only localize this at the main command level. This way the sub functions like dxf, frame, TAGFIND & TBFV cab be found & executed.

By the way I moved the code around you also no longer need GVTB sub function.

So for example the sub functions are all moved directly under defun C:GVTB:

 

(defun C:GVI 
; localize functions and variables            
 (/ blknam dwgnme f homedir ttlfil 
    sub_dxf sub_FRAME sub_TAGFIND sub_TBGV
 )
; other commented out variables:
; desclgth dwglen DWGNM len_dwgnm len_unit startpnt unit_stpnt UNITNM
; sub_dxf
(defun sub_dxf (code elist)
  (cdr (assoc code elist))
) ; defun sub_dxf
;  
; sub_FRAME
(defun sub_FRAME 
....
) ; defun sub_FRAME
;
(defun sub_TAGFIND 
.....
) ; defun sub_TAGFIND
;
; sub_TBGV
(defun sub_TBGV
.....
)  ; defun sub_TBGV

 

So if you load other code that also happened to have these same sub function names they won't be used in your GVI.lsp because it'll only use what's localized within this code.

I also don't think you need to run a separate code just to accommodate the different title block name like this:

 

  (if (tblsearch "BLOCK" blknam)
    (sub_TBGV)
    (sub_FRAME)
  )

 

This should only be done when the Attribute Tag names are very different. In your case, they're not. There's no reason to have two very similar functions searching through similar Tag names. The problem is when you have to modify one of the functions, you'll have to repeat the same modifications on the other function. So it's a better call to actually just run one of the sub functions like in the previous code I posted which then checks for that title block name first when there are different Tag names:

 

(if (tblsearch "BLOCK" blknam)
  (sub_TAGFIND "LOC_1" newv)
  (sub_TAGFIND "Location" newv)
)
; or
(if (tblsearch "BLOCK" blknam)
  (sub_TAGFIND "C_1" newv)
  (sub_TAGFIND "CUSTOMER_CODE" newv)
)

 

Also I'd place the open file read statement inside each of the sub functions since you're closing the file within those functions:

 

; sub_FRAME
(defun sub_FRAME 
; localize functions and variables            
  (/ newv)
;  (GVTB) ; no need for this
; add open file statement here
  (setq f (open ttlfil "r"))  
...
  (close f)
)  ; defun sub_FRAME
; sub_TBGV
(defun sub_TBGV
; localize functions and variables            
 (/ newv)
;  (GVTB) ; no need for this
; add open file statement here
  (setq f (open ttlfil "r"))
....
  (close f)
)  ; defun sub_TBGV

 

If you want to really get technical you may even want to pass the name of the text file as an argument into the sub function and then deal with it there.


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

raceharder
Enthusiast
Enthusiast

Once again, I appreciate the help and schooling. 

 

Correct me if I am wrong but it appears to me that most of my issues are with the structure of the code.  I am doing this all with no training in programming in this language (Most of my programming experience is in Ladder Logic and languages so old they are no longer in use, LOL.  Hence the need for me to learn more so that I don't end up not in use like one of those languages).  Can you direct me to a resource I could use to learn more about proper structuring of the code? 

 

Thank you again for all your help and advice.

0 Likes
Message 34 of 46

paullimapa
Mentor
Mentor

Having another programming language as a background is really helpful. You can pick up learning more on Autolisp here


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

raceharder
Enthusiast
Enthusiast

Thank you very much, sir.  

0 Likes
Message 36 of 46

paullimapa
Mentor
Mentor

Once again glad to have helped…cheers!!!


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

raceharder
Enthusiast
Enthusiast

This process I have been working on is to update title blocks in a drawing package.  The further I get into the customer provided drawing set, I am finding that there are now 3 different title blocks throughout.  Unfortunately 2 of the blocks have the same name but different attribute names.  This has created trouble with the lisps that we have been working on.

 

For example, there are 2 blocks with the name Title Block GVOSS.  There is one attribute that has a different name between the 2 iterations of Title Block GVOSS.  One is called Plant_Location and the other is called Struture_1.

 

I am trying to determine the best way to address this.  My thought was to create a script that deletes the existing title block from the page and then inserts a new title block.  I could then run this on the entire drawing set and all drawings would then have the same title block.  I wrote the script and it does work, however I am finding that many of the drawings are at different scales, so when I am inserting the new block, it is coming in either way too small or way to big.  I am unsure how to address this.

 

Any suggestions you may have would be greatly appreciated.  If there is additional info that you need from me, please just ask and I will do my best to provide you with whatever you request.

 

Thanks again for your help.

0 Likes
Message 38 of 46

paullimapa
Mentor
Mentor

In the code you run to replace the title block you should be also able to retrieve the scale currently used to apply to the replacement title block. Perhaps you can share that code here for everyone to take a look at ?


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

raceharder
Enthusiast
Enthusiast

I just wrote a quick script to grab the title block that is on the page and delete it, then purge all unused blocks followed by inserting the new title block called TitleBlockGVOSS.  I force this all on the command line.  I cannot upload a .scr to this site so here is the script as written:

 

ERASE
1,1
-1,-1

PURGE
B
all
N
-INSERT
TitleBlockGVOSS
0,0
1
1
0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

zoom
extents

 

I have also attached a copy of the new title block (TitleBlockGVOSS) just in case you need that.  Thank you again for your help.  

0 Likes
Message 40 of 46

paullimapa
Mentor
Mentor

Assuming you know the name of the title block you can include the name in this line of code at the top of the script:

(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))))))

Where you include the title block name here separating by commas: "Title Block GVOSS,FRAME"

This will save the block's x scale into variable sclx & y scale into variable scly

Then in your script where you indicate x scale & y scale use these instead like this:

-INSERT
TitleBlockGVOSS
0,0
!sclx
!scly
0

The ! exclamation mark before the variable name tells AutoCAD to use those variables.


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