Lisp to loop through all polylines and let me know which ones do not have a text entity justified to MC inside of it

Lisp to loop through all polylines and let me know which ones do not have a text entity justified to MC inside of it

vporrash141089
Advocate Advocate
1,975 Views
24 Replies
Message 1 of 25

Lisp to loop through all polylines and let me know which ones do not have a text entity justified to MC inside of it

vporrash141089
Advocate
Advocate

Hi everyone,

 

I'm working on a large set of files for which I need to verify that the mc justification of the unique text entity is  within the polyline, if there are text mc not within the polyline then I would change these to color red, appreciate all the help possible and thanks in advance for all your help!

 

I was thinking that the routine could loop through all polylines and after it ends let me know which ones did not have a text entity.

 

Regards,

 

0 Likes
Accepted solutions (2)
1,976 Views
24 Replies
Replies (24)
Message 2 of 25

Moshe-A
Mentor
Mentor

@vporrash141089 hi,

 


@vporrash141089 wrote:

Hi everyone,

 

I'm working on a large set of files for which I need to verify that the mc justification in within the polyline appreciate all the help possible and thanks in advance for all your help!

 

I was thinking that the routine could loop through all polylines and after it ends let me know which ones did not have a text entity.

 

Regards,

 


by MC you mean Justification Middle Center of text or Middle Center of the polyline? 

 

Moshe

 

Message 3 of 25

vporrash141089
Advocate
Advocate

I mean mc of text 🙂

0 Likes
Message 4 of 25

Moshe-A
Mentor
Mentor

then why do you care about the polyline?

 

you can select the texts, go to properties\Justify select MiddleCenter job done 😀

0 Likes
Message 5 of 25

vporrash141089
Advocate
Advocate

The text must be inside the polyline, if I chage the justification with TJUST command it will change it's justification but won't help me identify the polylines that do not have that mc point inside of it. 

 

The point is that the routine would help me identify out of hundreds of polylines which are missing that mc point inside the polyline.

 

The mc of the text might be slightly outside of the polyline or the entire text entity could be outside which would generate an error farther along in the process.  

0 Likes
Message 6 of 25

Moshe-A
Mentor
Mentor

post a sample dwg which exhibit the problem

0 Likes
Message 7 of 25

vporrash141089
Advocate
Advocate

Here is the polyline drawing you will notice most of them are within the polyline I usually check one by one to make sure all of them have a text mc entity and if not in polyline then I move into the polyline. 🙂

0 Likes
Message 8 of 25

Moshe-A
Mentor
Mentor

@vporrash141089 ,

 

i asked for sample dwg which exhibit the problem, if all polylines have text inside then what is left here todo?

if you mean the text are outside the polyline and you manually move them in then, show us that drawing.

 

question:

say you have dozens of texts outside polylines, what are the criteria to move them in?

how do i know which text goes into which polyline?

 

Moshe

 

0 Likes
Message 9 of 25

vporrash141089
Advocate
Advocate

Sorry I should have been clearer, in the example there are a couple of text not inside a polyline... I probably should have said that polylines without text mc inside should be the least in the file. 

 

When you see the file I attached you assume it is correct, however like I said there are a couple I have identified and should move manually after the fact.

 

Meaning what I want the tool to do is change the color of the polylines that do not have a text justified to the middle center in them and so I can identify them faster, that is all.

 

Let's say you were doing what I'm doing you said it is good, but it isn't so wouldn't it be easier to run a tool that tells you right away which polyline need fixing? 🙂

 

I appreciate you looking into this so much! 

 

@Moshe-A I've added another drawing with what i imagine the highlight would be like

 

 

0 Likes
Message 10 of 25

Moshe-A
Mentor
Mentor

@vporrash141089 ,

 

check this HLPL command.

 

enjoy

Moshe

 

 

; highlight polyline
(defun c:hlpl (/ ss)

 ; return pline points 
 (defun vertices (ent)
  (vl-remove-if
   'not
   (mapcar
    '(lambda (itm)
      (if (= (car itm) 10) 
       (cdr itm)
      )
     ); lambda
    (entget ent)	    
   ); mapcar
  ); vl-remove-if
 ); vertices 


 ; here start c:hlpl 
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (if (setq ss (ssget '((0 . "*polyline"))))
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (if (not (ssget "_wp" (vertices ename) '((0 . "text"))))
    (command "._chprop" "_si" ename "_properties" "_color" "_truecolor" "237,31,36" "")
   )
  ); foreach 
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)

 (princ)
); c:hlpl

 

Message 11 of 25

vporrash141089
Advocate
Advocate

Hi @Moshe-A almost there! Thank you so much!

 

I have attached the result of the HLPL command and as you can see marked in yellow are several instances in which the middle center point of the text is withing the polyline yet it changes it to red color. 

 

It also grabs the ones I need to fix but if there is a way to only mark the ones where the mc of the text is out it would be awesome!

 

PD: Can this be restricted to a polyline in layer:

 


@vporrash141089 wrote:

Sorry I should have been clearer, in the example there are a couple of text not inside a polyline... I probably should have said that polylines without text mc inside should be the least in the file. 

 

When you see the file I attached you assume it is correct, however like I said there are a couple I have identified and should move manually after the fact.

 

Meaning what I want the tool to do is change the color of the polylines that do not have a text justified to the middle center in them and so I can identify them faster, that is all.

 

Let's say you were doing what I'm doing you said it is good, but it isn't so wouldn't it be easier to run a tool that tells you right away which polyline need fixing? 🙂

 

I appreciate you looking into this so much! 

 

@Moshe-A I've added another drawing with what i imagine the highlight would be like

 

 


; highlight polyline
(defun c:hlpl (/ ss)

 ; return pline points
 (defun vertices (ent)
  (vl-remove-if
   'not
   (mapcar
    '(lambda (itm)
      (if (= (car itm) 10)
       (cdr itm)
      )
     ); lambda
    (entget ent)        
   ); mapcar
  ); vl-remove-if
 ); vertices


 ; here start c:hlpl
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
 
 (if (setq ss (ssget '((0 . "*polyline")(8 . "SPACE"))))
  (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   (if (not (ssget "_wp" (vertices ename) '((0 . "text"))))
    (command "._chprop" "_si" ename "_properties" "_color" "1" "")
   )
  ); foreach
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)

 (princ)
); c:hlpl
 
Attached another example where it selects multiple "Correct" Polylines

Thank you!

0 Likes
Message 12 of 25

vporrash141089
Advocate
Advocate

@Moshe-A  Thank you for your code! 🙂

0 Likes
Message 13 of 25

john.uhden
Mentor
Mentor

@vporrash141089 ,

That could be a daunting task.  A number of questions come to mind:

  1. Might there be more than one MC text within a poyline?  If so, how, in your mind, would you decide which one "belongs to the polyline?"
  2. Are the polylines all closed?
  3.  Were the text objects placed at a specific distance from and and at an angle tangent to the nearest point on the polyline?
  4. Are the candidate text objects the only ones that are MC? 
  5. I presume you mean by "inside" that the insertion point is inside, because lengthy text and/or mtext with multiple lines might well have boundaries that are outside.  BTW, attempts using AutoLisp to determine if a point is inside our outside a polyline have been going on for decades.  Though I think I have come up with an excellent solution, it is tedious itself.
  6. Are the candidate texts and plines on unique layers?  I ask because the quantity of candidates will affect the duration of the process.  We can filter out ones that don't meet layer and justification criteria.

There is always a chance that such requests may fall into "the hand and eye are quicker than the code" category.  Please bear in mind that the talented contributors here may spend hours of their free time trying to solve a requester's problem, and receive nothing in return except a form of thanks, if the requester is so kind.  But they are all independently wealthy and have nothing else to do, so that doesn't matter.  🙄

John F. Uhden

Message 14 of 25

vporrash141089
Advocate
Advocate

Hi Sir,

 

  1. Might there be more than one MC text within a poyline?  If so, how, in your mind, would you decide which one "belongs to the polyline?" No that never happens because the drawing comes with an equal amount on text per polylines if these are missing I would fix that before tackling the mc issue.
  2. Are the polylines all closed? Yes - They should be closed
  3. Were the text objects placed at a specific distance from and and at an angle tangent to the nearest point on the polyline? No these are placed at random
  4. Are the candidate text objects the only ones that are MC? They should be however they belong to the layer SPACENAME
  5. I presume you mean by "inside" that the insertion point is inside, because lengthy text and/or mtext with multiple lines might well have boundaries that are outside.  BTW, attempts using AutoLisp to determine if a point is inside our outside a polyline have been going on for decades.  Though I think I have come up with an excellent solution, it is tedious itself. Correct but I might be wrong with this concept there is insertion point and justification point the one I care about is the justification point which would be mc
  6. Are the candidate texts and plines on unique layers?  I ask because the quantity of candidates will affect the duration of the process.  We can filter out ones that don't meet layer and justification criteria - The polylines are in layer SPACE and the text are in layer SPACENAME,  the text should be previously justified to mc by me manually I don't need a tool to do that TJUST works fine.

There is always a chance that such requests may fall into "the hand and eye are quicker than the code" category.  Please bear in mind that the talented contributors here may spend hours of their free time trying to solve a requester's problem, and receive nothing in return except a form of thanks, if the requester is so kind.  But they are all independently wealthy and have nothing else to do, so that doesn't matter.  

 

I do understand that and will be as clear as possible when asking for help. Thank you for looking in to this appreciate all your help!

 

Thank you for your time!! 

 

 

 

0 Likes
Message 15 of 25

Moshe-A
Mentor
Mentor

@vporrash141089 ,

 


@vporrash141089 wrote:

Hi @Moshe-A almost there! Thank you so much!

 

I have attached the result of the HLPL command and as you can see marked in yellow are several instances in which the middle center point of the text is withing the polyline yet it changes it to red color. 

 

It also grabs the ones I need to fix but if there is a way to only mark the ones where the mc of the text is out it would be awesome!

 

PD: Can this be restricted to a polyline in layer:

 

well,  the reason it works that way, is because your text is not completely inside the polyline. HLPL searches the polyline with window method. if we will change it to crossing method, it will work but that means any text that crosses the polyline will consider inside.

 

line #26 in code, replace to this line or just edit the red "_CP" instead "_wp"

 

(if (not (ssget "_cp" (vertices ename) '((0 . "text"))))

 

moshe

 

 

0 Likes
Message 16 of 25

ВeekeeCZ
Consultant
Consultant
Accepted solution

This marks all plines that do not have exactly 1 MC point inside.

 

(vl-load-com)

(defun c:MCOutside ( / *error* LM:UniqueFuzz s a z i s w e m)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if z (command-s "_zoom" "_p"))
    (setvar 'cmdecho 1)
    (if a (mapcar 'entdel a))
    (princ))
  
  ;; Lee Mac - http://www.lee-mac.com/uniqueduplicate.html#uniquefuzz
  (defun LM:UniqueFuzz ( l f ) (if l (cons (car l) (LM:UniqueFuzz (vl-remove-if (function (lambda ( x ) (equal x (car l) f))) (cdr l)) f))))
  
  (if (and (setq s (ssget "_X" '((0 . "LWPOLYLINE") (8 . "SPACE") (410 . "Model"))))
	   (setq a (ssget "_X" '((0 . "TEXT") (8 . "SPACENAME") (410 . "Model"))))
	   (setq a (vl-remove-if '(lambda (x) (/= 1 (cdr (assoc 72 (entget x))))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex a)))))
	   (setq a (mapcar '(lambda (x) (entmakex (list '(0 . "POINT") (cons 10 (cdr (assoc 11 (entget x))))))) a))
	   (setvar 'cmdecho 0)
	   (setq z (vl-cmdf "_.zoom" "_e"))
	   (setq m 0)
	   )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (if (or (not (setq w (ssget "_CP" (LM:UniqueFuzz (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget e))) 1e-6) '((0 . "POINT") (8 . "0")))))
	      (/= 1 (sslength w)))
	(progn
	  (setpropertyvalue e "Color" 1)
	  (setq m (1+ m))))))
  (if m (princ (strcat (itoa m) " polylines marked.")))
  (*error* "end")
  )

 

0 Likes
Message 17 of 25

vporrash141089
Advocate
Advocate

Hi @Moshe-A 

 

Tried it with the modification on line 26 and I get a similar result, it select the 1 polyline that is not correct but also selects other 4 plines where the text is completely in the polyline.

 

Thanks again, I appreciate your help! - See attached

0 Likes
Message 18 of 25

vporrash141089
Advocate
Advocate

Hi @ВeekeeCZ this looks very promising but when I execute the MCOUTSIDE i get the following error:

 

AVFx1410_0-1673966880117.png

 

Appreciate your help!!

0 Likes
Message 19 of 25

ВeekeeCZ
Consultant
Consultant

You are changing layer names!

 

Either you are consistent with layer naming so you can keep the layer filters, or not, then remove those filters and select all manually.

0 Likes
Message 20 of 25

vporrash141089
Advocate
Advocate

Hi @ВeekeeCZ, works great better than I expected actually, thank you so much for your help and your time invested in this!

 

Also, thanks to all! I appreciate your time and effort; this will help me very much.

 

You guys are amazing! 

 

 

0 Likes