Results 1 to 5 of 5

Thread: Updating Block Description Text

  1. #1
    Member
    Join Date
    2007-09
    Posts
    6

    Default Updating Block Description Text

    Hello,

    I'm using the following program to extract block names and descriptions from a CSV file, and to insert the descriptions into the blocks:

    Code:
    (defun C:celldesc()
    	(setq fname (getstring "Enter the filename of the report:"))
    	(if (setq f(open fname "r"))
    	  (while (setq fText(read-line f))
    	    	(setq nameStart (+ 1 (vl-string-position (ascii ",") fText 0)))
    	    	(setq descStart (+ 1 (vl-string-position (ascii ",") fText (+ 1 nameStart))))
    	    	(setq bName (vl-string-trim ", " (substr fText nameStart (+ 1 (- descStart nameStart)))))
    	    	(setq bDesc (vl-string-trim ", " (substr fText descStart (+ 1 (- (strlen ftext) descstart)))))
    	    	(setq en (tblobjname "BLOCK" bName ))
    	    	(setq ei (entget en))
    		(entmod (append ei (list (cons 4 bDesc))))
    	   )
    	  (princ "\nFile Not Found")
    	)
      (princ)
    )
    The program isn't updating the blocks. When I put a (princ) statement around the (entmod) call, the program would print 'null' repeatedly - once for each block.The program seems capable of getting block attributes, but it doesn't want to update description.

    Any help would be appreciated.

    Last edited by Opie; 2008-01-14 at 01:33 PM. Reason: [CODE] tags added, see Moderator Note

  2. #2
    I could stop if I wanted to kpblc2000's Avatar
    Join Date
    2006-09
    Posts
    211

    Default Re: Updating Block Description Text

    Try to use:
    Code:
    (defun c:celldesc (/           adoc        handle      *error*     file_name
                       str         blk_descr   block_name  block_descr block_def
                       )
      (defun *error* (msg)
        (vl-catch-all-apply '(lambda () (close handle)))
        (vla-endundomark adoc)
        (princ msg)
        (princ)
        ) ;_ end of defun
    
      (vla-startundomark
        (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
        ) ;_ end of vla-startundomark
      (if (setq file_name (getfiled "Select a description file" "" "txt" 4))
        (progn
          (setq handle (open file_name "r"))
          (while (setq str (read-line file_name))
            (setq block_name  (1+ (vl-string-position (ascii ",") str 0))
                  block_descr (1+ (vl-string-position (ascii ",") str (1+ block_name)))
                  block_name  (vl-string-trim
                                ", "
                                (substr str block_name (+ 1 (- block_descr block_name)))
                                ) ;_ end of vl-string-trim
                  block_descr (vl-string-trim
                                ", "
                                (substr str
                                        block_descr
                                        (+ 1 (- (strlen str) block_descr))
                                        ) ;_ end of substr
                                ) ;_ end of vl-string-trim
                  ) ;_ end of setq
            (if (tblobjname "block" block_name)
              (progn
                (vl-catch-all-apply
                  '(lambda ()
                     (vla-put-comments
                       (setq block_def (vla-item (vla-get-blocks adoc) block_name))
                       block_descr
                       ) ;_ end of vla-put-Comments
                     (vla-update block_def)
                     ) ;_ end of lambda
                  ) ;_ end of vl-catch-all-apply
                ) ;_ end of progn
              ) ;_ end of if
            ) ;_ end of while
          ) ;_ end of progn
        ) ;_ end of if
      (vla-endundomark adoc)
      (princ)
      ) ;_ end of defun
    Use AUTOCAD / ADT / AA 2006 / 2008 / 2010
    All i say is only my opinion
    I'm watching you! Your

  3. #3
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,211

    Default Re: Updating Block Description Text

    Check this line, please:

    Code:
     (vla-update block_def)
    As I remember the Block object haven't "Update" method at all
    Am I wrong?

    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  4. #4
    Member
    Join Date
    2007-09
    Posts
    6

    Default Re: Updating Block Description Text

    Quote Originally Posted by kpblc2000 View Post
    Try to use:
    Code:
    (defun c:celldesc (/           adoc        handle      *error*     file_name
                       str         blk_descr   block_name  block_descr block_def
                       )
      (defun *error* (msg)
        (vl-catch-all-apply '(lambda () (close handle)))
        (vla-endundomark adoc)
        (princ msg)
        (princ)
        ) ;_ end of defun
    
      (vla-startundomark
        (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
        ) ;_ end of vla-startundomark
      (if (setq file_name (getfiled "Select a description file" "" "txt" 4))
        (progn
          (setq handle (open file_name "r"))
          (while (setq str (read-line file_name))
            (setq block_name  (1+ (vl-string-position (ascii ",") str 0))
                  block_descr (1+ (vl-string-position (ascii ",") str (1+ block_name)))
                  block_name  (vl-string-trim
                                ", "
                                (substr str block_name (+ 1 (- block_descr block_name)))
                                ) ;_ end of vl-string-trim
                  block_descr (vl-string-trim
                                ", "
                                (substr str
                                        block_descr
                                        (+ 1 (- (strlen str) block_descr))
                                        ) ;_ end of substr
                                ) ;_ end of vl-string-trim
                  ) ;_ end of setq
            (if (tblobjname "block" block_name)
              (progn
                (vl-catch-all-apply
                  '(lambda ()
                     (vla-put-comments
                       (setq block_def (vla-item (vla-get-blocks adoc) block_name))
                       block_descr
                       ) ;_ end of vla-put-Comments
                     (vla-update block_def)
                     ) ;_ end of lambda
                  ) ;_ end of vl-catch-all-apply
                ) ;_ end of progn
              ) ;_ end of if
            ) ;_ end of while
          ) ;_ end of progn
        ) ;_ end of if
      (vla-endundomark adoc)
      (princ)
      ) ;_ end of defun
    Thank you, this works perfectly, however:
    (while (setq str (read-line file_name))
    should read
    (while (setq str (read-line handle))

    because file_name is a string, not a FILE.

  5. #5
    I could stop if I wanted to kpblc2000's Avatar
    Join Date
    2006-09
    Posts
    211

    Default Re: Updating Block Description Text

    Yes, that's right. Both of you are right. I'm terribly sorry for my mistakes
    Use AUTOCAD / ADT / AA 2006 / 2008 / 2010
    All i say is only my opinion
    I'm watching you! Your

Similar Threads

  1. block description after the fact
    By cadtag in forum AutoCAD General
    Replies: 3
    Last Post: 2012-03-16, 11:11 PM
  2. Add description to an existing block
    By avatar in forum AutoLISP
    Replies: 6
    Last Post: 2010-02-24, 01:18 AM
  3. Dynamic Block Parameters Description
    By robert.evansii in forum AutoLISP
    Replies: 0
    Last Post: 2007-12-06, 11:42 AM
  4. Dynamic Block Parameters Description
    By robert.evansii in forum Dynamic Blocks - Technical
    Replies: 0
    Last Post: 2007-12-05, 06:06 PM
  5. Replies: 5
    Last Post: 2006-09-11, 05:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •