Here you go-
Create yopur block with the correct insertion point and attributes then
cut and paste the following and replace the obvious.
use this format for the path
DRIVE:\\FILE FOLDER\\BLOCK_NAME_HERE.dwg
(defun c:lnm (/ new_num blk)
(setq blk "BLOCK_NAME_HERE")
(if (and (not (tblsearch "block" blk))
(not (setq blk (findfile "BLOCK PATH HERE")))
)
(alert (strcat "Routine requires attributed block \"lot number\" and I
could not find it."
"\nPlease make this block available and try again...."))
(progn
(createDict "jmm_Number")
(if (not (setq recList (getDictRec "jmm_Number" "last_num")))
(progn
(addDictRec "jmm_Number" "last_num" (list (cons 76 1)))
(setq recList (getDictRec "jmm_Number" "last_num"))
)
)
(if (not *last_num*)(setq *last_num* (cdr (car reclist))))
(cond
((setq new_num (getint (strcat "\nNumber to start numbering with ("
(itoa *last_num*)
") : ")))(start_lbl))
((setq new_num *last_num*)(start_lbl))
)
(princ)
)
)
)
(defun start_lbl (/ INSPT SCL)
(setq scl (getvar "dimscale"))
(while (setq insPt (getpoint "\nSelect next number Insertion Point: "))
(command "-insert" blk inspt scl scl 0.0 new_num)
(setq new_num (1+ new_num)
*last_num* new_num
)
(chgDictRec "jmm_Number" "last_num" (list (cons 76 *last_num*)))
)
)
;The following Dictionary functions are as posted to the
;Autodesk customization newsgroup by Juerg Menzi...he
;mentions that the origin is unknown.....
;
; -- Function CreateDict
; Creates a new or returns an existing dictionary.
; Arguments [Typ]:
; Nme = Name of the new dictionary [STR]
; Return [Typ]:
; > Entity name of new/existing dictionary [ENAME]
; Notes:
; None
;
(defun CreateDict (Nme / DicEnt NewDic TmpLst)
(if (not (setq NewDic (GetDictEnt Nme)))
(setq TmpLst '((0 . "DICTIONARY") (100 . "AcDbDictionary"))
DicEnt (entmakex TmpLst)
NewDic (dictadd (namedobjdict) Nme DicEnt)
)
NewDic
)
)
;
; -- Function DelDict
; Deletes the specified dictionary.
; Arguments [Typ]:
; Nme = Name of the dictionary to delete [STR]
; Return [Typ]:
; > Entity name [ENAME]
; Notes:
; None
;
(defun DelDict (Nme)
(dictremove (namedobjdict) Nme)
)
;
; -- Function AddDictRec
; Adds a record to a dictionary.
; Arguments [Typ]:
; Nme = Name of dictionary to access [STR]
; Key = Keyname for the record object [STR]
; Lst = Data list '((Key1 . Value1)...(Keyx . Valuex))
; Return [Typ]:
; > Entity name of modified dictionary [ENAME]
; Notes:
; None
;
(defun AddDictRec (Nme Key Lst / DicEnt TmpLst)
(setq TmpLst (append
'((0 . "XRECORD") (100 . "AcDbXrecord") (280 . 0))
Lst
)
DicEnt (entmakex TmpLst)
)
(dictadd (GetDictEnt Nme) Key DicEnt)
)
;
; -- Function GetDictRec
; Retrieves the data list by key from a dictionary.
; Arguments [Typ]:
; Nme = Name of dictionary to access [STR]
; Key = Keyname for the record object [STR]
; Return [Typ]:
; > Data list
; Notes:
; None
;
(defun GetDictRec (Nme Key)
(cdr (cddddr (cddddr (dictsearch (GetDictEnt Nme) Key))))
)
;
; -- Function ChgDictRec
; Redefines the specified record of a dictionary.
; Arguments [Typ]:
; Nme = Name of dictionary to access [STR]
; Key = Keyname for the record object [STR]
; Lst = Data list '((Key1 . Value1)...(Keyx . Valuex))
; Return [Typ]:
; > Entity name of modified dictionary [ENAME]
; Notes:
; None
;
(defun ChgDictRec (Nme Key Lst)
(if (GetDictRec Nme Key)
(progn
(DelDictRec Nme Key)
(AddDictRec Nme Key Lst)
)
)
)
;
; -- Function DelDictRec
; Deletes the specified record from a dictionary.
; Arguments [Typ]:
; Nme = Name of dictionary to access [STR]
; Key = Keyname for the record object [STR]
; Return [Typ]:
; > Entity name of modified dictionary [ENAME]
; Notes:
; None
;
(defun DelDictRec (Nme Key)
(dictremove (GetDictEnt Nme) Key)
)
;
; -- Function GetDictKeys
; Returns a list of keynames from the specified dictionary.
; Arguments [Typ]:
; Nme = Name of dictionary to access [STR]
; Key = Keyname for the record object [STR]
; Return [Typ]:
; > Key list
; Notes:
; None
;
(defun GetDictKeys (Nme / TmpLst)
(cond
((setq TmpLst (GetDict Nme)) (GetMassoc 3 TmpLst))
(T nil)
)
)
;
; -- Function GetDictKeysVals
; Returns a list of keynames with associated values from the
; specified dictionary.
; Arguments [Typ]:
; Nme = Name of dictionary to access [STR]
; Return [Typ]:
; > Key value list '((Key1 . Value1)...(Keyx . Valuex))
; Notes:
; None
;
(defun GetDictKeyVals (Nme)
(mapcar
'(lambda (l)
(cons l (cdar (GetDictRec Nme l)))
) (GetDictKeys Nme)
)
)
;
; -- Function ListDicts
; Returns a list of all dictionaries in the current drawing.
; Arguments [Typ]:
; --- =
; Return [Typ]:
; > List of dictionaries
; Notes:
; None
;
(defun ListDicts ()
(GetMassoc 3 (entget (namedobjdict)))
)
;
; -- Function GetDict
; Retrieves the entity definition list of the specified dictionary.
; Arguments [Typ]:
; Nme = Name of the dictionary [STR]
; Return [Typ]:
; > Entity definition of dictionary
; Notes:
; None
;
(defun GetDict (Nme)
(dictsearch (namedobjdict) Nme)
)
;
; -- Function GetDictEnt
; Retrieves the entity name of the specified dictionary.
; Arguments [Typ]:
; Nme = Name of the dictionary [STR]
; Return [Typ]:
; > Entity name of dictionary [ENAME]
; Notes:
; None
;
(defun GetDictEnt (Nme / TmpLst)
(cond
((setq TmpLst (GetDict Nme)) (GetAssoc -1 TmpLst))
(T nil)
)
)
;
; -- Function GetMassoc
; Get multiple associative values from a list.
; Arguments [Typ]:
; Key = Key to search [INT]
; Lst = Dotted pair list
; Return [Typ]:
; > List of values
; Notes:
; Published by T.Tanzillo
;
(defun GetMassoc (Key Lst)
(apply 'append
(mapcar
'(lambda (l) (if (eq (car l) Key) (list (cdr l)))) Lst
)
)
)
;
; -- Function GetAssoc
; Get associative value from a list.
; Arguments [Typ]:
; Key = Key to search [INT]
; Lst = Dotted pair list
; Return [Typ]:
; > Value [ALL]
; Notes:
; None
;
(defun GetAssoc (Key Lst)
(cdr (assoc Key Lst))
)
;(princ "\n\nType LOTNUM to start.")
(princ)