Jump to content

Looking to Modify Lisp Routine to Add Leading Zero to Annotative Block with Attribute


McRuff

Recommended Posts

Hello All,

I am totally new here, so if there is a thread already started, let me know.

 

I have a block I'm using for a building column grid mark. It is annotative, contains (1) character of text for column line "C" or row "R" and an attribute for the numeric value. The block serves nicely for my purposes. Along with the block I have an auto lisp routine I found online that I use to sequence the numbering from 0 (zero) through 150.

 

  • The block and lisp routine work, but I cannot get a leading zero into the attribute for the numbers 0 through 9...ex. 00, 01, 02, etc.

 

I saw an old post from this site (2009) where alanjt posted a lisp he named NumFix. I don't see it posted any longer. I have an issue getting it to work and was wondering if anyone who uses this lisp can help me or know how to contact alanjt to invite him in.

 

If anyone has some other lisp that can do what I'm asking and may be able to be 'spliced' into my existing lisp routine, that would be a great help.

Link to comment
Share on other sites

welcome to the band 🤓

 

; make sure itoa has fixed length , i.e. (fixitoa 1 3) -> "001"
(defun fixitoa ( #i #n / s ) (setq s (itoa #i))(while (> #n (strlen s))(setq s (strcat "0" s))) s)

 

Link to comment
Share on other sites

Another method is using the text numeric value. if less than etc

 

(setq x "5")
(cond 
((< (atoi x) 10)(setq x (strcat "00" x)))
((>= (atoi x) 10)(setq x (strcat "0" x)))
)

 

 

Link to comment
Share on other sites

Well, thank you both for welcoming me to the site! I never expected not one but two responses so quickly.

 

If it helps, I'm currently running AutoCAD 2021. It's been years since I've had to write any lisp routines, so safe to say I'm very 'rusty'. I'm adding the lisp routine below. As you can see, there is no allowance for adding (maintaining) a leading zero to digits 1 through 9.Once I get to ten and above, I no longer need to have the leading zero.

 

In the lines you presented above, I would imagine I will need to repeat them in the lisp to specify only those digits I need to modify; is that a correct assumption? The other question become; where to insert the lines. I am thinking it would be before (setq num (1+ num)) in the lisp I'm using.

 

;*********************************
(defun c:ASQ () :Attribute SeQuential numbering
(princ "\nStarting Number: ")
(setq startnum (getint))
(setq num startnum)
(princ "\nPick Block to sequentially number: ")
(while
(setq a (entsel))
(setq b (car a))
(setq c (entget b))
(setq d (entnext b))
(setq e (entget d))
(setq f (assoc 0 e))
(setq g (assoc 2 e))
(setq h (assoc 1 e))
(setq num$ (itoa num))
(setq hh (cons 1 num$))
(setq e (subst hh h e))
(entmod e)
(entupd d)
(setq num (1+ num))
(princ "\nNext block: ")
)
(princ)
)
;*********************************

col_bub-lwr_left.dwg

I'm also attaching the annotative block with attribute so you get a better idea of what I'm using.

 

In a drawing session I start by inserting the block, double-clicking on it to set "C" or "R" requirement and then copying or arraying for the number of columns. After that I run the "ASQ" lisp and select the blocks to sequence them. Like I've stated, it does work with the exception of the leading zeros.

 

Hope this helps explaining things better.

Link to comment
Share on other sites

;;; Attribute SeQuential numbering
(defun c:ASQ ( / fixitoa startnum num a b c d e f g h num$ hh)
  ;;; make sure itoa has fixed length , i.e. (fixitoa 1 3) -> "001"
  (defun fixitoa (#i #n / s)
    (setq s (itoa #i))(while (> #n (strlen s)) (setq s (strcat "0" s))) s)
  (if (setq startnum (getint "\nStarting Number: ") num startnum)
    (while (setq a (entsel "\nPick Block to sequentially number: "))
      (setq b (car a) c (entget b) d (entnext b) e (entget d))
      (setq f (assoc 0 e) g (assoc 2 e) h (assoc 1 e))
      (setq num$ (fixitoa num 2) hh (cons 1 num$) e (subst hh h e))
      (entmod e) (entupd d)
      (setq num (1+ num))
    )
  )
  (princ)
)

 

Edited by rlx
fixed number of zero's to 2
Link to comment
Share on other sites

Thanks rlx! It works perfectly!! Didn't expect it so quickly.

 

Okay, a lot more of a rewrite than I thought.

 

Now back to my other project, sheet set manager. Of course the team I work with now says, 'Can we get it to this?' ...I just got it done and set to go; now you tell the rest of the 'wish list'? ...lol

 

Again, thanks for being such a great help,

McRuff

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