Sequentially Number Attribute Blocks

Sequentially Number Attribute Blocks

krkeene
Enthusiast Enthusiast
596 Views
7 Replies
Message 1 of 8

Sequentially Number Attribute Blocks

krkeene
Enthusiast
Enthusiast

I found an "attribute_sequential_increment_NEW.LSP" file by "chaitanya.chikkala" back in Sept. of 2015, that works great for my application, but was wondering if/how we can make it work for an Alpha sequence instead of just an Integer sequence.  I'd like to be able to use either Numeric or Alpha.  When I enter an "A" when prompted for the Starting Number, the first block value is A, but the next ones are 1, 2, 3, etc.  

0 Likes
Accepted solutions (1)
597 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

I made the following changes at the beginning of the code...try with these revisions:

(defun c:incr (/ ent obj x i ST_STR is_number) ; add is_number
  (SETQ ST_STR1 (GETSTRING "\nENTER SUFFIX (ANY ALPHABET/WORD)"))
  (SETQ ST_STR2 (GETSTRING "\nENTER PREFIX (ANY ALPHABET/WORD)"))
  (SETQ ST_STR (GETSTRING "\nENTER STARTING NUMBER OF THE SEQUENCE(ANY INTEGER)"))

(if(zerop(atoi ST_STR)) ; test if converts to 0
  (setq ST_STR (ascii ST_STR)) ; convert alphabet to ascii number
  (setq is_number T) ; set number flag
)

  (vl-load-com)
  (setq i 0)
  (SETQ BLOCK_LIST (SSGET))
  (SETQ BLOCK_LIST (FORM_SSSET BLOCK_LIST))
  (while (< I (LENGTH BLOCK_LIST))
; add check for alphabet vs number
(if(not is_number)
    (SETQ ST_STR (STRCAT "00" (chr ST_STR))) ; for alphabet
    (SETQ ST_STR (STRCAT "00" ST_STR))       ; for number
)

    (SETQ TEMP_ELE (NTH 0 (ATTRIBUTE_EXTRACT (NTH I BLOCK_LIST))))
    (SETQ TEMP_ATTRIBUTE (STRCAT ST_STR1 ST_STR ST_STR2))
    (SETQ TEMP_TAG (NTH 0 TEMP_ELE))
    (MODIFY_ATTRIBUTES (NTH I BLOCK_LIST) (LIST TEMP_TAG) (LIST TEMP_ATTRIBUTE))
; add check for alphabet vs number
(if(not is_number)
    (SETQ ST_STR (+ ST_STR 1)) ; for alphabet
    (SETQ ST_STR (ITOA (+ (ATOI ST_STR) 1))) ; for number
)
    (setq i (+ i 1))

  )
  (princ))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

Sea-Haven
Mentor
Mentor

What happens when you hit "Z" does it go to AA ?

 

There is some algorithms out there that will do that for you search for Gille functions.

; Number2Alpha - Converts Number into Alpha string
; Function By: Gilles Chanteau from Marseille, France
; Arguments: 1
; Num# = Number to convert
; Syntax example: (Number2Alpha 731) = "ABC"

0 Likes
Message 4 of 8

krkeene
Enthusiast
Enthusiast

Paul, Thanks for taking a look, but it still doesn't work.  I don't need the "00" in the number, so I removed the "00" section from 2 of the lines (Rows 18 & 19).  When I run the program, I get prompted for the Suffix, then Prefix, which I leave blank by pressing Enter.  Then I put an "A" when it prompts for the Starting Number.  The result is A, 2, 3, 4, etc. as mentioned previously.  

0 Likes
Message 5 of 8

krkeene
Enthusiast
Enthusiast

We should never hit Z, but if we did, I think we could just enter an "A" as a Prefix, then the sequential lettering would kick in to give us the AA, AB, AC, etc.   First, I need to get the Letter sequencing working.  

0 Likes
Message 6 of 8

paullimapa
Mentor
Mentor
Accepted solution

ok, that simplifies it even more without add the 00.  Try this modification:

(defun c:incr (/ ent obj x i ST_STR is_number) ; add is_number
  (SETQ ST_STR1 (GETSTRING "\nENTER SUFFIX (ANY ALPHABET/WORD)"))
  (SETQ ST_STR2 (GETSTRING "\nENTER PREFIX (ANY ALPHABET/WORD)"))
  (SETQ ST_STR (GETSTRING "\nENTER STARTING NUMBER OF THE SEQUENCE(ANY INTEGER)"))

  (vl-load-com)
  (setq i 0)
  (SETQ BLOCK_LIST (SSGET))
  (SETQ BLOCK_LIST (FORM_SSSET BLOCK_LIST))
  (while (< I (LENGTH BLOCK_LIST))
    (SETQ TEMP_ELE (NTH 0 (ATTRIBUTE_EXTRACT (NTH I BLOCK_LIST))))
    (SETQ TEMP_ATTRIBUTE (STRCAT ST_STR1 ST_STR ST_STR2))
    (SETQ TEMP_TAG (NTH 0 TEMP_ELE))
    (MODIFY_ATTRIBUTES (NTH I BLOCK_LIST) (LIST TEMP_TAG) (LIST TEMP_ATTRIBUTE))
; add check for alphabet vs number
(if(zerop(atoi ST_STR))
    (SETQ ST_STR (chr (+ (ascii ST_STR) 1))) ; for alphabet
    (SETQ ST_STR (ITOA (+ (ATOI ST_STR) 1))) ; for number
)
    (setq i (+ i 1))
  )
  (princ))

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 8

krkeene
Enthusiast
Enthusiast

Works Perfect.  Thanks Paul.  

0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

Glad to have helped…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes