Jump to content

Recommended Posts

Posted

Hi,

 

LeeMac wrote a Lisp for me some time back to update block attribs from a text file. The block attribs are the project name and project number. The come from the same line in the text file so the line is like this:

L4535 Joe Bloggs Road Improvement Scheme. So TAG1 attrib becomes "L4535 Joe Bloggs Road Improvement Scheme" and TAG2 becomes "L4535". I want to modify it so the TAG1 becomes everything after the first space and TAG2 remains as is. I have to modify it myself many times but I get lost in it.

 

I would appreciate if anyone could halp on this.

 

Thanks.

 

 
project_names : dialog { key = "dctitle";
 spacer;  
 : list_box { label = "Choose a project name:"; key = "lst";
              alignment = centered; fixed_height = true;
              fixed_width = true; width = 60; height = 20; }
 spacer;
 ok_cancel;
}

 

 
(defun c:project_names (/ *error* _read
                      BLOCKNAME
                      DCFILENAME DCFLAG DCTAG
                      ELST ENT I POS PTR SS STR
                      STRFILENAME STRLST TAGSTRING TAGSTRING1 TAGSTRING2

                    )
 (vl-load-com)
 ;; Lee Mac  ~  01.03.10
 
 (setq dcfilename  "project_names.dcl"   ;; DCL Filename
       Strfilename "CCC_NNRDO_Project_Names.txt"   ;; Data Filename
       BlockName   "CCC_Project_Names"    ;; Block Name
       TagString1  "TAG1"             ;; Tag String
       TagString2  "TAG2"             ;; Tag String
  )

 (defun *error* (msg)
   (and dcTag (unload_dialog dcTag))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (defun _read (file / ofile lst nl)
   (cond (  (setq ofile (open file "r"))
        
            (while (setq nl (read-line ofile))
              (setq lst (cons nl lst)))
            (close ofile)))
 
   (reverse lst))

 (cond (  (not (setq i -1 ss (ssget "_X" (list (cons 0 "INSERT")
                                               (cons 2 BlockName) (cons 66 1)))))
          (princ (strcat "\n** No Blocks with Name: " BlockName " Found **")))
       (  (not (setq Strfilename (findfile Strfilename)))
          (princ "\n** Data File not Found **"))
       (  (not (setq StrLst (_read Strfilename)))
          (princ "\n** Data File Empty **"))
       (  (<= (setq dcTag (load_dialog dcfilename)) 0)
          (princ "\n** Dialog Definition Not Found **"))
       (  (not (new_dialog "project_names" dcTag))
          (princ "\n** Dialog Could not be Loaded **"))
       (t
          (start_list "lst")
          (mapcar (function add_list) StrLst)
          (end_list)
          (setq ptr (set_tile "lst" "0"))
        
          (action_tile  "lst" "(setq ptr $value)")
          (setq dcFlag (start_dialog))
          (setq dcTag (unload_dialog dcTag) TagString1 (strcase TagString1)
                                            TagString2 (strcase TagString2)
                Str   (nth (atoi ptr) StrLst))
          (if (= 1 dcFlag)
            (while (setq ent (ssname ss (setq i (1+ i))))
              (while (not (eq "SEQEND" (cdr (assoc 0 (setq eLst (entget (setq ent (entnext ent))))))))
                (cond (  (eq TagString1 (cdr (assoc 2 eLst)))
                       
                         (entupd
                           (cdr (assoc -1 (entmod (subst (cons 1 Str)
                                                         (assoc 1 eLst) eLst))))))
                      (  (and (eq TagString2 (cdr (assoc 2 eLst)))
                              (setq pos (vl-string-position 32 Str)))
                         (entupd
                           (cdr (assoc -1 (entmod (subst (cons 1 (substr str 1 pos))
                                                         (assoc 1 eLst) eLst)))))))))
            (princ "\n*Cancel*"))))
 (princ))

Posted

Some untested modification. Changes marked in red:

           (if (= 1 dcFlag)
            (while (setq ent (ssname ss (setq i (1+ i))))
              (while (not (eq "SEQEND" (cdr (assoc 0 (setq eLst (entget (setq ent (entnext ent))))))))
                (cond (  [color=darkred](and [/color](eq TagString1 (cdr (assoc 2 eLst)))
                              [color=darkred](setq pos (vl-string-position 32 Str))[/color])
                         (entupd
                           (cdr (assoc -1 (entmod (subst (cons 1[color=darkred] (substr Str (+ 2 pos))[/color])
                                                         (assoc 1 eLst) eLst))))))
                      (  (and (eq TagString2 (cdr (assoc 2 [color=black]eLst)))
                               [/color][color=black](setq pos (vl-string-position 32 Str)))
[/color]                          (entupd
                           (cdr (assoc -1 (entmod (subst (cons 1 (substr str 1 pos))
                                                         (assoc 1 eLst) eLst)))))))))
            (princ "\n*Cancel*"))))

Posted

Well the untested modification has now been tested and it works a treat. Thanks for you help, Irneb. Much appreciated.

Posted

You're welcome! Glad I could do this in my head ... means my brain's got a few more years left :P

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