Rectangle point required in one direction at any direction

Rectangle point required in one direction at any direction

avinash00002002
Collaborator Collaborator
724 Views
11 Replies
Message 1 of 12

Rectangle point required in one direction at any direction

avinash00002002
Collaborator
Collaborator

Hi!

 

I have some circumtances that I have rectangles in various directions I want all corners as marked in drawing file. 

 

help required.

 

Thanks,

Avinash

0 Likes
Accepted solutions (1)
725 Views
11 Replies
Replies (11)
Message 2 of 12

hak_vz
Advisor
Advisor

 

(defun c:mark_rect ( / pointlist2d e eo pts)
(defun pointlist2d (lst / ret)(while lst (setq ret (cons (list (car lst)(cadr lst)) ret) lst (cddr lst))) (reverse ret))
(cond 
	((and(setq e (car(entsel "\nSelect rect >" ))))
		(setq
			eo (vlax-ename->vla-object e) 
			pts (pointlist2d (vlax-get eo 'Coordinates))
		)
			(entmake
					(list
						(cons 0 "TEXT")
						(cons 100 "AcDbEntity")
						(cons 100 "AcText")
						(cons 1 "P1")
						(cons 10 (nth 0 pts))
						(cons 40 (getvar 'textsize))
					)
				)
				(entmake
					(list
						(cons 0 "TEXT")
						(cons 100 "AcDbEntity")
						(cons 100 "AcText")
						(cons 1 "P2")
						(cons 10 (nth 1 pts))
						(cons 40 (getvar 'textsize))
					)
				)
				(entmake
					(list
						(cons 0 "TEXT")
						(cons 100 "AcDbEntity")
						(cons 100 "AcText")
						(cons 1 "P3")
						(cons 10 (nth 3 pts))
						(cons 40 (getvar 'textsize))
					)
				)
				(entmake
					(list
						(cons 0 "TEXT")
						(cons 100 "AcDbEntity")
						(cons 100 "AcText")
						(cons 1 "P4")
						(cons 10 (nth 2 pts))
						(cons 40 (getvar 'textsize))
					)
				)
	)
	(T (princ "\nNothing selected !"))
)
(princ)
)

 

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 3 of 12

avinash.patilWHS3Z
Enthusiast
Enthusiast

It requires sequence of points p1, p2, p3, p4

0 Likes
Message 4 of 12

hak_vz
Advisor
Advisor
(defun c:mark_rect ( / pointlist2d  eo pts )
	(defun pointlist2d (lst / ret)(while lst (setq ret (cons (list (car lst)(cadr lst)) ret) lst (cddr lst))) (reverse ret))
	(defun pick_rect ()
	(setq e (car(entsel "\nSelect rectangle >")))
	(if (and (not e) (= (getvar 'Errno) 7)) (pick_rect) e)
	)
	(setq
		e (pick_rect)
		eo (vlax-ename->vla-object e) 
		pts (pointlist2d (vlax-get eo 'Coordinates))
	)
		(entmake
				(list
					(cons 0 "TEXT")
					(cons 100 "AcDbEntity")
					(cons 100 "AcText")
					(cons 1 "P1")
					(cons 10 (nth 0 pts))
					(cons 40 (getvar 'textsize))
				)
			)
			(entmake
				(list
					(cons 0 "TEXT")
					(cons 100 "AcDbEntity")
					(cons 100 "AcText")
					(cons 1 "P2")
					(cons 10 (nth 1 pts))
					(cons 40 (getvar 'textsize))
				)
			)
			(entmake
				(list
					(cons 0 "TEXT")
					(cons 100 "AcDbEntity")
					(cons 100 "AcText")
					(cons 1 "P3")
					(cons 10 (nth 3 pts))
					(cons 40 (getvar 'textsize))
				)
			)
			(entmake
				(list
					(cons 0 "TEXT")
					(cons 100 "AcDbEntity")
					(cons 100 "AcText")
					(cons 1 "P4")
					(cons 10 (nth 2 pts))
					(cons 40 (getvar 'textsize))
				)
			)
		(list (nth 0 pts)(nth 1 pts)(nth 3 pts)(nth 2 pts))
)

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 5 of 12

avinash.patilWHS3Z
Enthusiast
Enthusiast

Thanks for your prompt reply,

 

I required all points marked as per my drawing file point location 

 

like. please see the location or P1 , P2 , P3 , P4.

0 Likes
Message 6 of 12

hak_vz
Advisor
Advisor

@avinash.patilWHS3Z 

Sequence of rectangle points is

(list (nth 0 pts)(nth 1 pts)(nth 3 pts)(nth 2 pts))

Modify code above and you have it. I would really like to see code for this written by OP (you?)

Its really simple task and helps learning autolisp.

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 7 of 12

hak_vz
Advisor
Advisor

@avinash.patilWHS3Z wrote:

Thanks for your prompt reply,

 

I required all points marked as per my drawing file point location 

 

like. please see the location or P1 , P2 , P3 , P4.


First and second code does that, second returns sequence of points in order p1 p2 p3 p4

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 12

Kent1Cooper
Consultant
Consultant

A different approach, embedded into a context that will do all closed 4-vertex lightweight Polylines you choose, all at once.  And you can choose them with windowing, fence, lasso, individual picks, etc., and it will "see" only the qualifying objects among the selection -- no error from picking the wrong kind of thing.

 

(vl-load-com)
(defun C:RCL (/ ss n pl i); = Rectangle Corner Labels
  (if (setq ss (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&") (70 . 1))))
    (repeat (setq n (sslength ss))
      (setq
        pl (ssname ss (setq n (1- n)))
        i 0
      ); setq
      (foreach x '(0 1 3 2)
        (command "_.text" "_mc" (vlax-curve-getPointAtParam pl x) "" ""
          (strcat "P" (itoa (setq i (1+ i))))
        ); command
      ); foreach
    ); repeat
  ); if
  (prin1)
)

 

It uses the current Text Style [assumed to not have a fixed height] and height, on the current Layer, but specifics for those could be built in.

It would even be possible to check each Polyline for whether it is, in fact, rectangular, if desired.

Kent Cooper, AIA
0 Likes
Message 9 of 12

avinash.patilWHS3Z
Enthusiast
Enthusiast

Hi!

 

Thanks for your reply,

 

I need points as marked in drawing.

0 Likes
Message 10 of 12

Sea-Haven
Mentor
Mentor

 Ok I asked a question over at TheSwamp, Lisp, Challenges, which should answer the problem, 2 things first are points numbered CW or CCW. The second is that the question asked there was reset Point1, rotate all the points around based on the selected point.

 

Make a pline rectang points with start point lower left. (theswamp.org)

 

It may give some clues on a solution.

 

 

0 Likes
Message 11 of 12

Kent1Cooper
Consultant
Consultant

@avinash.patilWHS3Z wrote:

....

I need points as marked in drawing.


My routine did what was asked for in the original drawing, exactly.  Please be more specific in your descriptions if the example you give is not really representative of what you want.

 

And mine does the Text as middle-center justified, as in your original drawing, but this latest drawing at Message 9 has them left-justified, which means the results were not done with my routine, so it probably should not have been in reply to me.  What justification do you really want?

 

EDIT:  Message 10 from @Sea-Haven links to a Swamp topic "Make a pline rectang points with start point lower left. (theswamp.org)".  This further compounds the confusion about what is intended.  If that is the standard, then the original drawing example is wrong.  Its vertical rectangle is numbered starting from lower right.  So what really is the requirement?

Kent Cooper, AIA
0 Likes
Message 12 of 12

komondormrex
Mentor
Mentor
Accepted solution

hi,

check check the code below

 

 

 

;***************************************************************************************************************************************************

;	komondormrex, jan 2024

;***************************************************************************************************************************************************

(defun vector_multiplying (vector_1 vector_2 / x1 y1 z1 x2 y2 z2)
	(mapcar 'set '(x1 y1 z1) (mapcar '- (cadr vector_1) (car vector_1)))
	(mapcar 'set '(x2 y2 z2) (mapcar '- (cadr vector_2) (car vector_2)))
	(if (null z1) (setq z1 0))
	(if (null z2) (setq z2 0))
	(list (- (* y1 z2) (* z1 y2)) (- (* z1 x2) (* x1 z2)) (- (* x1 y2) (* y1 x2)))
)

;***************************************************************************************************************************************************

(defun c:ññw_mark_rect_vx ( / rect_sset rect_vertices_list rect_segments width_mid_list is_ccw base_mid index mark_text text_alignment_point)
	(setq rect_sset (ssget '((0 . "lwpolyline") (90 . 4) (-4 . "&=") (70 . 1))))
	(if rect_sset
		(foreach rect_ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex rect_sset)))
			(setq rect_vertices_list (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 10 (car group))) (entget rect_ename)))
				  rect_segments (mapcar 'list rect_vertices_list (append (cdr rect_vertices_list) (list (car rect_vertices_list))))
				  width_mid_list (mapcar '(lambda (segment) (mapcar '* '(0.5 0.5) (mapcar '+ (car segment) (cadr segment))))
				  				 		  (mapcar '(lambda (segment index) (nth index rect_segments))
								 				   rect_segments
				  				 				   (cddr (vl-sort-i (mapcar '(lambda (segment) (distance (car segment) (cadr segment))) rect_segments) '>))
								 		  )
								 )
				  is_ccw (not (minusp (caddr (vector_multiplying (car rect_segments) (cadr rect_segments)))))
			)
			(setq base_mid (cond
								((equal (car (car width_mid_list)) (car (cadr width_mid_list)) 1e-8)
										(if (< (cadr (car width_mid_list)) (cadr (cadr width_mid_list)))
											(car width_mid_list) (cadr width_mid_list)
										)
								)
								(t
									(if (< (car (car width_mid_list)) (car (cadr width_mid_list)))
										(car width_mid_list) (cadr width_mid_list)
									)
								)
				  		   )
				  rect_segments (mapcar '(lambda (segment)
											(if (equal base_mid (mapcar '* '(0.5 0.5) (mapcar '+ (car segment) (cadr segment))))
												(list (car segment) base_mid (cadr segment)) segment
											)
										 )
										 rect_segments
								)
				  rect_vertices_list (apply 'append (mapcar '(lambda (segment) (vl-remove (last segment) segment)) rect_segments))
				  rect_vertices_list (append (member base_mid rect_vertices_list) (reverse (cdr (member base_mid (reverse rect_vertices_list)))))
			)
			(if (not is_ccw) (setq rect_vertices_list (append (list base_mid) (reverse (cdr rect_vertices_list)))))
			(setq index 0)
			(foreach vertex (list (car (cdr rect_vertices_list)) (cadr (cdr rect_vertices_list)) (cadddr (cdr rect_vertices_list)) (caddr (cdr rect_vertices_list)))
					(setq mark_text (vla-addtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
									 			 (strcat "P" (itoa (setq index (1+ index))))
									 			 (setq text_alignment_point (vlax-3d-point vertex))
									 			 50
									)
					)
					(vla-put-alignment mark_text 4)
					(vla-put-textalignmentpoint mark_text text_alignment_point)
			)
		)
	)
)

;***************************************************************************************************************************************************

 

 

updated_2