• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

recognize to rectangle

  • Thread starter Thread starter Angelo2449
  • Start date Start date

Angelo2449

Guest
Hello everyone,
with code :
Code:
 (vl-load-com)
(setq entityta (entsel "\nsel select item"))
(seq object (vlax-ename->vla-object)))
(setq l: object (vlax-curve-getdistatparam object (vlax-curve-getendparam object)))

(setq list (entget))
(setq first (nth 1 list))
(setq naming (cdr first)

(princ "\n")
(princ "named xxxxxxxxxxxxxx ")
(princ nomeentita)
(princ "\n")

(cond)
((= name "lwpolyline")
(princ "\n")
(setq name "polyline")
(princ "is a polylinea")
(princ "\n")
)

((= name "line")
(princ "\n")
(setq name "linea")
(princ "is a line")
(princ "\n")
)

((= name "circle")
(princ "\n")
(setq name "circle")
(princ "is a circle")
(princ "\n")
)
);
I recognize the various types of object, how could I recognize a rectangle (closed polyline) and extract the value of the two sides?
Thank you.
 
extract the coordinates of the vertices of the polylinea, if they are 4 compares the distance of the 2 diagonals, if they are equal is a rectangle.
 
but as I extract the 4 or more vertices (it could be a polygon).
I should also establish whether it is a closed polyline.
Thank you rpor66.
 
extract the coordinates of the vertices of the polylinea, if they are 4 compares the distance of the 2 diagonals, if they are equal is a rectangle.
but how do I extract the 4 or more vertices (can be a polygon)? ?
I should also establish whether it is a closed polyline.
Thank you rpor66.
 
a lisp of lee-mac could help you: allows you to find the summit in the bottom left and at the top right given the selection set of a polyline.
 
a lisp of lee-mac could help you: allows you to find the summit in the bottom left and at the top right given the selection set of a polyline.
I have already tried this function but failed to apply it, at least until now.
I have explored the commands > vlax-curve < and I have rewritten the code, now I know the initial point of the object, the final point and if the object consists of a closed or open polylinea:
Code:
 (seq object (vlax-ename->vla-object)))
(setq l: object (vlax-curve-getdistatparam object (vlax-curve-getendparam object)))
(setq piniz (vlax-curve-getstartpoint object))
(setq pfine (vlax-curve-getendpoint object))
(Sectq condition (vlax-curve-isclosed object) ;
I can't find the command that lists all the polylinea vertices, I'm almost sure it exists!
 
(vl-load-com)
;
; sub charge to obtain coord. min and max of the selection:
(if (null lm:ssboundingbox)(load "ssboundingbox"))

;
(prompt "\nselect a polyline ")
(setq selpol (ssget))

; find coord. low left and high right:
(setq coor (lm:ssboundingbox selpol))
;

in the coor variable you get something like:
(2515.91 5895.91 0.0) (2565.91 5945.91 0.0)
that is the coordinates at the bottom left and at the top right

if you want to get the other two do a "collage" using appropriately car cadr or nth and then join them with a list: take the x of the first with the y of the secona and vice versa. . .
 
Code:
; lista coordinate polilinea lw
(defun fnlwcoord10(ent / e count coord)   
    (setq count 0)   
    (while (setq e (nth count ent))       
        (if (= (car e) 10)
            (setq coord (append coord (list (cdr e))))
        )
        (setq count (1+ count))
    )
    (list (cdr (assoc 70 ent)) coord)
)
ent is the entry of the name of the selected entity
call back the function: (setq list (fnlwcoord10 ent)
return the list: (1(1465.6 1512.97) (2262.97 2055.93) (2558.77 1680.03) (1726.03 1207.76))))
where (car list) is 1 closed, 0 open
(setq listcoord (cadr list)) is the coordinate list
comparisons between coordinate distances 0-2 and 1-3:
(distance (nth 0 listcoord) (nth 2 listcoord)
(distance (nth 1 listcoord) (nth 3 listcoord)
if they are equal is a rectangle
 
Code:
Trash-shaped variable tipo variant in list
(defun fnvarianttolisp(var)
(cond
((=type was) ‘variant’
(fnvarianttolisp (vlax-variant-value)))
((type where) safearray
(mapcar 'fnvarianttolisp (vlax-safearray->list)
)
(t was)
)
)

Flag polilinea lw chiusa e coordinate
(defun fncoordslw(n/vlaobj closed)
(setq vlaobj (vlax-ename->vla-object))
(setq closed (vlax-get-property vlaobj "closed")
(list closed (fnvarianttolisp (vlax-get-property vlaobj 'coordinates)))
)
It does the same thing but the coordinates list is not divided by points, I find it more uncomfortable.
 
thank you guys but with all these answers I go in confusion (I am not an expert).
Today, by fucking here and I managed to write this code:
Code:
 (defun c:cdrs)
(cdrs)
)

(defun c:trovapunti)
(trovapunti)
)

; --------------------------------------------------------------------------------------

(defun trovapunti (/)
(setq vertici (cdrs 10 (entget (car)))))
);;defun

; --------------------------------------------------------------------------------------

(defun cdrs (key lst / pair rtn)

(while (setq pair)
(setq rtn (cons (cdr pair) rtn) lst (cdr (member pair lst))

(princ "\n")
(princ "rtn xxxxxxx")
(princ rtn)
(princ "\n")

;rtn >>>>> ((172.908 208.436)
;rtn >>>>> ((246.282 208.436) (172.908 208.436)
;rtn >>>>> ((246.282 143.763) (246.282 208.436) (172.908 208.436)
;rtn >>>>> ((172.908 143.763) (246.282 143.763) (246.282 208.436) (172.908 208.436)

);;while

(reverse rtn)
);;defun

; --------------------------------------------------------------------------------------
I would be grateful if you could change it to get a list of coordinates to manage.
In essence I would like to have this:
"172.908,208,436 246.282,208,436 246.282,143.763 172.908,143.763"
Thank you.
 
Hello, guys.
I managed to get something good!
Code:
 (defun c:cdrs)
(cdrs)
)

(defun c:trovapunti)
(trovapunti)
)

; --------------------------------------------------------------------------------------

(defun trovapunti (/)
(setq vertici (cdrs 10 (entget (car)))))
);;defun

; --------------------------------------------------------------------------------------

(defun cdrs (key lst / pair rtn primo cx cy stringa cont)

(setq stringa "")
(setq cont 0)

(while (setq pair)
(setq rtn (cons (cdr pair) rtn) lst (cdr (member pair lst))
(setq primo (car rtn))
(setq cont (1+ cont))

(setq cx (car primo))
(setq cy (cadr primo))

(princ "\n")
(princ "cx xxxxxxx")
(princ cx)
(princ "\n")
(princ "cy xxxxxxx")
(princ cy)
(princ "\n")

(setq stringa (strcat stringa (rtos cx 2 3) "," (rtos cy 2 3) "#))

);;while

(reverse rtn)

(setq stringa (strcat stringa (itoa cont)))

(princ "string xxxxxxx")
(princ stringa)
(princ "\n")

);;defun

; --------------------------------------------------------------------------------------
string > string < contains all the data I need
If it is possible to improve it I would be grateful.
Thank you.
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top