Jump to content

Block Attribute Renumbering


Cad64

Recommended Posts

Hi guys, I am in need of a lisp routine and I'm hoping somebody will be able to help me out. I don't think it's terribly complicated, but it is outside of my skill set.

 

What I need is a way to re-number attributes inisde blocks.

 

The blocks I'm working with contain 4 attributes, but the only attribute that needs to change is the "Valve Number". (See the screenshot below).

 

Sometimes, when laying out large irrigation plans, I may need to go back and place another valve somewhere in the middle of the layout. This means I have to renumber all the other valves which can take quite a bit of time doing it manually.

 

Ideally I would like to have a routine that lets me specify the starting valve number and then lets me click on each block to update the number incrementally as I click on each one. For example, suppose I need to renumber valves A-6 to A-40. I would like to be able to initiate the routine, type in 6 as the starting number and then start clicking on blocks to automatically renumber them.

 

Also, the "Valve Number" in my example is A-1, but the letter won't always be "A". Sometimes it will be "B" or "C" or whatever, so only the number after the dash can change.

 

Thanks for taking a look and let me know if you need more info. I would upload the block but it belongs to my client so I can't.

Block Attribute.jpg

Link to comment
Share on other sites

Hi,

 

Please try this program that I have just wrote and let me know how you get on with it and if you need any further extension of the function;

 


(defun c:IncAtts (/ *error* run st blk e at pre num v)
 ;;	Tharwat. cadtutor	;;
 ;;	Date:04.May.2016	;;

 (defun *error* (msg)
   (if (and msg
            (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
            )
     (princ (strcat "\nError: " msg))
     )
   (princ)
   )
 (setq run t)
 (while (not (setq *starting:number*
                    (cond ((and (setq st
                                       (getstring
                                         (strcat
                                           "\nSpecify starting number after char: eg. [X-1] <"
                                           (if *starting:number*
                                             *starting:number*
                                             (setq *starting:number* "A-1")
                                             )
                                           ">: "
                                           )
                                         )
                                      )
                                (eq st "")
                                )
                           *starting:number*
                           )
                          ((and (wcmatch st "*-#*")
                                (numberp (+ 2 (vl-string-search "-" st)))
                                )
                           (setq *starting:number* st)
                           )
                          (t nil)
                          )
                   )
             )
   (princ "\nUncorrect string!. Try again")
   )
 (princ "\nSelect attributed block with Tag name <1>:")
 (while
   (and
     run
     (setq blk
            (car
              (entsel
               )
              )
           )
     (eq (cdr (assoc 0 (setq e (entget blk)))) "INSERT")
     (eq (cdr (assoc 66 e)) 1)
     (if (vl-some
           '(lambda (x)
              (and (eq (vla-get-tagstring x) "1")
                   (setq at x)
                   )
              )
           (vlax-invoke (vlax-ename->vla-object blk) 'getattributes)
           )
       at
       (progn
         (princ "\nAttributed Block doesn't have tag name <1> !")
         (setq run nil)
         )
       )
     )
    (vla-put-textstring
      at
      (setq pre               (substr *starting:number*
                                      1
                                      (1+ (vl-string-search "-" *starting:number*))
                                      )
            num               (substr
                                *starting:number*
                                (+ 2 (vl-string-search "-" *starting:number*))
                                )
            *starting:number* (strcat pre (itoa (1+ (atoi num))))
            v                 (strcat pre num)
            )
      )
    )
 (princ)
 )(vl-load-com)

Link to comment
Share on other sites

Try this little gem from Gile:

 

Thanks for the link. That looks pretty good but it's really way more than I need. This routine will be used by other people in my clients office and I'm afraid all those options will be confusing and overwhelming for some users. I'm looking for something super simple that can be run from the command line, no dialogs. Just run the command, type in the starting number and go.

Link to comment
Share on other sites

Please try this program that I have just wrote and let me know how you get on with it and if you need any further extension of the function;

 

Hi Tharwat, this is exactly what I was looking for and it seems to work perfectly. Thank you for taking the time to write it. This will be very helpful. :)

Link to comment
Share on other sites

Hi Tharwat, this is exactly what I was looking for and it seems to work perfectly. Thank you for taking the time to write it. This will be very helpful. :)

 

Excellent, happy to help. :)

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