Jump to content
Guite

Sequential numbering a single attribute value in multiple attribute block

Recommended Posts

Guite

Hi all,

 

I am starting this new topic in the hope of getting better response. I found a topic which almost met my requirement here in the 8th post by ASMI. The difference is my blocks have multiple attributes.

 

My requirements are these:

1. User selects multiple block instances

2. User enters tag (choose if possible, hard coded also will do)

3. User enters starting number, including leading zeros, but no prefix or suffix

4. Routine puts in sequential numbers with leading zeros in the attribute value, starting at top left block, goes left to right, top to bottom.

 

In step 3 above, if the routine can 'remember' the last number of previous execution and continues, well and good. May be its difficult or impossible. If it can be done, then the routine might just as well 'remember' last tag used so that the user need only press enter on subsequent executions.

 

Can someone please help me on this?

 

Thanks in advance, this forum is wonderful.

 

Guite

Share this post


Link to post
Share on other sites
Guest Alan Cullen

I'll just work on one problem at a time, your other one. :lol:

 

I'll leave this one for ASMI to sort out. o:)

Share this post


Link to post
Share on other sites
Guite
I'll just work on one problem at a time, your other one. :lol:

 

I'll leave this one for ASMI to sort out. o:)

 

I thought that one was a closed chapter :lol:. Anyway the two are related. If you can provide a solution to that one, it would be great.

 

Guite

Share this post


Link to post
Share on other sites
Guest Alan Cullen

Guite,

 

Go back to the other thread, do what I asked, and I'll sort it out for you. o:)

Share this post


Link to post
Share on other sites
ASMI

1. Specify start number

2. Pick to wanted attribute

3. Select blocks and press Spacebar

 

Enjoy...

 

(defun c:mnum(/ stStr stNum nLen cAtr dLst blName
      fLst blLst blSet aName sLst lZer aStr)
 (vl-load-com)
 (if
   (and
     (setq stStr(getstring "\nSpecify start number: "))
     (setq stNum(atoi stStr))
     (setq nLen(strlen stStr))
     ); end and
   (progn
     (if
(and
   (setq cAtr(nentsel "\nPick attribute > "))
   (= "ATTRIB"(cdr(assoc 0(setq dLst(entget(car cAtr))))))
  ); end and
(progn
  (setq blName
    (vla-get-Name
       (vla-ObjectIDToObject
	  (vla-get-ActiveDocument
	     (vlax-get-acad-object))
	        (vla-get-OwnerID
	           (vlax-ename->vla-object(car cAtr)))))
	fLst(list '(0 . "INSERT")(cons 2 blName))
	aName(cdr(assoc 2 dLst))
	); end setq
  (princ "\n<<< Select blocks to number >>> ")
  (if
    (setq blSet(ssget fLst))
    (progn
     (setq sLst
                   (mapcar 'vlax-ename->vla-object
	      (mapcar 'car
	       (vl-sort
	        (vl-sort
	          (mapcar '(lambda(x)(list x(cdr(assoc 10(entget x)))))
	            (vl-remove-if 'listp 
                             (mapcar 'cadr(ssnamex blSet))))
	                '(lambda(a b)(<(caadr a)(caadr b))))
		          '(lambda(a b)(>(cadadr a)(cadadr b)))))))
     (foreach i sLst
       (setq lZer "")
       (repeat(- nLen(strlen(itoa stNum)))
	 (setq lZer(strcat lZer "0"))
	 ); end repeat
       (setq atLst
	      (vlax-safearray->list
		 (vlax-variant-value
		   (vla-GetAttributes i))))
       (foreach a atLst
	 (if
	   (= aName(vla-get-TagString a))
	      (vla-put-TextString a
		(strcat lZer(itoa stNum)))
	   ); end if
	 ); end foreach
	 (setq stNum(1+ stNum))
       ); end foreach
      ); end progn
    (princ "\nEmpty selection! Quit. ")
    ); end if
  ); end progn
(princ "\nThis isn't attribute! Quit. ")
); end if
     ); end progn
   (princ "\nInvalid start number! Quit. ")
   ); end if
 (princ)
 ); end of c:mnum

Share this post


Link to post
Share on other sites
Guite

Thanks a lot, ASMI. I will try it out on Monday.

 

Cheers,

Guite

Share this post


Link to post
Share on other sites
Guite

WOW! Just tested it and it works like a charm. Thank you so much ASMI.

 

Cheers,

Guite

Share this post


Link to post
Share on other sites
Guest Alan Cullen

The guru strikes again. Guite, ASMI hates being refered to as a guru, but he really is, along with a few others here. :P o:)

Share this post


Link to post
Share on other sites
Guite

Oh I see. So that's our little secret. Promise, I will only reveal it judiciously. :)

 

Guite

Share this post


Link to post
Share on other sites
Guite

Hi ASMI,

 

Please look at the attached files. The numbering sequence in your script is based on world UCS. Can it be modified to read local/screen UCS? As it stands now, the sequence will be very difficult to follow/track when the drawing is printed.

 

Anyway, your script works perfectly when everything is aligned to world UCS. Thanks once again for your help this far.

 

Guite

DOOR-DD01.dwg

Door-tags.jpg

Share this post


Link to post
Share on other sites
ASMI

Ok. Try it.

 

(defun c:mnum(/ stStr stNum nLen cAtr dLst blName
      fLst blLst blSet aName sLst lZer aStr)
 (vl-load-com)
 (if
   (and
     (setq stStr(getstring "\nSpecify start number: "))
     (setq stNum(atoi stStr))
     (setq nLen(strlen stStr))
     ); end and
   (progn
     (if
(and
   (setq cAtr(nentsel "\nPick attribute > "))
   (= "ATTRIB"(cdr(assoc 0(setq dLst(entget(car cAtr))))))
  ); end and
(progn
  (setq blName
    (vla-get-Name
       (vla-ObjectIDToObject
	  (vla-get-ActiveDocument
	     (vlax-get-acad-object))
	        (vla-get-OwnerID
	           (vlax-ename->vla-object(car cAtr)))))
	fLst(list '(0 . "INSERT")(cons 2 blName))
	aName(cdr(assoc 2 dLst))
	); end setq
  (princ "\n<<< Select blocks to number >>> ")
  (if
    (setq blSet(ssget fLst))
    (progn
     (setq sLst
                   (mapcar 'vlax-ename->vla-object
	      (mapcar 'car
	       (vl-sort
	        (vl-sort
	          (mapcar '(lambda(x)(list x
		   (trans(cdr(assoc 10(entget x)))0 1)))
	            (vl-remove-if 'listp 
                             (mapcar 'cadr(ssnamex blSet))))
	                '(lambda(a b)(<(caadr a)(caadr b))))
		          '(lambda(a b)(>(cadadr a)(cadadr b)))))))
     (foreach i sLst
       (setq lZer "")
       (repeat(- nLen(strlen(itoa stNum)))
	 (setq lZer(strcat lZer "0"))
	 ); end repeat
       (setq atLst
	      (vlax-safearray->list
		 (vlax-variant-value
		   (vla-GetAttributes i))))
       (foreach a atLst
	 (if
	   (= aName(vla-get-TagString a))
	      (vla-put-TextString a
		(strcat lZer(itoa stNum)))
	   ); end if
	 ); end foreach
	 (setq stNum(1+ stNum))
       ); end foreach
      ); end progn
    (princ "\nEmpty selection! Quit. ")
    ); end if
  ); end progn
(princ "\nThis isn't attribute! Quit. ")
); end if
     ); end progn
   (princ "\nInvalid start number! Quit. ")
   ); end if
 (princ)
 ); end of c:mnum

Share this post


Link to post
Share on other sites
Guite

ASMI, you da man!!! It works perfectly (until I find another bug :wink: 8), just kidding of course).

 

Thank you very much. :D:D:D

 

Guite

Share this post


Link to post
Share on other sites
JSNORTIN

I Would Like To Have This Add +2 So Say Your Start # Is 100 Your Next Would Be 102, 104, Etc... How Would I Change It To Do That?

Share this post


Link to post
Share on other sites
ASMI
I Would Like To Have This Add +2

Find line:

(setq stNum(1+ stNum))

and change to

(setq stNum(+ 2 stNum))

Share this post


Link to post
Share on other sites
Trebuchet

Sorry to bring up an old thread, but I'm using this lisp, and is there a way to make it change the blocks by select order the way tcount does?

 

Thanks so much.

Share this post


Link to post
Share on other sites
ASMI

Oops! One more submarine come to the surface.

 

... and is there a way to make it change the blocks by select order the way tcount does?

Because not? I will think about it next week. Today I have other work.

Share this post


Link to post
Share on other sites
Trebuchet

Thank you!

Share this post


Link to post
Share on other sites
wizman
is there a way to make it change the blocks by select order the way tcount does?

 

just a sidenote:

 

express' acettxt.lsp may give a hint how it sorts its entities.

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

×