Jump to content

Points in a rectangle


TunzaGibbo

Recommended Posts

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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)) 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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))
) 

Link to comment
Share on other sites

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-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))

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...