Build list with the directions of the polylines

Build list with the directions of the polylines

adaptacad
Advocate Advocate
2,480 Views
27 Replies
Message 1 of 28

Build list with the directions of the polylines

adaptacad
Advocate
Advocate

There is a way to steal the direction a polyline is in accordance with the block, whether it is on the right, left, front or back and how many are in that direction.
and return a list like this ' ((2 "front") (0 "back") (2 "right") (1 "left"))
if someone helps me i will be very happy,
Thank you very much in advance!

 

adaptacad_0-1599768985241.png

 

 

0 Likes
Accepted solutions (1)
2,481 Views
27 Replies
Replies (27)
Message 2 of 28

Kent1Cooper
Consultant
Consultant

I'm not sure how to approach that, but clarify something:

FrontOrRight.PNG

According to the count, the red-circled diagonal line is apparently counted as going to the front, and the other diagonal one to the right.  But the red-circled one is closer in angle to the right than to the front.  What criteria determine what constitutes "front"-ward as opposed to "right"-ward?

Kent Cooper, AIA
Message 3 of 28

adaptacad
Advocate
Advocate

Thanks for the answer.
You're right, it was very confusing even for me.
it is not necessary to be very precise, the important thing is to indicate the direction and quantity.
so the understanding is better are basically these senses
return '((1 "N") (2 "E") (1 "NE") (1 "O"))

 

adaptacad_0-1599780274628.png

 

adaptacad_1-1599780314590.png

 

0 Likes
Message 4 of 28

doaiena
Collaborator
Collaborator

Here is my suggestion:

 

(pick a base point)

(foreach pline

(setq param (getParamAtPoint (getClosestPointTo base)))
(angle (getPointAtParam (fix param)) (getPointAtParam (+ (fix param) 1))
add to list etc...
)

 

Message 5 of 28

adaptacad
Advocate
Advocate

and how to do the comparison of the angles to know the direction ??
use the OR?
I still don't know how to do it!

0 Likes
Message 6 of 28

doaiena
Collaborator
Collaborator

This should get you started:

(defun c:test ( / ss pt ctr polyObj param ang lst)

(setq ss (ssget  '((0 . "LWPOLYLINE"))))
(setq pt (getpoint "\nPick a base point: "))

(if (and ss pt)
(progn

(setq ctr 0)
(repeat (sslength ss)
(setq polyObj (vlax-ename->vla-object (ssname ss ctr)))
(setq param (vlax-curve-getParamAtPoint polyObj (vlax-curve-getClosestPointTo polyObj pt)))
(setq ang (* 180.0 (/ (angle (vlax-curve-getPointAtParam polyObj (fix param)) (vlax-curve-getPointAtParam polyObj (+ (fix param) 1))) pi)))

(setq lst (cons ang lst))

(setq ctr (1+ ctr))
);repeat

(princ lst)
));if pt and ss

(princ)
);defun
Message 7 of 28

hak_vz
Advisor
Advisor
Accepted solution

Different approach to the problem

 

(defun c:indira ( / deg_to_rad pt p1 p2 anglist dirlist ss i ret)
(defun deg_to_rad (deg)(* pi (/ deg 180.0)))
(setq pt (getpoint "\nSelect centerpoint >"))
(setq anglist (mapcar 'deg_to_rad '(45 135 225 315 45)))
(setq dirlist '("N" "O" "S" "E"))
(setq i 0)
(foreach dir dirlist
(setq p1 (polar pt (nth i anglist) 5))
(setq p2 (polar pt (nth (+ i 1) anglist) 5))
(setq ss(ssget "F" (list p1 p2)))
(if ss (setq n (sslength ss)) (setq n 0))
(setq ret (cons (list n dir) ret))
(setq i (+ i 1))
)
(reverse ret)
)

(defun c:indira ( / deg_to_rad pt p1 p2 anglist dirlist ss i ret)
(defun deg_to_rad (deg)(* pi (/ deg 180.0)))
(setq pt (getpoint "\nSelect centerpoint >"))
(setq anglist (mapcar 'deg_to_rad '(22.5 67.5 112.5 157.5 202.5 247.5 292.5 337.5 22.5)))
(setq dirlist '("NE" "N" "NO" "O" "SO" "S" "SE" "E"))
(setq i 0)
(foreach dir dirlist
(setq p1 (polar pt (nth i anglist) 5))
(setq p2 (polar pt (nth (+ i 1) anglist) 5))
(setq ss(ssget "F" (list p1 p2)))
(if ss (setq n (sslength ss)) (setq n 0))
(setq ret (cons (list n dir) ret))
(setq i (+ i 1))
)
(reverse ret)
)

 

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 8 of 28

Kent1Cooper
Consultant
Consultant

@adaptacad wrote:

.... to indicate the direction and quantity.
so the understanding is better are basically these senses
return '((1 "N") (2 "E") (1 "NE") (1 "O"))

....

adaptacad_1-1599780314590.png


But that should be determining angles not  in relation to absolute compass directions, but as directions relative to the rotation of the Block, if I understand the image in Message 1 correctly.

 

I see a problem with the nature of the Polylines.  The long horizontal above is one Polyline all the way across [though at least it has a vertex in the middle], so the same Polyline extends in more than one direction from the Block, and that is in its drawn  direction on one side but in the opposite  direction on the other side.  Likewise for the two diagonals, which are a single Polyline.  In other situations in the sample drawing, there are L-shaped 2-segment ones, and some that extend in only one direction with a single segment.  It would be difficult to find an approach that can account for all those possibilities, and would be much easier if all  of them were separate ones, with none continuing through at the middle.  I think @doaiena 's suggestion assumes they are separate, since it looks at each Polyline only once, not one segment at a time.  That can give only one result per Polyline, but you are looking for two results from many of your Polylines.

 

But even if they were all separate pieces, that approach could, I think, give opposite-direction results in some cases if any are drawn in the inward  direction, depending on the specific position of their inward end relative to the reference point or the Block.  If the nearest point of one drawn inward is at the downstream end, there will be no next parameter value, so the angle measurement will fail.  If the nearest point on it isn't at the very end, whether User-selected or based on the Block's insertion point, then the rounded-down parameter will be at the outward  end, and the angle will be measured in the opposite direction from the one intended.  This would be the case, for example, in the upper non-orthogonal situation if its lower-right Polyline were drawn from the outside in, instead of the way it is, and if the reference point is the Block insertion point.  @doaiena's suggestion asks the User for the reference point, but it would make sense to me to have that taken from the Block, since the Block needs to be selected anyway, if the angle determinations are to be relative to its rotation angle.

 

Also, are they always  Polylines, or might they sometimes be Lines, or something else?

Kent Cooper, AIA
0 Likes
Message 9 of 28

doaiena
Collaborator
Collaborator

In my post i just set up a general framework, upon which @adaptacad could expand. As you have already said, there are many more questions that need to be answered in order to provide a complete solution. The OP should jump in and post a very detailed explanation of what exactly needs to happen, including all the edge cases he could think of.

0 Likes
Message 10 of 28

adaptacad
Advocate
Advocate

@hak_vz  This was perfect !! thank you very much!

0 Likes
Message 11 of 28

adaptacad
Advocate
Advocate

(defun c:indira ( / deg_to_rad pt p1 p2 anglist dirlist ss i ret)
(defun deg_to_rad (deg)(* pi (/ deg 180.0)))
(setq pt (getpoint "\nSelect centerpoint >"))
(setq anglist (mapcar 'deg_to_rad '(22.5 67.5 112.5 157.5 202.5 247.5 292.5 337.5 22.5)))
(setq dirlist '("NE" "N" "NO" "O" "SO" "S" "SE" "E"))
(setq i 0)
(foreach dir dirlist
(setq p1 (polar pt (nth i anglist) 5))
(setq p2 (polar pt (nth (+ i 1) anglist) 5))
(setq ss (ssget "F" (list p1 p2)))
(if ss (setq n (sslength ss)) (setq n 0))
(setq ent (ssname ss i))
(setq clr (cdr (assoc 62 (entget ent))))
(setq ret (list clr n dir))
;(setq ret (cons (list n dir) ret))
(setq i (+ i 1))
)
(reverse ret)
)

 

 

Why not add color ??

 

 

0 Likes
Message 12 of 28

hak_vz
Advisor
Advisor

You can do what ever you like. Just define what you would like.

 

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 13 of 28

Kent1Cooper
Consultant
Consultant

@adaptacad wrote:

....
(setq anglist (mapcar 'deg_to_rad '(22.5 67.5 112.5 157.5 202.5 247.5 292.5 337.5 22.5)))
(setq dirlist '("NE" "N" "NO" "O" "SO" "S" "SE" "E"))
....
(setq p1 (polar pt (nth i anglist) 5))
(setq p2 (polar pt (nth (+ i 1) anglist) 5))
(setq ss (ssget "F" (list p1 p2)))
....

I'm wondering [without trying it]....  If a Line or Polyline or whatever lies exactly on  one of those break-point directions, such as 22.5°, won't it be touched by the Fence selection for two  of the octants, and therefore be counted twice?  Maybe you would want it counted for both octants, but if not, some criteria would be needed for which of them to include it in.

 

[Also, I don't know the typical circumstances, but that 5 for the distance from the center in setting p1 & p2 requires that all objects to be found must come at least to within 5 drawing units of the center at their inner end, and extend at least to 5 drawing units away at their outer end.  Would that always be the case?]

Kent Cooper, AIA
0 Likes
Message 14 of 28

adaptacad
Advocate
Advocate

It's perfect like you did.
I just don't understand how I can add color to the list.
what's wrong with my editing?

0 Likes
Message 15 of 28

adaptacad
Advocate
Advocate

@Kent1Cooper  I don't understand what you mean, can you give me an example ??
in all the tests I did the @hak_vz routine) it worked perfectly.

0 Likes
Message 16 of 28

Kent1Cooper
Consultant
Consultant

@adaptacad wrote:

@Kent1Cooper  I don't understand what you mean, can you give me an example ?? ....


When I do this:

indira1.JPG

yellow-to-green should be the Fence for the NorthEast octant, and it should find both  the 22.5° and 67.5° lines.  And green-to-cyan should be the Fence for the North octant, and it should find both  the 67.5° and 112.5° lines.  Using the indira command on them returns this:

((0 "NE") (1 "N") (1 "NO") (0 "O") (0 "SO") (0 "S") (0 "SE") (1 "E"))

 

It's seeing all three lines, only once each, but note that two of them [N, NO] are being counted in the octant that is counterclockwise  from the line's direction, but one [E] is being counted in the octant that is clockwise  from the line's direction.

 

I assume the fact that none of them is being counted in two  adjacent octants is a rounding issue in the degrees-to-radians calculations, and the Fence endpoints are not always precisely on the octant break directions, but these lines are.  I tried it on this:
indira2.JPG

with all  of the octant-dividing directions, and this was returned:

((0 "NE") (2 "N") (0 "NO") (2 "O") (0 "SO") (2 "S") (1 "SE") (1 "E"))

 

Some octants are not "given" any lines, some are given 1, and some 2.  It may not be that some of those lines are being counted twice in two adjacent octants, because two of the Fences in the selections touch them [which is what I suspected might happen in my previous Reply], but at least some Fences are seeing the lines at both ends of them, and some are not seeing the line at either end.

Kent Cooper, AIA
Message 17 of 28

adaptacad
Advocate
Advocate

Wow! I am always surprised by the technical look of you !!!

This is really a @Kent1Cooper  problem and I haven't checked it out!

0 Likes
Message 18 of 28

adaptacad
Advocate
Advocate

but at the moment I don't understand how to get the name of the entity to get the color of the polyline and add to the list.

0 Likes
Message 19 of 28

Kent1Cooper
Consultant
Consultant

I tried a different approach to the angle calculations:

 

(setq anglist '(1 3 5 7 9 11 13 15 1))
....
(setq p1 (polar pt (* pi (/ (nth i anglist) 8.0)) 5))
(setq p2 (polar pt (* pi (/ (nth (+ i 1) anglist) 8.0)) 5))

 

and got this result [different varieties of the same problem]:

((1 "NE") (0 "N") (1 "NO") (1 "O") (2 "SO") (0 "S") (2 "SE") (1 "E"))

Kent Cooper, AIA
Message 20 of 28

adaptacad
Advocate
Advocate

@Kent1Cooper  The chance of this influencing is very small !! I believe it will be in very, very rare cases.

0 Likes