Automatically edit text to reflect boundary areas from entire layer

Automatically edit text to reflect boundary areas from entire layer

mpa-la
Advocate Advocate
2,128 Views
28 Replies
Message 1 of 29

Automatically edit text to reflect boundary areas from entire layer

mpa-la
Advocate
Advocate

Hi all, I am looking for a lisp routine to help with a repetitive, multi step task.  Basically, I have layers that have a bunch of closed boundaries in them.  I need the area of all the boundaries on one layer converted to text with a comma in the right spot.  What I do now is as follows:  We have a layer highlight command, so I do that and exit it, then an area multiple command, issue that and use previous as the selection set (from the layer highlight command), that shows the number to me (no decimal points needed) on the command line, then I have to type it manually into my waiting text object, and put the comma in manually. 

 

The point of doing it this way is that I can have a hatches in my legend that are on the same layers with the boundaries.  Next to it is the text the quantity goes into, so I can just go down the legend, click the hatch to get the layer, then click the text to automatically input the quantity.  This saves me from doing a lot of layer isolation, and moving around in the drawing.

 

Btw, I don't want to insert a new text object, I want to edit an existing one that's already in my legend template.

 

 I've tried to do this myself by kind of combining the lisp routines, but I can't get it to work.  I hope somebody would enjoy taking on this challenge, or knows of something out there that already does this.

 

Thanks!!  Allison

0 Likes
Accepted solutions (1)
2,129 Views
28 Replies
Replies (28)
Message 21 of 29

mpa-la
Advocate
Advocate

I got it!!!  You mistyped a K instead of '+.   Mwah ha ha ha!!!

0 Likes
Message 22 of 29

ronjonp
Mentor
Mentor

It depends on what version of the code you're using .. I made one to choose left or right and one hardcoded to right.

From your example change (mapcar '+ p '(50 12 0)) (mapcar '+ p '(1.2 .27 0))

0 Likes
Message 23 of 29

mpa-la
Advocate
Advocate

Gotcha, we have the text to the right, so I'm still using that one.  I see why I got confused.  Thanks again so much!

0 Likes
Message 24 of 29

k_ngo-quoc
Enthusiast
Enthusiast

Hi Ronjonp,

Your lisp work great!

Many thanks again!

0 Likes
Message 25 of 29

ronjonp
Mentor
Mentor

@k_ngo-quoc Glad to help 🍻

0 Likes
Message 26 of 29

mpa-la
Advocate
Advocate

Hey Ronjon, hope you're having a great new year! 

 

We just realized that the lisp you helped me with last year is only including polylines in the calcs it makes.  How would I go about adding regions and circles (that's all I can think of that would have an area, if you think of anything else, that too) to the items it includes in the area calculation?  I have attached our current version of it below, I added a second half that works at a different scale for the text portion of the program.  Thanks in advance!

0 Likes
Message 27 of 29

ronjonp
Mentor
Mentor

@mpa-la wrote:

Hey Ronjon, hope you're having a great new year! 

 

We just realized that the lisp you helped me with last year is only including polylines in the calcs it makes.  How would I go about adding regions and circles (that's all I can think of that would have an area, if you think of anything else, that too) to the items it includes in the area calculation?  I have attached our current version of it below, I added a second half that works at a different scale for the text portion of the program.  Thanks in advance!


 

;;Change this
(setq s (ssget "_X" (list '(0 . "LWPOLYLINE") (assoc 8 (entget (car e))))))
;; to this :)
(setq s (ssget "_X" (list '(0 . "CIRCLE,*POLYLINE,REGION,SPLINE,ELLIPSE") (assoc 8 (entget (car e))))))

Like so:

(defun c:foo (/ rtoc a e s)
  ;; RJP » 2021-04-20
  (defun rtoc (n p / foo d l)
    ;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/1-000-comma-separator/m-p/5015892#M322341
    (defun foo (l n)
      (if (or (not (cadr l)) (= 46 (cadr l)))
	l
	(if (zerop (rem n 3))
	  (vl-list* (car l) 44 (foo (cdr l) (1+ n)))
	  (cons (car l) (foo (cdr l) (1+ n)))
	)
      )
    )
    (setq d (getvar 'dimzin))
    (setvar 'dimzin 0)
    (setq l (vl-string->list (rtos (abs n) 2 p)))
    (setvar 'dimzin d)
    (vl-list->string
      (append (if (minusp n)
		'(45)
	      )
	      (foo l (- 3 (rem (fix (/ (log (abs n)) (log 10))) 3)))
      )
    )
  )
  (while
    (and (setq e (entsel "\nPick legend hatch: "))
	 (setq
	   s (ssget "_X"
		    (list '(0 . "CIRCLE,*POLYLINE,REGION,SPLINE,ELLIPSE") (assoc 8 (entget (car e))))
	     )
	 )
	 (or (and (setq e (ssget "_C" (cadr e) (mapcar '- (cadr e) '(50 12 0)) '((0 . "*TEXT"))))
		  (setq e (ssname e 0))
	     )
	     (setq e (car (entsel "\nPick text to update: ")))
	 )
	 (setq a (apply '+ (mapcar 'vlax-curve-getarea (mapcar 'cadr (ssnamex s)))))
	 (entmod (append (entget e) (list (cons 1 (rtoc a 0)))))
    )
  )
  (princ)
)

 

0 Likes
Message 28 of 29

mpa-la
Advocate
Advocate

Omg, so simple!!  Thanks so much!

0 Likes
Message 29 of 29

mpa-la
Advocate
Advocate

Hmm, if there's a region included I get this error: "bad argument value: AcDbCurve 43".  If there's no easy fix, we very rarely have regions, they only get created when the boundary command spazzes out.  If we get the error, we can know to look for regions and get rid of them.

0 Likes