leonucadomi Posted November 3, 2022 Share Posted November 3, 2022 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. Quote Link to comment Share on other sites More sharing options...
robierzo Posted November 3, 2022 Share Posted November 3, 2022 (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 November 3, 2022 by robierzo 1 Quote Link to comment Share on other sites More sharing options...
leonucadomi Posted November 3, 2022 Author Share Posted November 3, 2022 excellent , thanks Quote Link to comment Share on other sites More sharing options...
leonucadomi Posted November 3, 2022 Author Share Posted November 3, 2022 with those points (punto 1 , punto 2) how could i draw a point in pt1 and pt2? Quote Link to comment Share on other sites More sharing options...
robierzo Posted November 3, 2022 Share Posted November 3, 2022 (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 November 3, 2022 by robierzo 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 3, 2022 Share Posted November 3, 2022 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 2 Quote Link to comment Share on other sites More sharing options...
leonucadomi Posted November 3, 2022 Author Share Posted November 3, 2022 excellent guys I learn a lot with you 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.