Lisp - Closed Polyline

Lisp - Closed Polyline

Anonymous
Not applicable
1,536 Views
8 Replies
Message 1 of 9

Lisp - Closed Polyline

Anonymous
Not applicable

Hello

is there any lisp that checks if inside a closed polyline there is a label: text or mtext, and if it is not, it somehow marks this polyline, for example by changing its color?

Text, mtext is on the specified layer

Thanks for any help

0 Likes
1,537 Views
8 Replies
Replies (8)
Message 2 of 9

doaiena
Collaborator
Collaborator

This will get you started. Adjust it as you see fit.

 

(defun c:test ( / ss ctr ent)

(if (setq ss (ssget "_X" '((0 . "LWPOLYLINE") (70 . 1))))
(progn
(setq ctr 0)

(repeat (sslength ss)
(setq ent (ssname ss ctr))
(if (ssget "_WP" (mapcar 'cdr (vl-remove-if-not '(lambda (dxf) (= (car dxf) 10)) (entget ent))) '((0 . "TEXT,MTEXT")))
(command "_chprop" ent "" "_C" "1" "")
)
(setq ctr (1+ ctr))
);repeat

));if ss

(princ)
);defun
Message 3 of 9

Anonymous
Not applicable

This is almost what I mean.

I have attached a drawing to show what I mean.
Well, text 1365/61 is inside a closed polyline. The text insertion point is inside a closed polyline because the text itself extends beyond the boundaries. If the text insertion point is inside a closed polyline, it also tells me that the text is inside.

 

Edit: Text insertion point is outside of closed polyline. But I would like Lisp mark closed polyline when center of text was inside closed polyline

0 Likes
Message 4 of 9

doaiena
Collaborator
Collaborator

In that case, change this:
(ssget "_WP" (mapcar 'cdr (vl-remove-if-not '(lambda (dxf) (= (car dxf) 10)) (entget ent))) '((0 . "TEXT,MTEXT")))

to this:

(ssget "_CP" (mapcar 'cdr (vl-remove-if-not '(lambda (dxf) (= (car dxf) 10)) (entget ent))) '((0 . "TEXT,MTEXT")))

Message 5 of 9

john.uhden
Mentor
Mentor

Of course you realize that doesn't account for bulged segments.

You would have more accurate results by extracting points at a tight interval around the length of its perimeter, but even that would not be 100% accurate, but maybe good enough for the OP's purpose.

Then again you might improve the performance by extracting additional points only along bulged segments.

The subject of determining if a point is inside or outside or on a polyline has been discussed here at length for decades.  Search for "@inside revisited."  Maybe I found it...  here 

John F. Uhden

Message 6 of 9

doaiena
Collaborator
Collaborator

Yes @john.uhden, you are correct. The OP's definition of the problem was vague, so i wrote a skeleton function which would give him some direction (if he is familiar with autolisp). If he comes back and posts a detailed definition on what functionality he is seeking, there may be a completely different solution than the one i proposed.

Message 7 of 9

Anonymous
Not applicable

It almost solved my problem, but maybe my problem was imprecise. My point was to check if the text, and rather the text insertion point, is inside a closed polyline. It doesn't matter to me that the text passes after the polylines. the question is whether the insertion point is inside.

edit: as the insertion point I understand the middle of the text

0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

checks if inside a closed polyline there is a label: text or mtext, and if it is not, it somehow marks this polyline

....

mark closed polyline when center of text was inside closed polyline

....


Those are mutually contradictory.  Which condition should result in the Polyline being marked?

 

There are several threads you can Search for in this Forum about determining whether something is inside a Polyline.  I expect in this case the CP selection will be needed, and then Text/Mtext is found, its insertion point determined, and one of those routines used to check whether it's inside.

Kent Cooper, AIA
0 Likes
Message 9 of 9

Anonymous
Not applicable

sorry for the lack of precision.

this is correct:

and if it is not, it somehow marks this

0 Likes