Autonumbering rectangle (same height/length/orientation)

Autonumbering rectangle (same height/length/orientation)

ccsmith25
Contributor Contributor
2,876 Views
22 Replies
Message 1 of 23

Autonumbering rectangle (same height/length/orientation)

ccsmith25
Contributor
Contributor

I've already found a file what can add number in center of each selected rectangle. - see attachment (demo.lsp)

Unfortunatelly I am not an expert in autolisp so I would like to ask for some support.

Is it possible to modify the function to add the same number to each rectangulars where the height/width and orientation is the same?

sample.jpg

The rectangulars are placed orthogonal. No 45° or any different orientation like 0°; 90°; 270°.

Thank you in advance for the answers.

Any help is greatly appreciated!

0 Likes
Accepted solutions (3)
2,877 Views
22 Replies
Replies (22)
Message 2 of 23

pbejse
Mentor
Mentor

@ccsmith25 wrote:

Is it possible to modify the function to add the same number to each rectangulars where the height/width and orientation is the same?


300x200 not the same as 200x300 correct?

 

 

0 Likes
Message 3 of 23

ccsmith25
Contributor
Contributor

It is correct. It is two difference elements.  ID1=300x200mm and ID2=200x300mm.

0 Likes
Message 4 of 23

pbejse
Mentor
Mentor

@ccsmith25 wrote:

It is correct. It is two difference elements.  ID1=300x200mm and ID2=200x300mm.


Was hoping you would say they are the same 😆 Its way more easy.

The additonal code could be really simple depending on how those Polylines were created @ccsmith25 . For now I will assume it was created the same way for all.

 

0 Likes
Message 5 of 23

pbejse
Mentor
Mentor
Accepted solution
(defun c:demo (/ TxtHt	sn     ss     i	     e	    sum	   verts
		 ptList	p      RefData	     bbox   pts	   Len
		 Wid	l&W
		)
  (initget 7)
  (if (and
	(setq TxtHt (getreal "\nEnter Text Height: "))
	(setq sn (initget 7)
	      sn (getint "\nEnter Start Number: ")
	)
	(setq ss (ssget '((0 . "LWPOLYLINE"))))
      )

    (repeat (setq i (sslength ss))
      (setq e	  (ssname ss (setq i (1- i)))
	    sum	  '(0 0)
	    verts (cdr (assoc 90 (entget e)))
      )
      (setq ptList
	     (mapcar 'cdr
		     (vl-remove-if-not
		       '(lambda (x) (= (car x) 10))
		       (entget e)
		     )
	     )
      )
      (foreach x ptList (setq sum (mapcar '+ x sum)))
      (setq p (mapcar '/ sum (list verts verts)))

;;  Because we are not sure how the LWPOLYLINES are created	;;
;;  pBe July 2020						;;
      
      (setq bbox (Vla-getboundingbox (vlax-ename->vla-object e) 'll 'ur))
      (setq pts (mapcar 'vlax-safearray->list (list ll ur)))

      (setq Len  (vl-princ-to-string (- (caadr pts)(caar pts))))
      (setq Wid  (vl-princ-to-string (- (cadadr pts)(cadar pts))))
      (setq l&W  (strcat Len "X" Wid))
 
;;								;;

      (entmakex
	(list
	  (cons 0 "TEXT")
	  (cons 10 p)
	  (cons 11 p)
	  (cons 40 TxtHt)
	  '(50 . 0.0)
	  '(72 . 4)
	  '(73 . 3)
;;  pBe July 2020						;;
	  (cons	1
		(cond
		  ((setq f (assoc l&W RefData))
		   (cadr f)
		  )
		  ((setq RefData (cons (list l&W (itoa sn)) RefData))
		   (setq sn (1+ sn))
		   (cadar RefData)
		  )
		)
	  )
;; 								;;
	)
      )
    )
  )
  (princ)
)

HTH

 

BTW: would you happen to know who the original author is? 

 

0 Likes
Message 6 of 23

ccsmith25
Contributor
Contributor

Hi,

Thanks for your solution. it is working properly. Could you modify the program to add 25 unit offset of the TEXT in height from the center?

I found the orignal LISP: https://www.cadtutor.net/forum/topic/46252-autonumbering-of-selected-rectangles/

 

0 Likes
Message 7 of 23

Kent1Cooper
Consultant
Consultant

EDITED:

I agree the bounding-box approach is better.  But I would do it before  the calculation of the midpoint for the Text insertion point. Then all this:

 

	    sum	  '(0 0)
	    verts (cdr (assoc 90 (entget e)))
      )
      (setq ptList
	     (mapcar 'cdr
		     (vl-remove-if-not
		       '(lambda (x) (= (car x) 10))
		       (entget e)
		     )
	     )
      )
      (foreach x ptList (setq sum (mapcar '+ x sum)))
      (setq p (mapcar '/ sum (list verts verts)))

 

can be replaced with just:

 

      (setq p (mapcar '/ (mapcar '+ (car pts) (cadr pts)) '(2 2 2)))

 

 

 

 

Kent Cooper, AIA
Message 8 of 23

ccsmith25
Contributor
Contributor

Can I ask for another favor?

Once the lenght and width are collected (l&W) we could also write this data.

Could you modify the output text to contain the id, width and lenght data in format: ID.1_L300xW500?

I appreciate your effort.

Thanks is advance.

0 Likes
Message 9 of 23

pbejse
Mentor
Mentor

@ccsmith25 wrote:

... add 25 unit offset of the TEXT in height 

Could you modify the output text to contain the id, width and lenght data in format: ID.1_L300xW500?

 

Is that 25% of the text height or 25 regardless of the text height?

Let me guess, you wanted the text rotated to 90% if W is longer than L?

Tell me before i post the modified code incorporating @Kent1Cooper suggestion for the TEXT insertion point.

 

 

0 Likes
Message 10 of 23

ccsmith25
Contributor
Contributor

Sorry for confusing. I meant that I would like to offset the position of text in height by 25 units (mm).  

Also concatenate ID., length, width data in following form. No need to rotate the text. It is always positioned at 0°.

ccsmith25_1-1595143876425.png

Thanks for your help in this matter.

0 Likes
Message 11 of 23

pbejse
Mentor
Mentor
Accepted solution

@ccsmith25 wrote:

Sorry for confusing. I meant that I would like to offset the position of text in height by 25 units (mm).  

Also concatenate ID., length, width data in following form. No need to rotate the text. It is always positioned at 0°.


Here you go [ refer to attached lsp file ]

Command: LabelTheBox
Enter Text Height: 25
Enter Start Number: 1
Select objects: Specify opposite corner: 3 found

HTH

 

0 Likes
Message 12 of 23

Sea-Haven
Mentor
Mentor

A suggestion or 2, search the text on a layer get last ID number. Its pushing my own wheel barrow the Multi getvals.lsp you can save a value for use in the dcl the default value just needs to be reset.

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(if (= ah-num nil) (setq ah-num "1"))
(if (= ah-txtht nil)(setq ah-txtht "2.5"))
(setq ans (AH:getvalsm (list "Enter values" "Text height" 5 4 ah-txtht "Enter start number" 5 4 ah-num)))
; do your thing then set ah-num and ah-txtht
0 Likes
Message 13 of 23

pbejse
Mentor
Mentor

@Sea-Haven wrote:

A suggestion or 2, search the text on a layer get last ID number...


You may have something there @Sea-Haven.

 

(setq existing (ssget "_X" '((0 . "TEXT")(1 . "ID.*_L*xW*"))))

 

 

 

0 Likes
Message 14 of 23

ccsmith25
Contributor
Contributor

I am grateful for you help. It is working very well. 

0 Likes
Message 15 of 23

ccsmith25
Contributor
Contributor

Hi! Could you change the LISP to the result precision will be 0 instead of 0.0?

Is it possible to use MULTITEXT instead of TEXT? I would like to add a new line after ID. 

0 Likes
Message 16 of 23

pbejse
Mentor
Mentor

@ccsmith25 wrote:

Hi! Could you change the LISP to the result precision will be 0 instead of 0.0?

Is it possible to use MULTITEXT instead of TEXT? I would like to add a new line after ID. 


Yes, easy. If your adding a new line as part of the MTEXT, then i guess you dont need that 25Omm offset??  What is the source /value of the new line? 

 

0 Likes
Message 17 of 23

ccsmith25
Contributor
Contributor

No need the offset in this case.

The text format will be like below. Middle centered justify. In first line the ID. and the second one the dimension with 0 precision. (Example 792 and not 792.0). 

ccsmith25_0-1595181940686.png

 

0 Likes
Message 18 of 23

pbejse
Mentor
Mentor
Accepted solution

@ccsmith25 wrote:

No need the offset in this case.

The text format will be like below. Middle centered justify. In first line the ID. and the second one the dimension with 0 precision. (Example 792 and not 792.0). 


 No problem.. here you go...

(entmakex
	(list
	  (cons 0 "MTEXT")
	  (cons 100 "AcDbEntity")
          (cons 100 "AcDbMText")
	  (cons 10 p)
	  (cons 40 TxtHt)
	  '(50 . 0.0)
	  '(71 . 5) 	   
	  '(72 . 5)
	  '(73 . 1)	  
	  (cons	1
		(cond
		  ((setq f (assoc (setq size (strcat "L" Len "xW" Wid)) RefData))
			  (strcat "ID." (Cadr f) "\\P" size)
		  )
		  ((setq RefData (cons (list size (itoa sn) ) RefData))
		   (setq sn (1+ sn))
		    (strcat "ID." (cadar  RefData) "\\P" size)
		  )
		)
	  )
	)
      )

Please refer to attached lisp file [ LabelTheBox 2.0.LSP ]

 

HTH

 

0 Likes
Message 19 of 23

ccsmith25
Contributor
Contributor

Thanks for your previous solution. It is working like a charm.

Hi! Does LISP allow to add two different text height in multitext like this below?

ccsmith25_0-1595251903516.png

First row text height would be double than the second line.

0 Likes
Message 20 of 23

pbejse
Mentor
Mentor

@ccsmith25 wrote:

Thanks for your previous solution. It is working like a charm.

Hi! Does LISP allow to add two different text height in multitext like this below?


You have exceeeded the maximum number of request.

Please deposit 40USD to this account

 

77 121 32 110 97 109 101 32 105 115 32 80 97 116 114 105 99 107 44 32 78 105 99 101 32 116 111 32 109 101 101 116 32 121 111 117 33

 

😁

This time i will let you modify the code on your own.

Check the string on the  existing MTEXT you manually configured, look at the Contents value at Properties dialog.

make note of the formating. See if you can figure out the bit where the control for the mext height for the secondline

 

Hint: strcat