Re: Drawing number/name generator??

Aug 20, 2003 6 Replies


Having said all the above... I pose my question


> again.... does anyone have a utility or app that will
> generate such numbers? It would "remember" all the
> numbers previously generated....and make sure the new
> one is unique.... no matter WHO used the app.

There was a similar post, not too long ago in this group. It think the original poster found a solution and posted it. It's not exactly what you're looking for, but is similar.


I'd be willing to take a stab at something like that for you, though if you want it free, it would be on my timetable. It wouldn't be terribly difficult to program for you.


A couple of things to think about:


What do you want to store, number only, number and desription, etc.? Do you want to store a PLT file for each, as well? Do you have Access, Excel or similar file (goes to potential usability)?

Something like this?

(defun C:NUMGEN (/ fname numfile num nextnum) (if (setq fname (findfile "dwgnum.dat")) (progn (setq numfile (open fname "r")) (while (setq num (read-line numfile)) (setq nextnum num) );;while (if nextnum (setq nextnum (1+ (atoi nextnum))) (setq nextnum (1+ (* 100 (fix (getvar "cdate"))))) );;if );;progn (setq nextnum (1+ (* 100 (fix (getvar "cdate")))) numfile (open "dwgnum.dat" "w") );;setq );;if (close numfile) (while (not (findfile "dwgnum.dat"))) (if (/= (fix (/ nextnum 100))(fix (getvar "cdate"))) (setq nextnum (1+ (* 100 (fix (getvar "cdate"))))) );;if (setq numfile (open (findfile "dwgnum.dat") "a")) (write-line (itoa nextnum) numfile) (close numfile) (alert (strcat "Next available number is " (itoa nextnum))) (princ) ) ___

I thought the question was pretty clear:

The way I read it, he wants to "generate [unique] numbers." Period. ___

Wow Paul!

That was quick

Im very dumb abt LISP tho. How do i run this?

Do I run it from WITHIN Autocad itself? Or can it be run stand alone?

BTW..... THANKS!!

Inside of AutoCAD. First, cut and paste the routine into a file called NUMGEN.LSP, and place that file in your acad path. With AutoCAD open, type either APPLOAD and follow the prompts, or simply (load "numgen"). This adds a NUMGEN command to your AutoCAD installation; just type NUMGEN to use it.

There's a great deal of information on using AutoLISP and Visual LISP in the Customization Guide section of HELP.

...and here's a somewhat different version that actually generates a unique number and renames the current drawing (if it doesn't already have a compliant 10-digit name); instructions as above, but call the file NAMEGEN.LSP, and call it with NAMEGEN:

(defun C:NAMEGEN (/ fname numfile nextnum num) (if (setq fname (findfile "dwgnum.dat")) (progn (setq numfile (open fname "r")) (while (setq num (read-line numfile)) (setq nextnum num) );;while (if nextnum (setq nextnum (1+ (atoi nextnum))) (setq nextnum (gen)) );;if );;progn (setq nextnum (gen) numfile (open "dwgnum.dat" "w") );;setq );;if (close numfile) (while (not (findfile "dwgnum.dat"))) (if (not (wcmatch (substr (getvar "dwgname") 1 10) "##########")) (nameit) (progn (initget "Yes No") (setq yn (getkword "Drawing already named; do you want to RENAME it [Y/N]? ")) (if (= yn "Yes") (nameit) );;if );;progn );;if (princ) );;defun (defun nameit () (if (/= (fix (/ nextnum 100))(fix (getvar "cdate"))) (setq nextnum (gen)) );;if ___

Oops ... you'll need to include this subroutine in the NAMEGEN.LSP file as well:

(defun gen () (1+ (* 100 (fix (getvar "cdate")))) );;defun

...just add it to the end. ___

Could've been bad judgement on my part, but I didn't sense any likelyhood of it, from the initial post. ;)

Def> Because it's a good start, and it may encourage someone to "learn to fish." > ___

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required