Jump to content

Recommended Posts

Posted

Hello,

 

I have this Lisp that inserts a block with an attributes.

I use it to give a certain ID-number to doors, windows in drawings.

 

Attributes in block called _Doorlitt are as follows:

 

Tag: LITTERA

Prompt: Littera

Default: D_Litt

 

In block _Windows it looks the same as above.

 

When I insert it the blocks opens for editing, simple.

Now ... is it a way for the main lisp to have a built in function which sees the last number in an ID like D_001 and when the user inserts the Door ID again (same block) it checks for the last Default and auto adds D_00(2) ... JUST LAST number...

 

Thats important because sometimes a user might change the Default value to maybe Door_01 or Door1 or Door01 or maybe Door 1 (with space here).

So... is that possible for lisp to read the last number from a specific block called _Doorlitt and to add the last number+1 in the Default value?

If the user tries to change the last number it will still be renumbered to the last value.

 

Thanx

Posted

I found this lisp:

 

 

 

;; Increment Text lisp routine

;;

;; by: Irné Barnard

;; Version 1.2

;;

;; Version history

;; ==================================

;; 1.2

;; Added alphabetic increments

;;

;; 1.1

;; Add prefix / suffix

;; Add minimum digits

;;

;; 1.0

;; Initial version

;;

(setq INCRset '(1 "" "" 1 1 t)

alphalst

'("A" "B" "C" "D" "E" "F" "G" "H" "J" "K" "L" "M" "N" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"

)

) ;_ end of setq

;; Utility function to convert alpha number to integer

;|(defun alphatoi (a / i neg n)

(if (setq neg (= "-" (substr a 1 1)))

(setq a (substr a 2))

)

(setq i a n (strlen i) a "")

(while (> n 0)

(setq a (strcat a (substr i n 1)) n (1- n))

)

(setq i 0 n 1)

(while (

(if (= n (strlen a))

()

(setq i (+ i (* (vl-position (1- n) )

)

(setq n (1+ n))

)

(if neg (setq i (* i -1)))

i

)

|;

;; Utility function to convert integer to Alpha number

(defun itoalpha (i / a neg)

(setq neg (

i (abs (fix i))

a ""

) ;_ end of setq

(while (>= i 0)

(setq a (strcat (nth (rem i (length alphalst)) alphalst) a))

(setq i (- i (rem i (length alphalst))))

(setq i (fix (/ i (length alphalst))))

(if (= i 0)

(setq i -1)

(if (/= (rem i) 0)

(setq i (1- i))

) ;_ end of if

) ;_ end of if

) ;_ end of while

(if neg

(setq a (strcat "-" a))

) ;_ end of if

a

) ;_ end of defun

;; Command to increment text values by picking

(defun c:Increment (/ dcl_id obj objid id quit rate start value prfx sufx digits numerals)

(setq start (nth 0 INCRset)

prfx (nth 1 INCRset)

sufx (nth 2 INCRset)

rate (nth 3 INCRset)

digits (nth 4 INCRset)

numerals (nth 5 INCRset)

) ;_ end of setq

(defun Setup ()

(setq DCL_ID (load_dialog "Increment.DCL"))

(if (not (new_dialog "increment" DCL_ID))

(exit)

) ;_ end of if

(defun CHECKOUT ()

(setq start (atoi (get_tile "start")))

(setq prfx (get_tile "prefix")

sufx (get_tile "sufix")

) ;_ end of setq

(setq rate (if (= (atoi (get_tile "one")) 1)

"1"

(if (= (atoi (get_tile "two")) 1)

"2"

"0"

) ;_ end of if

) ;_ end of if

) ;_ end of setq

(setq rate (atoi (if (/= (atoi (get_tile "increase")) 1)

(strcat "-" rate)

rate

) ;_ end of if

) ;_ end of atoi

) ;_ end of setq

(setq digits (atoi (get_tile "digits")))

(setq numerals (= (get_tile "num") "1"))

(setq INCRset (list start prfx sufx rate digits numerals))

) ;_ end of defun

(defun DONE ()

(setq quit 1)

) ;_ end of defun

(if (/= start nil)

(set_tile "start" (itoa start))

) ;_ end of if

(if (/= prfx nil)

(set_tile "prefix" prfx)

) ;_ end of if

(if (/= sufx nil)

(set_tile "sufix" sufx)

) ;_ end of if

(if (/= digits nil)

(set_tile "digits" (itoa digits))

) ;_ end of if

(if numerals

(set_tile "num" "1")

(set_tile "alpha" "1")

) ;_ end of if

(if (/= rate nil)

(progn

(cond

((= rate 0) (set_tile "none" "1"))

((= rate 2) (set_tile "two" "1"))

((= rate -2) (set_tile "two" "1") (set_tile "decrease" "1"))

((= rate -1) (set_tile "decrease" "1"))

) ;_ end of cond

) ;_ end of progn

) ;_ end of if

(action_tile "accept" "(CHECKOUT)(done_dialog)")

(action_tile "cancel" "(DONE)(done_dialog)")

(start_dialog)

(unload_dialog DCL_ID)

) ;_ end of defun

(SETUP)

(while (/= quit 1)

[color=red] (while (and (/= quit 1) (not (or (= id "TEXT") (= id "MTEXT") (= id "ATTRIB"))))[/color]

(setq obj nil)

(if numerals

(progn

(setq value (itoa start))

(while (

) ;_ end of progn

(progn

(setq value (itoalpha start))

(while (

) ;_ end of progn

) ;_ end of if

(while (and (/= quit 1) (= obj nil))

(setvar "errno" 0)

(initget 4 "Change")

(setq obj (nentsel (strcat "\rSelect text...(" value ")[Change]")))

(cond

((= (getvar "errno") 52)

(setq quit 1

obj 1

) ;_ end of setq

)

((= obj "Change") (Setup) (setq obj nil))

((/= obj nil) (setq objid (entget (car obj))) (setq id (cdr (assoc 0 objid))))

) ;_ end of cond

) ;_ end of while

) ;_ end of while

(if (/= quit 1)

(progn

(setq objid (subst (cons 1 (strcat prfx value sufx)) (assoc 1 objid) objid))

(entmod objid)

(command "_updatefield" (car obj) "")

(entupd (car obj))

(setq INCRset (list start prfx sufx rate digits numerals))

(setq start (+ start rate))

(setq id nil)

(setq obj nil)

) ;_ end of progn

) ;_ end of if

) ;_ end of while

(princ)

) ;_ end of defun

;;; ROUND Arrondit

Posted

This works great.

 

Can it be tweaked to select a specific attribute if a block contains multiple attributes, for example a room name/number block?

 

Thanks

Derek

Posted

Which routine are you referring to?

 

ASMI's or the posted code?

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