Author Topic: Auto Number feedback  (Read 1941 times)

0 Members and 1 Guest are viewing this topic.

quamper

  • Guest
Auto Number feedback
« on: December 29, 2008, 12:41:46 PM »
I'm not much of a LISP programmer so I just stumbled through writing a real quick and dirty autonumber/increment routine thing. I'm sure this is a duplication of something I could have googled and found. I guess it was a learning experience. Anyways any suggestions or feedback on something I did wrong or could have done better? I'd love to learn for future efforts.

It seems to work fine for me other than I have to hit escape and repeat the command when I want to change to a new Prefix, but that doesn't really bother me.

Code: [Select]
(defun c:lb( / PREFIX SUFFIX TXTINSERT)
    (command "layer" "set" "label" "")
    (setq PREFIX (getstring "\nEnter Label Prefix: "))
    (setq SUFFIX 1)
    (while T
        (setq TXTINSERT (getpoint "\nSelect Text Placement: "))
        (command "text" TXTINSERT "" "" (strcat PREFIX "_"
            (if (< SUFFIX 10) "0" "")
            (itoa SUFFIX))
        )
        (setq SUFFIX (+ SUFFIX 1))
    )
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Auto Number feedback
« Reply #1 on: December 29, 2008, 01:08:30 PM »
Here would be my quick comments :)

Code: [Select]
(defun c:lb (/ prefix suffix txtinsert)
  ;;use make and the layer will be created otherwise will bomb if layer does not exist
  (command "-layer" "make" "label" "")
  ;;If you have a prefix you use regularly, you could make a default if enter is pressed like so
  (if (and (setq prefix (getstring "\nEnter Label Prefix<MYPRE>: "))
           (= prefix "")
      )
    (setq prefix "MYPRE")
  )
  (setq suffix 1)
  (while (setq txtinsert (getpoint "\nSelect Text Placement: "))
    ;;allows to hit enter to get out of loop
    (command "text"
             txtinsert
             ""
             ""
             (strcat prefix
                     "_"
                     (if (< suffix 10)
                       "0"
                       ""
                     )
                     (itoa suffix)
             )
    )
    (setq suffix (+ suffix 1))
  )
  (princ);;to exit quietly
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

quamper

  • Guest
Re: Auto Number feedback
« Reply #2 on: December 29, 2008, 01:13:41 PM »
I never realized that you could use make with the layer command for existing layers making them current at the same time. That's great!

I like the default prefix, unfortunately for my usage I don't have ones that are used regularly, but I see what you were doing there so that's great feedback. Thanks!

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Auto Number feedback
« Reply #3 on: December 29, 2008, 01:16:38 PM »
Did you want the suffix count to reset to 1 when 10 is hit? If so you need to change this portion:

             (strcat prefix
                     "_"
                     (if (> suffix 10)
                       (itoa (setq suffix 1))
                       (itoa suffix)
                     )
             )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

quamper

  • Guest
Re: Auto Number feedback
« Reply #4 on: December 29, 2008, 01:19:21 PM »
Did you want the suffix count to reset to 1 when 10 is hit? If so you need to change this portion:

No I wanted the 0 prefixing when it was less than 10

so Label_01, Label_02, Label_03 ... etc

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Auto Number feedback
« Reply #5 on: December 29, 2008, 01:20:41 PM »
Gotcha  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC