Jump to content

Title Block Update Automatically


gmmdinesh

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 39
  • Created
  • Last Reply

Top Posters In This Topic

  • gmmdinesh

    19

  • Tharwat

    12

  • rlx

    6

  • BIGAL

    2

Top Posters In This Topic

Posted Images

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

; 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
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...