leonucadomi Posted May 13 Posted May 13 hello all: Excuse me for insisting on the issue of numbering but. I use this block , and they ask me to number pieces from left to right and from top to bottom I know that AutoLabelAttributesV1-4.lsp from the master Lee Mac performs automatic numbering I would like to know if there is any routine that numbers by doing a ssget requesting the number on which it starts Or if possible, not only make the selection in the window, but also click on each of the blocks. Here is my block, thanks block.dwg Quote
BIGAL Posted May 14 Posted May 14 A fairly simple task based on the smaple dwg. (defun c:numblk ( / ss num lst obj atts att1 numstr) (while (setq ss (ssget '((0 . "insert")))) (setq num (getint "\nEnter start number ")) (setq lst '()) (repeat (setq k (sslength ss)) (setq ent (entget (ssname ss (setq k (1- k))))) (setq inspt (cdr (assoc 10 ent))) (setq x (car inspt) y (cadr inspt)) (setq entname (cdr (assoc -1 ent))) (setq lst (cons (list Y X entname) lst)) ) (setq lst (vl-sort lst '(lambda (a b) (cond ((> (car a) (car b))) ((= (car a) (car b)) (< (cadr a) (cadr b))) ) ) ) ) (foreach blk LST (setq obj (vlax-ename->vla-object (caddr blk))) (setq atts (vlax-invoke obj 'Getattributes)) (setq att1 (car atts)) (cond ((< num 10)(setq numstr (strcat "00" (rtos num 2 0)))) ((< num 100)(setq numstr (strcat "0" (rtos num 2 0)))) ((setq numstr (rtos num 2 0))) ) (vlax-put att1 'textstring numstr) (setq num (1+ num)) ) ) (princ) ) 1 1 Quote
Lee Mac Posted May 14 Posted May 14 This should get you most of the way there, though, it is written for text/mtext instead of attributes. 1 Quote
leonucadomi Posted May 14 Author Posted May 14 12 hours ago, BIGAL said: A fairly simple task based on the smaple dwg. (defun c:numblk ( / ss num lst obj atts att1 numstr) (while (setq ss (ssget '((0 . "insert")))) (setq num (getint "\nEnter start number ")) (setq lst '()) (repeat (setq k (sslength ss)) (setq ent (entget (ssname ss (setq k (1- k))))) (setq inspt (cdr (assoc 10 ent))) (setq x (car inspt) y (cadr inspt)) (setq entname (cdr (assoc -1 ent))) (setq lst (cons (list Y X entname) lst)) ) (setq lst (vl-sort lst '(lambda (a b) (cond ((> (car a) (car b))) ((= (car a) (car b)) (< (cadr a) (cadr b))) ) ) ) ) (foreach blk LST (setq obj (vlax-ename->vla-object (caddr blk))) (setq atts (vlax-invoke obj 'Getattributes)) (setq att1 (car atts)) (cond ((< num 10)(setq numstr (strcat "00" (rtos num 2 0)))) ((< num 100)(setq numstr (strcat "0" (rtos num 2 0)))) ((setq numstr (rtos num 2 0))) ) (vlax-put att1 'textstring numstr) (setq num (1+ num)) ) ) (princ) ) excellent thanks, Quote
PGia Posted May 14 Posted May 14 19 hours ago, BIGAL said: A fairly simple task based on the smaple dwg. (defun c:numblk ( / ss num lst obj atts att1 numstr) (while (setq ss (ssget '((0 . "insert")))) (setq num (getint "\nEnter start number ")) (setq lst '()) (repeat (setq k (sslength ss)) (setq ent (entget (ssname ss (setq k (1- k))))) (setq inspt (cdr (assoc 10 ent))) (setq x (car inspt) y (cadr inspt)) (setq entname (cdr (assoc -1 ent))) (setq lst (cons (list Y X entname) lst)) ) (setq lst (vl-sort lst '(lambda (a b) (cond ((> (car a) (car b))) ((= (car a) (car b)) (< (cadr a) (cadr b))) ) ) ) ) (foreach blk LST (setq obj (vlax-ename->vla-object (caddr blk))) (setq atts (vlax-invoke obj 'Getattributes)) (setq att1 (car atts)) (cond ((< num 10)(setq numstr (strcat "00" (rtos num 2 0)))) ((< num 100)(setq numstr (strcat "0" (rtos num 2 0)))) ((setq numstr (rtos num 2 0))) ) (vlax-put att1 'textstring numstr) (setq num (1+ num)) ) ) (princ) ) Hi @BIGAL I've found that this vl-sort formula for sorting objects in a row only works correctly when the objects are properly aligned. But when they've been manually aligned and there's even a slight discrepancy, it fails. Is there a way to fix this? Quote
BIGAL Posted May 15 Posted May 15 Possibly the only way around having a tolerance on the Y would be to use some form of selection order, but that removes the automation. The other way may be to say round the Y value before saving in the lst list. if say objects have a Y of 20.25 & 19.9 then they could be rounded to 20. There is rounding code out there. Have a go. https://www.lee-mac.com/round.html 1 Quote
Recommended Posts
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.