Give Line direction clock wise

Give Line direction clock wise

avinash00002002
Collaborator Collaborator
418 Views
27 Replies
Message 1 of 28

Give Line direction clock wise

avinash00002002
Collaborator
Collaborator

Hi!

I need help that I have select a line at any direction it always give me clockwise direction p1 and p2 point.

Avinash

0 Likes
Accepted solutions (1)
419 Views
27 Replies
Replies (27)
Message 21 of 28

komondormrex
Mentor
Mentor

check the following

(defun c:mark_line_ends (/ line_object line_mid_point delta_x_y delta_x_y line_start line_end) 
	(setq line_object (vlax-ename->vla-object (car (entsel "\nPick line: ")))
	      line_mid_point (polar (vlax-get line_object 'startpoint) (vla-get-angle line_object) (* 0.5 (vla-get-length line_object)))  
	      delta_x_y (mapcar '- (vlax-get line_object 'startpoint)  (vlax-get line_object 'endpoint) '(0 0))
	)
  	(if (< (abs (car delta_x_y)) 1e-9)
	  (setq line_angle (* 1.5 pi)) 
	  (setq line_angle (atan (apply '/ (reverse delta_x_y))))
	)
  	(mapcar '(lambda (text line_point) (vla-addtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
				       		       text
					    	       (vlax-3d-point line_point)
					     	       25
					   )
		 )
		'("P1" "P2")
		 (list
	   	 	(polar (setq line_start (polar line_mid_point (+ pi line_angle) (* 0.5 (vla-get-length line_object)))) (- (+ pi line_angle) (* 0.5 pi)) 25)
	         	(polar (setq line_end (polar line_mid_point line_angle (* 0.5 (vla-get-length line_object)))) (+ line_angle (* 0.5 pi)) 25)
		 )
	)
        (vlax-put line_object 'startpoint line_start)
  	(vlax-put line_object 'endpoint line_end)
	(princ)
)

updated_2

0 Likes
Message 22 of 28

avinash00002002
Collaborator
Collaborator

Thanks for your prompt reply, it works now text  p1 and p2, How to get define p1 and p2 from this routine

 

0 Likes
Message 23 of 28

Kent1Cooper
Consultant
Consultant

@avinash00002002 wrote:

I want to achieve that I need p1 point at the left side and p2 point is right side for identify cut at p1 point has left side and if cut at point p2 then it identify right side always.


I don't understand what relationship this has to "clock wise" in the Topic heading, and Message 1's "...always give me clockwise direction."

Kent Cooper, AIA
0 Likes
Message 24 of 28

komondormrex
Mentor
Mentor

if you need to change end points of a line according to marking check update_2 in message 21.

0 Likes
Message 25 of 28

autoid374ceb4990
Collaborator
Collaborator

avinash00002002:

Please explain  "identify cut at p1 point has left side and if cut at point p2 then it identify right side"

0 Likes
Message 26 of 28

Kent1Cooper
Consultant
Consultant

If what you want is to have whichever end is farther to the left put into a variable called p1, and whichever end is farther to the right put into a variable called p2, no matter which direction the Line was drawn, try this [in simplest terms, minimally tested]:

(defun C:LLtoR ; = Line endpoints ordered from Left to Right
  (/ lin endsLtoR)
  (setq
    lin (car (entsel "\nSelect Line for endpoint ordering: "))
    endsLtoR
      (vl-sort (list (getpropertyvalue lin "StartPoint") (getpropertyvalue lin "EndPoint"))
        '(lambda (a b) (< (car a) (car b)))
      ); sort
    p1 (car endsLtoR)
    p2 (cadr endsLtoR)
  ); setq
  (prin1)
)

If a Line is vertical [neither end is to the left or right of the other], its start point will be p1 and its end point will be p2.  But it could be made to, for example, put whichever end is lower into p1 and whichever end is higher into p2, or to differentiate by some other standard.

Kent Cooper, AIA
0 Likes
Message 27 of 28

Sea-Haven
Mentor
Mentor
Accepted solution

One of the things I often do is pick a line near and end this does not change the line direction but does swap P1 and P2 so they go away from P1. Is this maybe what you want.

 

like others need some visual clues, a dwg or an image.

 

SeaHaven_0-1758072459191.png

 

 

 

 

 

 

0 Likes
Message 28 of 28

Moshe-A
Mentor
Mentor

@Sea-Haven,

 

Well done! after 6 experts and 26:30 hours you are winning my the gold medal, i take off my hat 😀
@john.uhden where are you? we 
need your Wisdom here 🙏

 

 

0 Likes