PDA

View Full Version : Title Block attribute change


jerry.smirl
2008-03-19, 07:22 PM
I am wondering as to if anyone knows if there is a lisp routine or other way to batch change the name of dwgs from an excel spreadsheet. In one column old string and the other new string. Can it change the 3rd attribute of a title block reading from the old string and changing it to the new string value?

ccowgill
2008-03-20, 01:36 PM
I am wondering as to if anyone knows if there is a lisp routine or other way to batch change the name of dwgs from an excel spreadsheet. In one column old string and the other new string. Can it change the 3rd attribute of a title block reading from the old string and changing it to the new string value?
it is possible to do it, and it is relatively simple, I dont have the time right now to write it, but maybe someone else can help you. what you need to do is read each line of the excel file to a list, then read each item in that list using the vl-file-rename function, you can tell it to rename a file called the first string, to the second string. you can use vl-filename-directory to select the directory path to look in and getfiled to select the excel file. look here (http://forums.augi.com/showthread.php?t=29605&highlight=dwgprops)for a way to read each line in a tab delimited excel file

jerry.smirl
2008-03-20, 11:18 PM
Can someone explain this routine to me:

(defun chgdwg (csv_file / ss_tblk lst_tblk
en_tblk file_tblk str_record lst_record
str_old str_new
)
;(setq csv_file (strcat (getvar "dwgprefix") "continuations.csv"))
(setq
ss_tblk
(ssget "X" '((0 . "INSERT") (2 . "SUG Border")))
)
(if ss_tblk
(progn
(setq file_tblk (open csv_file "r"))
(setq str_record (read-line file_tblk))
(while str_record
(setq lst_record
(append lst_record
(list (strparse str_record ","))
)
)
(setq str_record (read-line file_tblk))

)

(close file_tblk)

(setq lst_tblk (sel2lst ss_tblk))
(foreach en_tblk lst_tblk
(setq
str_old (getval 1 (setq en_att (nth 2 (att2lst en_tblk))))
)
(setq str_new (getval (strcat (substr str_old 1 4)
" "
(substr str_old 5 4)
)
lst_record
)
)
(if str_new
(progn
(setval 1
(strcat (strchg (nth 0 str_new) " " "") ".dwg")
en_att
)
(setval 1
(nth 1 (strparse (nth 0 str_new) " "))
(nth 5 (att2lst en_tblk))
)
(command "saveas"
""
(strcat (getvar "dwgprefix")
"New\\"
(strchg (nth 0 str_new) " " "")
".dwg"
)
)
)
)

)

This is part of a lisp routine that we have and It will not change the attribute in our title block. Nor does it saves as into the "New" Folder.

Moderator Note:
Please use [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code)

ccowgill
2008-03-21, 02:14 PM
you are missing quite abit of code to be able to determine what it is you are trying to do, what are the functions sel2lst, getval, att2lst, strchg, strparse? you are missing an entupd and entmod to get the changes to show up. I use this to change attributes

(setq counter 1
ss
(ssget
"_X"
(list
'(-4 . "<and")
(cons 410 (getvar "ctab"))
'(0 . "insert")
'(2
.
"TBL12,TBL13,TBL14,TBL15,TBL14TEXTWRAP,WJITBLK24x36"
)
(cons 10 '(0 0 0))
'(-4 . "and>")
) ;end list
) ;_ end of ssget
) ;_ end of setq
(if (/= ss nil)
(progn
(foreach itm2 lst
(setq Ent (ssname ss 0)
EntData (entget Ent)
) ;_ end of setq
(if
(not
(foreach Att (vlax-invoke
(vlax-ename->vla-object Ent)
'GetAttributes
) ;_ end of vlax-invoke
(if (= (vla-get-TagString Att)
"SHEETDESCRIPTIONLINE1"
) ;_ end of =
(setq tmpList
(cons Att (vla-get-TextString Att))
) ;_ end of setq
) ;_ end of if
) ;end foreach
) ;END NOT

(vla-put-TextString (car tmpList) (nth 0 itm2))

(vla-Update (car tmpList))
) ;end if
(if
(not
(foreach Att (vlax-invoke
(vlax-ename->vla-object Ent)
'GetAttributes
) ;_ end of vlax-invoke
(if (= (vla-get-TagString Att)
"SHEETDESCRIPTIONLINE2"
) ;_ end of =
(setq tmpList
(cons Att (vla-get-TextString Att))

) ;_ end of setq
) ;_ end of if
) ;end foreach
) ;END NOT

(vla-put-TextString (car tmpList) (nth 1 itm2))

(vla-Update (car tmpList))
) ;end if
; ) ;end progn
; ) ;end if
) ;end foreach
) ;_ end of progn
) ;_ end of if
:

jerry.smirl
2008-03-21, 02:52 PM
Here is the whole lisp file:

(defun isinstr (ssub sall / lsub lall i n ret)
;; the best LISP version (??)
(setq lall (strlen sall)
lsub (strlen ssub)
) ;_ end of setq
(cond ((> lsub lall) nil)
((< lsub lall)
(setq i 1
n (1+ (- lall lsub))
) ;_ end of setq
(while (and (not ret) (<= i n))
(if (= ssub (substr sall i lsub))
(setq ret i)
(setq i (1+ i))
) ;_ end of if
) ;_ end of while
ret
)
(t
(if (= ssub sall)
1
) ;_ end of if
)
) ;_ end of cond
)
(defun entity (ele) ;convert to element name
(cond ;accepts the following types:
((= (type ele) 'ename) ele) ; ENAME
((not (listp ele)) nil) ; error: no list
((= (type (car ele)) 'ename) (car ele)) ; entsel-list
((cdr (assoc -1 ele))) ; entget-list or nil
) ;_ end of cond
) ;_ end of defun

(defun getval (grp ele)
(if ele
(cdr (assoc grp
(if (listp ele)
ele
(entget (entity ele))
)
)
)
nil
)
)

(defun setval (grp val ele)
(entmod
(if (null (assoc grp (entget (entity ele))))
; if group doesn't exist
(reverse
(cons (cons grp val) (reverse (entget (entity ele))))
)
; make it,
(subst (cons grp val) ; otherwise
(assoc grp (entget (entity ele))) ; replace it
(entget (entity ele))
) ;_ end of subst
) ;_ end of if
) ;_ end of entmod
;;(entupd (entity ele)) ;_ normaly should be disabled
)

(defun sel2lst (ss / n lst)
(if (= 'pickset (type ss))
(repeat (setq n (fix (sslength ss)))
(setq n (1- n)
lst (cons (ssname ss n) lst)
) ;_ end of setq
) ;_ end of repeat
) ;_ end of if
)

(defun strparse (strng chs / len c l s chsl cnt)
;;delim==one-of-chs.
(setq chsl (strtol chs))
(setq len (strlen strng)
s ""
cnt (1+ len)
) ;_ end of setq
(while (> (setq cnt (1- cnt)) 0)
(setq c (substr strng cnt 1))
(if (member c chsl)
(if (/= cnt len)
;; "1,2," -> ("1" "2") and not ("1" "2" "")
(setq l (cons s l)
s ""
) ;_ end of setq
) ;_ end of if
(setq s (strcat c s))
) ;_ end of if
) ;_ end of while
(cons s l)
;; ",1,2" -> ("" "1" "2")
)

(defun att2lst (enblk / en lst)
(setq en (entnext enblk))
;(while (istypep en '("ATTRIB" "VERTEX"))
(while (istypep en '("ATTRIB"))
(setq lst (cons en lst))
(setq en (entnext en))
) ;_ end of while
(reverse lst)
)

(defun gettyp (ele) ;return type
(getval 0 ele)
) ;_ end of defun

;;; Ex: (istypep ele '("TEXT" "ATTDEF"))
;;; is element a "TEXT" or a "ATTDEF"?
(defun istypep (ele typ) ; better implementation to accept
; lists
; too
(cond ((listp typ) (member (gettyp ele) typ))
((stringp typ) (= (gettyp ele) typ)) ;assume typ uppercase
(t nil)
) ;_ end of cond
)

(defun stringp (s) (= (type s) 'str))

(defun strchg (s old new / i ls lold)
(setq lold (strlen old) ; length of substr to search
ls (1+ (- (strlen s) lold)) ; max. position to search to
i 1
)
(while (<= i ls)
(if (= (substr s i lold) old) ; found
(setq s (strcat (if (> i 1)
(substr s 1 (1- i))
""
)
new
(if (<= i ls)
(substr s (+ i lold))
""
)
)
i (+ i (strlen new))
) ; next position to search
(setq i (1+ i))
)
)
s
)

(defun chgdwg (csv_file / ss_tblk lst_tblk
en_tblk file_tblk str_record lst_record
str_old str_new
)
;(setq csv_file (strcat (getvar "dwgprefix") "continuations.csv"))
(setq
ss_tblk
(ssget "X" '((0 . "INSERT") (2 . "SUG Border")))
)
(if ss_tblk
(progn
(setq file_tblk (open csv_file "r"))
(setq str_record (read-line file_tblk))
(while str_record
(setq lst_record
(append lst_record
(list (strparse str_record ","))
)
)
(setq str_record (read-line file_tblk))

)

(close file_tblk)

(setq lst_tblk (sel2lst ss_tblk))
(foreach en_tblk lst_tblk
(setq
str_old (getval 1 (setq en_att (nth 2 (att2lst en_tblk))))
)
(setq str_new (getval (strcat (substr str_old 1 4)
" "
(substr str_old 5 4)
)
lst_record
)
)
(if str_new
(progn
(setval 1
(strcat (strchg (nth 0 str_new) " " "") ".dwg")
en_att
)
(setval 1
(nth 1 (strparse (nth 0 str_new) " "))
(nth 5 (att2lst en_tblk))
)
(command "saveas"
""
(strcat (getvar "dwgprefix")
"New\\"
(strchg (nth 0 str_new) " " "")
".dwg"
)
)
)
)

)


(setq
ss_note
(ssget "X" '((0 . "INSERT") (2 . "SU_SYMBOL_NOTE_TTLBLK")))
)

(if ss_note
(progn
(setq lst_note (sel2lst ss_note))
(foreach en_note lst_note
(setq lst_atts_note (att2lst en_note))
(if lst_atts_note
(progn
(foreach en_note_att lst_atts_note
(setq str_old (getval 1 en_note_att))
(foreach old_new lst_record
(if
(isinstr (nth 0 old_new) str_old)
(setval 1
(strchg str_old
(nth 0 old_new)
(nth 1 old_new)
)
en_note_att
)
)
)
)
)
)
)
)
)
)
)
)

The attribute that I am trying to change is the second attribute, and the naming convention in this attribute is "XXX-XXX-XXX" all one string. But in previous borders the nameing convention was "0000" as the 3rd attribute and "0000" as the 5th attribute to be changed. And also the naming of the dwg was different. Currently it is "XXX-XXX-XXX" and previously we used "XXXX-XX-XXXX-X-XX". Where in this lisp can I modify to fit the new name and "nth" location of the attribute, or am I missing something?

Moderator Note:
Please use [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code)

ccowgill
2008-03-21, 07:00 PM
Ok, now that I am totally confused (not hard to do) If I understand you correctly, you want to be able to change the name of a drawing based on 2 columns in an excel file, the first column being the old drawing name, the second being the new drawing name. then you want to change the value of a titleblock attribute to reflect the new drawing name?????
Is it feasible to redo your titleblock using a field linked to the name of the drawing in that location? The way we do our title block is with a mix of attributes and regular text. we only have a couple of attributes that have the ability to be filled in from our titleblock program, for the rest of the text, the program either uses a field or uses the coordinates of the text within the title block to change the text

jerry.smirl
2008-03-21, 09:06 PM
It is not at all feasible to change the title block, it is a client's title block. And yes we want to change an attribute based on 2 columns in an excel file. We were able to use this on a title block similar to this. And it would saveas "new" string value in a folder called "New". But somewhere I am missing something in this lisp.

abdulhuck
2008-03-23, 12:57 PM
It is not at all feasible to change the title block, it is a client's title block. And yes we want to change an attribute based on 2 columns in an excel file. We were able to use this on a title block similar to this. And it would saveas "new" string value in a folder called "New". But somewhere I am missing something in this lisp.

Can you post the excel file and the attribute tag name? I feel that a simple script can do this.

Required information:

1. The folder name of current drawings
2. Folder name for renamed drawing files
3. Excel file with old and new file names.
4. The attribute tag to be changed with new dwg no.
5. The block name.

Regards
Abdul Huck

jerry.smirl
2008-03-24, 05:22 PM
1. The folder name of current drawings: Final Issue For QAQC

2. Folder name for renamed drawing files: New

3. Excel file with old and new file names: The file that we use is a csv and not a xls

4. The attribute tag to be changed with new dwg no.: DRAWING_NUMBER and the other is DWG also "1." "2." "NOTE"

5. The block name. SU_SYMBOL_NOTE_TTBLK, SU_LINK and SUG Border

I really appreciate this very much. Thank you for the direction.