Jump to content

Recommended Posts

Posted

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.

image.thumb.png.23abeab98e0db2cc198dfca34622c45b.png

Here is my block, thanks

 

block.dwg

Posted

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

 

  • Like 1
  • Thanks 1
Posted

This should get you most of the way there, though, it is written for text/mtext instead of attributes.

  • Thanks 1
Posted
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, 

Posted
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?

Posted

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

 

  • Thanks 1

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