Trim multiple polylines from text (Contour Labels)

Trim multiple polylines from text (Contour Labels)

brendon_butler
Enthusiast Enthusiast
1,813 Views
12 Replies
Message 1 of 13

Trim multiple polylines from text (Contour Labels)

brendon_butler
Enthusiast
Enthusiast

Hi all!

 

I have an issue sometimes where consultants send us contours (polylines) with contour labels that haven't been trimmed to the contours. Therefore, the contour line runs through the labels, which makes the labels hard to read. I could mask the labels, but don't want to blank data such as hatch undernealth the labels.

 

So, what I'd like is a Lisp routine whereby I select multiple polylines and it trims from all or selected text. I can do this easily with the Trim command now, but only on an individual basis. I need to do this for hundreds / thousands of label entities.

 

If someone is able to help, I'd be much appreciative.

 

Cheers

Brendon

0 Likes
Accepted solutions (1)
1,814 Views
12 Replies
Replies (12)
Message 2 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

Brendon, hope you still need this. Then try and see. 

First you should isolate texts (labels) and contours. Then try and see - if the result is not good enough then try uncomment commented line (red).

 

Spoiler
(vl-load-com)

(defun c:TrimPlinesAroundText ( / *error* adoc text-box-off mxv LM:intersections ed en i pl ps ss)

  ;; Error
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (vla-endundomark adoc)
    (princ))
  
  ;; Text Box  -  gile / Lee Mac
  ;; Returns an OCS point list describing a rectangular frame surrounding
  ;; the supplied text or mtext entity with optional offset
  ;; enx - [lst] Text or MText DXF data list
  ;; off - [rea] offset (may be zero)
  (defun text-box-off (enx off / bpt hgt jus lst ocs org rot wid)
    (cond ((= "TEXT" (cdr (assoc 00 enx)))
	   (setq bpt (cdr (assoc 10 enx))
		 rot (cdr (assoc 50 enx))
		 lst (textbox enx)
		 lst (list (list (- (caar  lst) off) (- (cadar  lst) off)) (list (+ (caadr lst) off) (- (cadar  lst) off))
			   (list (+ (caadr lst) off) (+ (cadadr lst) off)) (list (- (caar  lst) off) (+ (cadadr lst) off)))))
	  ((= "MTEXT" (cdr (assoc 00 enx)))
	   (setq ocs  (cdr (assoc 210 enx))
		 bpt  (trans (cdr (assoc 10 enx)) 0 ocs)
		 rot  (angle '(0.0 0.0) (trans (cdr (assoc 11 enx)) 0 ocs))
		 wid  (cdr (assoc 42 enx))
		 hgt  (cdr (assoc 43 enx))
		 jus  (cdr (assoc 71 enx))
		 org  (list (cond ((member jus '(2 5 8)) (/ wid -2.0)) ((member jus '(3 6 9)) (- wid))      (0.0))
			    (cond ((member jus '(1 2 3)) (- hgt))      ((member jus '(4 5 6)) (/ hgt -2.0)) (0.0)))
		 lst (list (list (- (car org) off)     (- (cadr org) off))     (list (+ (car org) wid off) (- (cadr org) off))
			   (list (+ (car org) wid off) (+ (cadr org) hgt off)) (list (- (car org) off)     (+ (cadr org) hgt off))))))
    (if lst ((lambda ( m ) (mapcar '(lambda ( p ) (mapcar '+ (mxv m p) bpt)) lst))
	      (list (list (cos rot) (sin (- rot)) 0.0)
		    (list (sin rot) (cos rot)     0.0)
		    '(0.0 0.0 1.0)))))
  
  ;; Matrix x Vector  -  Vladimir Nesterovsky
  ;; Args: m - nxn matrix, v - vector in R^n
  (defun mxv (m v) (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))

  

  ;-------------------------------------------------------------------------------------------
  ;-------------------------------------------------------------------------------------------

  (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))

  (princ "\nSelect TEXTs or MTEXTs, or press <ENTER> to select them all: ")
  (if (or (setq ss (ssget '((0 . "*TEXT"))))
	  (setq ss (ssget "_X" '((0 . "*TEXT") (410 . "Model"))))
	  )
    (progn
      (command "_.ZOOM" "_E")
      (repeat (setq i (sslength ss))
	(setq ed (entget (setq en (ssname ss (setq i (1- i))))))
	(setq ps (text-box-off ed -0.1))
	; (command "_.ZOOM" "_Ob" en "")                    ; UNCOMMENT THIS LINE TO GET MORE PRECISE, BUT MUCH SLOWER
	(if (and (setq pl (ssget "_F" (mapcar '(lambda (x) (trans x 0 1)) ps) '((0 . "*POLYLINE"))))
		 (= 1 (sslength pl))
		 )
	  (progn
	    (command "_.TRIM" en "" "_F")
	    (foreach e (mapcar '(lambda (x) (trans x 0 1)) ps) (command e))
	    (command "" "")))
	))
    (princ "\nNo '*TEXT' selected."))
  (command "_.ZOOM" "_E")
  (*error* "end")
)

0 Likes
Message 3 of 13

giscivil92
Advocate
Advocate

Hi @ВeekeeCZ 

Unfortunately, it hasn't worked!

0 Likes
Message 4 of 13

hak_vz
Advisor
Advisor

@giscivil92  You don't need to trim polylines, at least I don't do it in similar job.

Instead, convert all contours elevations text entities to mtexts. Mtext has background mask property.

In express tools there is a tool for it. Convert each text entity separately,  otherwise it will all be joined to single mtext. Bring all this mtexts to front and use Lee Macs Background mask. In this way polylines are not trimmed and it helps when one has to create sections.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 13

Sea-Haven
Mentor
Mentor

I agree about mtext mask but post1 " I could mask the labels, but don't want to blank data". Another way may be to break but add a non plot line segment you will see it but it does not plot. If later on can rejoin the contour line and move the label. Even freeze the dummy connect layer.

0 Likes
Message 6 of 13

giscivil92
Advocate
Advocate

Hi @hak_vz Does this code have for Text ?

in fact that trim polyline under the text!

0 Likes
Message 7 of 13

john.uhden
Mentor
Mentor

@brendon_butler ,

IMHO, do NOT break anything.  Use Mtext and background masking.  Then use Draworder to establish the hierarchy of what is "on top of" other things.  Usually hatch belongs on the bottom (all the way back).  In fact AutoCAD provides a "HatchToBack" (maybe "Hatch2Back") command to make it easy.

John F. Uhden

0 Likes
Message 8 of 13

john.uhden
Mentor
Mentor

@giscivil92 , @brendon_butler :

I finally found my LabelCountour.lsp which uses background masking.

John F. Uhden

0 Likes
Message 9 of 13

giscivil92
Advocate
Advocate

Hi @john.uhden 

Thanks.

Can you update this code to define the interval distance for labels and select multiple polylines!?

0 Likes
Message 10 of 13

john.uhden
Mentor
Mentor

@giscivil92 ,

Thanks for asking, but no.  If I want to do group labeling of surface models I use Civil 3D.

My routine is intended to help those with only "vanilla" AutoCAD.

John F. Uhden

0 Likes
Message 11 of 13

Sea-Haven
Mentor
Mentor

Like CIV3D the civil package "Civil Site Design" does contour labelling automatically. 

0 Likes
Message 12 of 13

giscivil92
Advocate
Advocate

Greeting @Sea-Haven 

Can you show me, how can I do it!?

0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor

Civil Site Design or Stringer may suit your needs.

 

Home - Civil Site Design

Home - Civil Survey Solutions

0 Likes