AutoCAD LISP where I can select the Polyline which bounds the selected Text

AutoCAD LISP where I can select the Polyline which bounds the selected Text

josephacpromero
Community Visitor Community Visitor
460 Views
7 Replies
Message 1 of 8

AutoCAD LISP where I can select the Polyline which bounds the selected Text

josephacpromero
Community Visitor
Community Visitor

Hi, just a quick introduction on my work:

I work with countertop pieces (usually rectangles) that has a text inside them indicating which are Countertops, Splashes, Aprons.

Currently, I have to use select similar to the rectangular pieces, and quickselect to either by Area of Length of the polylines to be able to pinpoint which piece is which. This takes a long time if there are hundreds of pieces to work on.

What I want to achieve is to select similar on the text inside the closed polylines, quickselect for content so I can only select either Countertop, Splash, or Apron.
Then I want to use a command that selects the Polyline bounding the text instead of the texts that I initially selected.

I am but a construction draftsman so I have to ask the programming gurus for help.

Thank you.

0 Likes
461 Views
7 Replies
Replies (7)
Message 2 of 8

ronjonp
Advisor
Advisor

@josephacpromero 

Post a sample drawing. 

0 Likes
Message 3 of 8

Sea-Haven
Mentor
Mentor

This has been asked before if you can isolate the text and the outer pline/lines then you can get the insertion point of the text and then use BPOLY to make a new pline that matches your benchtop shape, then area & length etc.

 

A dwg would be good.

 

An example

 

(defun c:wow  ( / ss ent ent2 pt len parea)
(setq ss (ssget '((0 . "*TEXT"))))
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (1- x))))
(setq pt (cdr (assoc 10 (entget ent))))
(command "bpoly" pt "")
(setq ent2 (vlax-ename->vla-object  (entlast)))
(setq len (vlax-get ent2 'length))
(setq parea (vlax-get ent2 'Area))
(princ (strcat "\nArea is " ( rtos parea 2 2) " Length is " (rtos len 2 2)))
(vla-delete ent2)
)
(princ)
)
(c:wow)

 

 

0 Likes
Message 4 of 8

josephacpromero
Community Visitor
Community Visitor

Here's a sample of what I do

0 Likes
Message 5 of 8

josephacpromero
Community Visitor
Community Visitor

I think this is different for my intended use. I've attached a sample DWG for your reference.

Thank you.

0 Likes
Message 6 of 8

Sea-Haven
Mentor
Mentor

Ok I think I understand you need something like this to start with which gets objects in one panel.

 

(setq ss (ssget '((0 . "LWPOLYLINE")(8 . "COUNTER TOP,ISLAND,SPLASH,APRON"))))

Ok now you can get the length, width and name of every panel within an area.

 

Looking at dwg I think you want a "NESTING" solution you will need to google I can not help. You want a cutting sheet layout. 

0 Likes
Message 7 of 8

komondormrex
Mentor
Mentor

@josephacpromero 

hey there, check the following.

(defun find_outer_pline (text_ename / text_object fence_dist pline_sset outer_pline)
  (setq text_object (vlax-ename->vla-object text_ename)
	fence_dist 50
  )
  (while (not (setq pline_sset (ssget "_f" (list (vlax-get text_object 'insertionpoint)
						 (polar (vlax-get text_object 'insertionpoint) (+ pi (vla-get-rotation text_object)) fence_dist)
					   )
				          '((0 . "lwpolyline"))
			       )
	      )
	 )
    	 (setq fence_dist (+ 50 fence_dist))
  )
  (vl-some '(lambda (pline) (equal text_ename (ssname (ssget "_wp" (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 10 (car group))) (entget (setq outer_pline pline))))
								  '((0 . "text"))
						      ) 0
					      )
			    )
	    )
	    (vl-remove-if 'listp (mapcar 'cadr (ssnamex pline_sset)))
  )
  outer_pline
)
(defun c:change_outer_pline_layer (/ text_layer_list)
  	(setq text_layer_list '(("SPLASH"     . "SPLASH")
				("APRON"      . "APRON")
				("COUNTERTOP" . "COUNTER TOP")
				("PENINSULA"  . "ISLAND")
				("ISLAND"  . "ISLAND")
			       )
	)
	(foreach text (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget (list '(0 . "text") (cons 1 (apply 'strcat (cdr (apply 'append (mapcar '(lambda (text) (list "," text)) (mapcar 'car text_layer_list)))))))))))
	  	(entmod (append (entget (find_outer_pline text)) (list (cons 8 (cdr (assoc (cdr (assoc 1 (entget text))) text_layer_list))))))
	)
)
Message 8 of 8

ec-cad
Collaborator
Collaborator

Komondormrex,

Excellant !

Was working on it, but now, no need.

Works perfectly.

Cheers 🙂

ECCAD

0 Likes