TunzaGibbo Posted June 22, 2018 Share Posted June 22, 2018 In LISP can I select a rectangle and automatically have the 4 corner point located for me? Quote Link to comment Share on other sites More sharing options...
rlx Posted June 22, 2018 Share Posted June 22, 2018 http://www.cadtutor.net/forum/showthread.php?35846-points-of-a-polyline-lisp-routine Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 23, 2018 Share Posted June 23, 2018 This may be a bit simpler and its up to you to what you do with the list of points, as its simple it does not check what you have picked. As many vertices in the pline. (setq obj2 (vlax-ename->vla-object (car(entsel)))) (setq co-ords (vlax-safearray->list (vlax-variant-value (vlax-get-property obj2 "Coordinates" )))) (setq I 0) (repeat (/(length co-ords) 2) (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) )) (setq co-ordsxy (cons xy co-ordsxy)) (setq I (+ I 2)) ) (princ co-ordsxy) Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted June 23, 2018 Author Share Posted June 23, 2018 Thanks Bigal I ran that code and it gives the co-ordinates of the 4 points. To use the position of those 4 points would I need a name for each corner? Say for example a line from P1 P2 P3 P4 Regards Tony Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 23, 2018 Share Posted June 23, 2018 To use the position of those 4 points would I need a name for each corner? Say for example a line from P1 P2 P3 P4 Hi, With the following simple codes you would have the fourth coordinates assigned to the variable name 'l' and each one assigned to variables start with p1, p2, p3 and p4 (and (setq s (car (entsel "\nSelect Polyline with four coordinates :"))) (or (= (cdr (assoc 0 (setq e (entget s)))) "LWPOLYLINE") (alert "Invliad object. Try again") ) (or (= (cdr (assoc 90 (setq e (entget s)))) 4) (alert "Invliad number of coordinates") ) (mapcar '(lambda (p) (and (= (car p) 10) (setq l (cons (cdr p) l)))) e) (mapcar 'set '(p1 p2 p3 p4) l) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 24, 2018 Share Posted June 24, 2018 Nice one Tharwat. Tunzagibbo as the points are in a list you can get at each corner by just retrieving each vertice using this method also. ; the list of points starts with item zero not 1 ; want 3rd point (setq pt3 (nth 2 co-ordsxy)) ; want 4th point (setq pt4 (nth 3 co-ordsxy)) Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted June 24, 2018 Author Share Posted June 24, 2018 Thanks Bigal Another question if you don't mind. I have a rectangle that I have used "setq" to name it INNERSHAPE I then want to use your code to find the 4 corners of INNERSHAPE without having to select that shape again on the screen Can the Centroid of this shape also be located in the same operation? Regards Tony Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 24, 2018 Share Posted June 24, 2018 Nice one Tharwat. Thank you BIGAL. Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted June 24, 2018 Author Share Posted June 24, 2018 Hi Bigal I thought this should work but it doesn't seem to get the 4 points (Last 4 Lines) (defun InnerShape (/ InnerShape co-ords I xy co-ordsxy Innerpt1 Innerpt2 Innerpt3 Innerpt4) (setq InnerShape (vlax-ename->vla-object (entlast))) ;my name choice "InnerShape" (setq co-ords (vlax-safearray->list (vlax-variant-value (vlax-get-property InnerShape "Coordinates" )))) ;my name choice "InnerShape" (setq I 0) (repeat (/(length co-ords) 2) (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) )) (setq co-ordsxy (cons xy co-ordsxy)) (setq I (+ I 2))) (princ co-ordsxy) (setq Innerpt1 (nth 0 co-ordsxy) :always start with 0 NOT 1 Innerpt2 (nth 1 co-ordsxy) Innerpt3 (nth 2 co-ordsxy) Innerpt4 (nth 3 co-ordsxy)) ) Quote Link to comment Share on other sites More sharing options...
dlanorh Posted June 24, 2018 Share Posted June 24, 2018 Hi BigalI thought this should work but it doesn't seem to get the 4 points (Last 4 Lines) (defun InnerShape (/ InnerShape co-ords I xy co-ordsxy Innerpt1 Innerpt2 Innerpt3 Innerpt4) (setq InnerShape (vlax-ename->vla-object (entlast))) ;my name choice "InnerShape" (setq co-ords (vlax-get-property InnerShape "Coordinates" )))) ;my name choice "InnerShape" (setq I 0) (repeat (/(length co-ords) 2) (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) )) (setq co-ordsxy (cons xy co-ordsxy)) (setq I (+ I 2))) (princ co-ordsxy) (setq Innerpt1 (nth 0 co-ordsxy) [color=red];always start with 0 NOT 1 This comment should start with a semi-colon not a colon, otherwise it throws an error[/color] Innerpt2 (nth 1 co-ordsxy) Innerpt3 (nth 2 co-ordsxy) Innerpt4 (nth 3 co-ordsxy)) ) See above. If you want the coords in creation order (how the line was drawn) you need to (setq co-ordsxy (reverse co-ordsxy)) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 25, 2018 Share Posted June 25, 2018 Tunzagibbo as you have a rectangle the centroid is just the mid point of pt1 & Pt3 (setq ang (angle Innerpt1 Innerpt3)) (setq dist ( / (distance Innerpt1 Innerpt3) 2.0)) (setq ptmid (polar Innerpt1 ang dist)) Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted June 26, 2018 Author Share Posted June 26, 2018 Thanks to all who helped I have the lisp working perfectly now Regards Tony Gibbs Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.