Jump to content

extract coordinates in rectangle ...help


Recommended Posts

Posted

hello all:

 

I have rectangles or squares.

I want to select one and that it gives me the coordinate of one corner and another corner diagonally. (example PT1 AND PT3)

 

Help please.

 

image.png.c48a55bc7b7726ef5b4c3536a76254c5.png

 

Posted (edited)

 

(defun stsup ( l ) (if l (cons (list (car l) (cadr l)) (stsup (cddr l)))));by ????
(defun c:testcoord ()
  (setq obj_poli (vlax-ename->vla-object (car(entsel "\nSelecciona polilinea: "))))
  (setq coordenadas (vla-get-coordinates obj_poli))
  (setq lista_pt (stsup (vlax-safearray->list (vlax-variant-value coordenadas))))
  ;ordenamos lista de menor a mayor X, y si son iguales, de menor a mayor Y
  (setq lista_pt1 (vl-sort lista_pt '(lambda (el1 el2)
    (if (equal (car el1) (car el2))
      (> (cadr el1) (cadr el2))
      (< (car el1) (car el2)) 
    )
  )))
  (princ "\nPunto 1: ")
  (princ (car lista_pt1))
  (princ "  Punto 2: ")
  (princ (last lista_pt1))
  (princ)
)

 

Edited by robierzo
  • Like 1
Posted

 

with those points (punto 1 , punto 2)

how could i draw a point in pt1 and pt2?

 

image.png.ebf9f1c1cb6e07ebe12086b212eb693c.png

 

 

Posted (edited)
(defun stsup ( l ) (if l (cons (list (car l) (cadr l)) (stsup (cddr l)))))
(defun c:testcoord (/ obj_poli coordenadas lista_pt lista_pt1)
  (while (setq obj_poli (vlax-ename->vla-object (car(entsel "\nSelecciona polilinea: "))))
    (setq coordenadas (vla-get-coordinates obj_poli))
    (setq lista_pt (stsup (vlax-safearray->list (vlax-variant-value coordenadas))))
    ;ordenamos lista de menor a mayor X, y si son iguales, de menor a mayor Y
    (setq lista_pt1 (vl-sort lista_pt '(lambda (el1 el2)
      (if (equal (car el1) (car el2))
        (> (cadr el1) (cadr el2))
        (< (car el1) (car el2)) 
      )
    )))   
    (entmake (list '(0 . "POINT")'(100 . "AcDbEntity")'(100 . "AcDbPoint")(cons 10 (car lista_pt1))))
    (entmake (list '(0 . "POINT")'(100 . "AcDbEntity")'(100 . "AcDbPoint")(cons 10 (last lista_pt1))))

    (princ "\nPunto 1: ")
    (princ (car lista_pt1))
    (princ "  Punto 2: ")
    (princ (last lista_pt1))
    (princ)
  );fin While
)

 

Edited by robierzo
  • Like 1
Posted

Something like this, but notes its based on how the square was drawn, if you want top left and bottom right that is your home work there are a few methods to check the X&Y points.

 

(defun c:wow (  / plent )
(setq plent (entsel "\nPick rectang"))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent)))))
(command "Point" (nth 0 co-ord))
(command "Point" (nth 2 co-ord))
(princ)
)
(c:wow)

 

Another method is to use "Bounding box" it returns the opposite corners to what you want, but can work out the other corners by pulling the X & Y values of the min and max.

 

(setq obj (vlax-ename->vla-object (car (entsel "pick object "))))

(vla-GetBoundingBox obj 'minpoint 'maxpoint)
(setq pointmin (vlax-safearray->list minpoint))
(setq pointmax (vlax-safearray->list maxpoint))
;minpoint contains the minimum point of the bounding box
;maxpoint contains the maximum point of the bounding box

 

 

  • Like 2
Posted

excellent guys I learn a lot with you

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