Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sequentially number attribute blocks with prefix

28 REPLIES 28
Reply
Message 1 of 29
Anonymous
11205 Views, 28 Replies

sequentially number attribute blocks with prefix

I am currently working on a project that requires me layout an area by inserting blocks at certain locations.  The block is a generic attributed block but I sumetimes need to have multipe groups of blocks i.e. G001, G002 then H001 and so on. I was just wondering if there is a way for me to select all the blocks in the drawing (using select similar) and then number the blocks automatically in a sequential order but also have an option to append a letter to the front. I have found some lsps around the web that do some of this but it's never quite what I need. Trying to reverse engineer them and apply it to my own lsp is a little above my skill level haha Any help is gratly appreciated.

28 REPLIES 28
Message 2 of 29
pbejse
in reply to: Anonymous


@Anonymous wrote:

I am currently working on a project that requires me layout an area by inserting blocks at certain locations.  The block is a generic attributed block but I sumetimes need to have multipe groups of blocks i.e. G001, G002 then H001 and so on. I was just wondering if there is a way for me to select all the blocks in the drawing (using select similar) and then number the blocks automatically in a sequential order but also have an option to append a letter to the front. I have found some lsps around the web that do some of this but it's never quite what I need. Trying to reverse engineer them and apply it to my own lsp is a little above my skill level haha Any help is gratly appreciated.


Will that be a constant value for the LETTER? Other cases with no LETTER at all?

 

You wont be able to control the "sequence" if you are planning to use a "Select Similar" method of selection, unless its by  order of creation.

 Just a thought, you mentioned "certain locations" , is that like in a row/column grid position? is so then yes, select similar would work justfine.

 

You found a lisp, post it here [plesase  do acknowledge the author]. You may havea better chance of "reverse engineering" the code with forum members help.

 

pBe

 

EDIT: this may interest you --> To sort the blocks look into this link BlockSSSort.lsp by Kent Cooper <-- post # 9 

Message 3 of 29
3wood
in reply to: Anonymous

You can also try ALTEXT.vlx which is able to numbering block attributes in a sequence and add prefix at the same time.

 

Message 4 of 29
chaitanya.chikkala
in reply to: Anonymous

Hello....

   I have written a lisp routine which increments attribute values sequentially.I attaching the same with this message.

   Hope this will serve your purpose.

   Command for using this : incr

  

Message 5 of 29
Anonymous
in reply to: pbejse

Here is the existing script I use but it requires clicking each individual block, I need to be able to select all blocks at once.

 

(defun c:NUMME (/ oldPref oldSuf oldStart curText curStr
numZeros)
(vl-load-com)

(initget 6)
(setq numZeros (getInt "\nEnter number of 0 prefix's:"))

(defun num2str (num / numStr)
(setq numStr (itoa num))
(If (< (strlen numStr) numZeros)
(repeat (- numZeros (strlen numStr))
(setq numStr (strcat "0" numStr))
)
)
numStr
)

(if(not rnm:Pref)(setq rnm:Pref ""))
(if(not rnm:Suf)(setq rnm:Suf ""))
(if(not rnm:Start)(setq rnm:Start 1))
(setq oldPref rnm:Pref
oldSuf rnm:Suf
oldStart rnm:Start); end setq
(setq rnm:Pref
(getstring T
(strcat "\nPrefix: <"rnm:Pref">: ")))
(if(= "" rnm:Pref)(setq rnm:Pref oldPref))
(if(= " " rnm:Pref)(setq rnm:Pref ""))
(setq rnm:Suf
(getstring T
(strcat "\nSuffix: <"rnm:Suf">: ")))
(if(= "" rnm:Suf)(setq rnm:Suf oldSuf))
(if(= " " rnm:Suf)(setq rnm:Suf ""))
(setq rnm:Start
(getint
(strcat "\nStarting number <"
(itoa rnm:Start)">: ")))
(if(null rnm:Start)(setq rnm:Start oldStart))
(while T
(setq curStr(strcat rnm:Pref(num2Str rnm:Start)rnm:Suf))
(setq curText
(car
(nentsel "\n<<< Pick TEXT, MTEXT or ATTRIBUTE or press Esc to quit >>> ")))
(if
(and
curText
(member(cdr(assoc 0(entget curText))) '("TEXT" "MTEXT" "ATTRIB"))
); end and
(progn
(vla-put-TextString
(vlax-ename->vla-object curText)curStr)
(setq rnm:Start(1+ rnm:Start))
); end progn
(princ "\n This is not DText or MText ")
); end if
); end while
(princ)
); end of c:renum

(princ "\n[Info] http:\\\\www.AsmiTools.com [Info]")
(princ "\n[Info] Renumber tool. Type RENUM to run. [Info]")

Message 6 of 29
pbejse
in reply to: Anonymous


@Anonymous wrote:

Here is the existing script I use but it requires clicking each individual block, I need to be able to select all blocks at once.

 .....


That is exactly my point HaleOED, You may have a problem with  "all blocks at once" appraoch, the sequence will depend on the entity creation order.

Are you fine with that?  We can modify the code to select all TEXT,MTEXT,ATTRIBUTE all at once just for you to see what happens to the sequence.

 

And what about attributes? if there are more than 1 attribute definition on the block? say 2 or 3? modify all of them? and what if the items already have the prefix/suffix? Remember i'm talking about selecting ALL at once here. 

 

Better yet, post a dwg sample here.

 

pBe

 

EDIT: oops, i forgot, you did mention attribute blocks, so the question about attribute still stands,

We can do this via selection on screen, pick the blocks on the order of sequence then press enter to process the selection. will that work for you?

 

Message 7 of 29
Anonymous
in reply to: pbejse

The blocks only have 1 attribute and your suggested mode for selection would work perfectly. The numbering could be based on the entity order creation no problem. Apologies for not being clearer. 

Message 8 of 29
Anonymous
in reply to: Anonymous

Anymore suggestions with this issue? I'm still stuck 😞

Message 9 of 29
chaitanya.chikkala
in reply to: Anonymous

PLEASE TRY THIS CODE...WHICH I HAVE MODIFIED AS PER YOUR REQUIREMENT

 

 

USAGE: COMMAND IS "INCR"....THEN ENTER STARTING NUMBER OF THE SEQUENCE AND THE SELECT THE BLOCKS WHICH U WANT TO MODIFY AT ONCE....

Message 10 of 29
Anonymous
in reply to: chaitanya.chikkala

Thank you, this is close but I need to be able to have a prefix that user inputs i.e. 'G' and I also need the numbers to have two leading zeroes i.e. 009 but then changes to 010 etc

Message 11 of 29
stevor
in reply to: Anonymous

Google: 'autolisp pad string with 0s zeros'

for many forms.

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/automatic-numbering-that-starts-at-00...

etal.

 

S
Message 12 of 29
chaitanya.chikkala
in reply to: Anonymous

So you want the whole attribute to be changed to the strings like

"G001" "G002"....if user inputs are "G" and "1" and

"H001" "H002"....if user inputs are "H" and "1"?????

 

 

IF SO....DAT IS POSSIBLE....PLEASE MAKE IT CLEAR......

Message 13 of 29

I HAVE MODIFIED THE CODE AS WHAT I MENTIONED IN THE PREVIOUS POST....

 

IF THIS ALSO DOESN'T WORK....I WILL TRY TO MODIFY AS PER YOUR REQUIREMENT.....NO PROBLEM

 

 

SAME COMMAND...BUT TWO INPUTS "G" "1"....LIKE THAT

Message 14 of 29
Anonymous
in reply to: chaitanya.chikkala

Thank you so much for that. It doesn't quite do what I need because it pads the zeroes incorrectly when you get to a two digit number. For example it should be H010 instead of H0010, I need the zeros to pad the space. I see a link above posted by another user so I think I shall try to work out how to change that in the script you sent me. Really want to learn how to do this stuff. Thanks!

Message 15 of 29
chaitanya.chikkala
in reply to: Anonymous

You are welcome. Try to figure it out...If you struck somewhere I can assist you further Smiley Happy

Message 16 of 29


@chaitanya.chikkala wrote:

You are welcome. Try to figure it out...If you struck somewhere I can assist you further Smiley Happy


Hello sir, thank you for this lisp.  I am also working with multiple blocks with attributes, I have tried your lisp and it is very close to what i need. please help me modify this lisp a bit that allows user to add another user input suffix at the back and remove the 00. e.g. G1A, G2A, G3A and so on. 

Message 17 of 29

TRY THIS OUT WITH THE SAME COMMAND

Message 18 of 29

Sir, It works perfect. This is exactly what I need. thank you very much for your help.Smiley Happy


@chaitanya.chikkala wrote:

TRY THIS OUT WITH THE SAME COMMAND


 

Message 19 of 29

Hi, I happen to be in a similar situation however i tried this LISP you posted and it makes sense. The only problem I have is I need to have it assigned to a particular attribute in the block. How can I edit that, I have about 4 attributes?

Thanks.

Message 20 of 29

Hi, That is possible if the attribute values that you want to change have the same tag name in all the blocks. In that case, I can change that code to suit your requirement. If possible please post your block in your reply. Thanks & Regards, Ch V Chaitanya.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost