Jump to content
gmmdinesh

Title Block Update Automatically

Recommended Posts

gmmdinesh

Hi Everyone

I Have a Bulk of DWG files which needs to fill up the Title Block, each drawing file having Multiple layouts, all the title Block need to fill same details, and i have a text file for that. I need to update the title block Automatically.

When i run the Command it will automatically get the detail from that text file (without open the dialog box for user selection) and update the Title Block. Text file saved on Specific path.

 

Anyone Have an Idea Please Help Me.

 

Thanks in Advance.

Share this post


Link to post
Share on other sites
gmmdinesh

Hi RLX

I have already tried that lee-mac Lisp, when i run that lisp its opening the dialog box for select the csv file. and also it was working with CSV file, but i have a Text file only.

 

Could you please help me, how to fill automatically using text file.

 

Thanks

Share this post


Link to post
Share on other sites
rlx
Hi RLX

I have already tried that lee-mac Lisp, when i run that lisp its opening the dialog box for select the csv file. and also it was working with CSV file, but i have a Text file only.

 

Could you please help me, how to fill automatically using text file.

 

Thanks

 

 

don't have much time but post example dwg & txt and will try to have a look at it. Or maybe just convert your txt file to a csv file?

Share this post


Link to post
Share on other sites
BIGAL

some examples

 

line1

line2

line3

 

 

line1,line2,line3

 

line1 line2 line3 = line1,line2,line3

 

Did you look at sample.zip in "Lee-mac" use notepad or excel to open sample csv.

Share this post


Link to post
Share on other sites
rlx
Posted (edited)

quick , dirty & barely tested (txt -> csv)

test.txt

TXT_to_CSV.lsp

TEST2.txt

Edited by rlx
fixed little reverse bug

Share this post


Link to post
Share on other sites
gmmdinesh

Please look at the Sample files.

 

Sample.dwg

Att.txt

 

Thanks

Share this post


Link to post
Share on other sites
rlx

converting txt file could be as simple as :

 

 

(defun c:t2 ( / fn-in fp-in fn-out fp-out inp)
 (defun _ct (s)
   (while (vl-string-position (ascii "\t") s)(setq s (vl-string-subst "," "\t" s))) s)

 (and (setq fn-in (getfiled "Filename to convert" "" "txt" 0))
      (setq fp-in (open fn-in "r"))       
      (setq fn-out (strcat (vl-filename-directory fn-in) "/"
                           (vl-filename-base fn-in) ".csv"))
      (setq fp-out (open fn-out "w"))
      (while (setq inp (read-line fp-in)) (write-line (_ct inp) fp-out)))
 (if fp-in (close fp-in))(if fp-out (close fp-out)) (gc)
 (princ)
)

Share this post


Link to post
Share on other sites
gmmdinesh

Hey Rlx,

Thanks for your Code, But I dont want to convert the text file to CSV.

If I have A CSV file, Can i Update my title Block without opening the Dialog Box?

 

Thanks

Share this post


Link to post
Share on other sites
rlx
Hey Rlx,

Thanks for your Code, But I dont want to convert the text file to CSV.

If I have A CSV file, Can i Update my title Block without opening the Dialog Box?

 

Thanks

 

 

You started your 1st mail by saying you have a text file on a specific location. But probably not a problem. Each drawing has it own txt / csv file or one big mother of all csv / txt files for multiple files (drawings) , so multiple lines? And if so , how is the structure of your drawing name or is it just 9574896 as in your example? If so , is each sheet on a separate (named?) layout?

Share this post


Link to post
Share on other sites
gmmdinesh
You started your 1st mail by saying you have a text file on a specific location. But probably not a problem. Each drawing has it own txt / csv file or one big mother of all csv / txt files for multiple files (drawings) , so multiple lines? And if so , how is the structure of your drawing name or is it just 9574896 as in your example? If so , is each sheet on a separate (named?) layout?

Yes, I have a big mother file for all drawings. and i have attached here sample only, my original file is slightly Different from this sample.

Share this post


Link to post
Share on other sites
Lee Mac
I have already tried that lee-mac Lisp, when i run that lisp its opening the dialog box for select the csv file. and also it was working with CSV file, but i have a Text file only.

 

Could you please help me, how to fill automatically using text file.

 

  • A CSV file is merely a Text file whose data is delimited using commas - you can easily convert your Text file to a CSV file.

 

  • You can configure my program to source the data automatically without prompting the user for the file - read the program description.

 

  • With the program configured to run without prompting the user for the file, you can run my program across mutiple drawings using a Script (which could even be created using my Script Writer program).

Share this post


Link to post
Share on other sites
rlx
Posted (edited)
; having no complete list , using provided sample drawing and 1 data row only
; also use a fixed blockname ("1")


(defun SplitStr ( s d / p )
 (if (setq p (vl-string-search d s))
    (cons (substr s 1 p) (SplitStr (substr s (+ p 1 (strlen d))) d)) (list s)))

(defun c:t3 ( / fn-in fp-in attribute-names-list attribute-values-list ss blk)
 ; change attribute
 (defun _CA (a v)
   (vl-some '(lambda (x)
 (if (eq (strcase a) (strcase (vla-get-tagstring x)))(vla-put-textstring x v)))
     (vlax-invoke blk 'getattributes)))
 
 ; if filename has fixed name & location (setq fn-in "c:/bla/bladie/blabla.txt) "
 (setq bn "1" fn-in (getfiled "Text file containing" "" "txt" 0) fp-in (open fn-in "r"))
 (setq attribute-names-list (cddr (SplitStr (read-line fp-in) "\t")))
 (setq attribute-values-list (cddr (SplitStr (read-line fp-in) "\t")))
 (if fp-in (close fp-in))
 (foreach layout (layoutlist)
   (if (and (setq ss (ssget "_X" (list (cons 0 "INSERT")(cons 2 bn))))
     (setq blk (vlax-ename->vla-object (ssname ss 0))))
     (mapcar '(lambda (att val) (_CA att val))
                   attribute-names-list attribute-values-list
     )
   )
 )
 (princ)
)

Edited by rlx

Share this post


Link to post
Share on other sites
Tharwat

Hi,

 

I wrote this program based on txt file & sample drawing that attached earlier by the OP.

 

(defun c:AutoAttsUpd ( / *error* _peelstring  txt dir opn lst str sel int ent soc pos)
 ;; Tharwat - 07.Jun.2018	;;
 (defun *error* (msg)
   (and opn (close opn))
   (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
        (princ (strcat "\nError => " msg ))
   )
 )
 
 (setq txt "Att") ;; text File name that must be available in the directory of current drawing.
 (if (and (setq dir (strcat (getvar 'DWGPREFIX) txt ".txt"))
          (or (findfile dir)
              (alert (strcat "Text file " dir " is not found in current drawing's directory <!>"))
              )
          (setq opn (open dir "r"))
          (read-line opn)
          )
   (progn
     (defun _peelstring (string del / str pos lst)
       (while (setq pos (vl-string-search del string 0))
         (setq str    (substr string 1 pos)
               string (substr string (+ pos (1+ (strlen del))))
               )
         (and str (/= str "") (setq lst (cons str lst)))
         )
       (and string (/= string "") (setq lst (cons string lst)))
       (reverse lst)
       )
     (while (setq str (read-line opn))
       (setq lst (cons (_peelstring str "\t") lst))
       )
     (and (setq int -1 sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (apply 'strcat (mapcar '(lambda (u) (strcat (cadr u) ",")) lst))))))
          (while (setq ent (ssname sel (setq int (1+ int))))
            (and (setq soc (assoc (cdr (assoc 5 (entget ent))) lst))
                 (setq soc (cddr soc)
                       pos -1)
                 (princ "\nProcessing ...")
                 (mapcar '(lambda (x) (vla-put-textstring x (nth (setq pos (1+ pos)) soc)))
                         (vlax-invoke (vlax-ename->vla-object ent) 'getattributes))
                 )
            )
          )
     )
   )
 (*error* nil)
 (princ)
 ) (vl-load-com)

Share this post


Link to post
Share on other sites
gmmdinesh

Hello,

Thank you all for your Code,

Tharwat,when i tried your code i got error like file not found on current drawing directory.

Actually my text file is not placed on current drawing directory. so how to mention the path in lisp?

 

Thanks

Share this post


Link to post
Share on other sites
Tharwat

Tharwat,when i tried your code i got error like file not found on current drawing directory.

Actually my text file is not placed on current drawing directory. so how to mention the path in lisp?

 

Thanks

 

Hi,

Select your txt file then right click then properties, then from the properties window go to security tab then copy the path of the file then close that window.

 

Now just replace the path with the following from my codes above.

 

(setq txt "Att") ;; text File name ..... [b][color="red"]<--- REMOVE THIS LINE FROM THE PROGRAM SINCE YOU DON'T NEED IT ANYMORE.[/color][/b]
 (if (and (setq dir "C:\\Users\\Tharwat\\Desktop\\Att.txt") ;; [b][color="blue"]YOU SHOULD HAVE THE PATH WITH TWO BACK SLASHES OR ONE FORWARD SLASH.[/color][/b]
          (or (findfile dir)
               (alert (strcat "Text file was not found in current path => " dir))
          )
          ;;; THE REST OF CODES

Share this post


Link to post
Share on other sites
gmmdinesh

Hello Tharwat,

I have changed the code as you posted above, but it's not changed anything.

(defun c:AutoAttsUpd ( / *error* _peelstring  txt dir opn lst str sel int ent soc pos)
 ;; Tharwat - 07.Jun.2018	;;
 (defun *error* (msg)
   (and opn (close opn))
   (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
        (princ (strcat "\nError => " msg ))
   )
 )
 
; (setq txt "Att") ;; text File name ..... <--- REMOVE THIS LINE FROM THE PROGRAM SINCE YOU DON'T NEED IT ANYMORE.
 (if (and (setq dir "B:\\AppData\\Local\\Autodesk\\Autodesk AutoCAD Map 3D 2014\\R19.1\\enu\\LISP\\Att.txt") ;; YOU SHOULD HAVE THE PATH WITH TWO BACK SLASHES OR ONE FORWARD SLASH.
          (or (findfile dir)
               (alert (strcat "Text file was not found in current path => " dir))
          )
          (setq opn (open dir "r"))
          (read-line opn)
          )
   (progn
     (defun _peelstring (string del / str pos lst)
       (while (setq pos (vl-string-search del string 0))
         (setq str    (substr string 1 pos)
               string (substr string (+ pos (1+ (strlen del))))
               )
         (and str (/= str "") (setq lst (cons str lst)))
         )
       (and string (/= string "") (setq lst (cons string lst)))
       (reverse lst)
       )
     (while (setq str (read-line opn))
       (setq lst (cons (_peelstring str "\t") lst))
       )
     (and (setq int -1 sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (apply 'strcat (mapcar '(lambda (u) (strcat (cadr u) ",")) lst))))))
          (while (setq ent (ssname sel (setq int (1+ int))))
            (and (setq soc (assoc (cdr (assoc 5 (entget ent))) lst))
                 (setq soc (cddr soc)
                       pos -1)
                 (princ "\nProcessing ...")
                 (mapcar '(lambda (x) (vla-put-textstring x (nth (setq pos (1+ pos)) soc)))
                         (vlax-invoke (vlax-ename->vla-object ent) 'getattributes))
                 )
            )
          )
     )
   )
 (*error* nil)
 (princ)
 ) (vl-load-com)

 

Could you please check this.

Share this post


Link to post
Share on other sites
Tharwat

A few restriction points as per your txt file:

 

  • Do you have the attributed block names as included in the txt file in the second column?
  • Do the attributed blocks in the drawing matching the handle codes as in the txt file in the first column?

Share this post


Link to post
Share on other sites
gmmdinesh
Do you have the attributed block names as included in the txt file in the second column?

Do the attributed blocks in the drawing matching the handle codes as in the txt file in the first column?

 

Yes I have same Attribute Block with same name as Text file and the Handle Name also Same.

But when i tried to manually it's working (Using ATTIN)

Share this post


Link to post
Share on other sites
Tharwat

So can you upload a real sample drawing along with the txt file you have tested the program with to take a close look?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×