TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Marc'Antonio Alessi on November 26, 2014, 09:59:28 AM

Title: Test if LwPoly Is Closed also apparently
Post by: Marc'Antonio Alessi on November 26, 2014, 09:59:28 AM
Is this a valid test?
Code: [Select]
(defun c:LwPolyIsClosed ( / EntNam EntObj)
  (or
    (eq
      :vlax-true
      (vla-get-closed (setq EntObj (vlax-ename->vla-object (setq EntNam (car (entsel))))))
    )
  ; (= 1 (logand 1 (cdr (assoc 70 (entget EntNam)))))
    (equal (vlax-curve-getStartPoint EntObj)  (vlax-curve-getEndPoint EntObj))
  )
)
Title: Re: Test if LwPoly Is Closed also apparently
Post by: Tharwat on November 26, 2014, 11:06:35 AM
My attempt .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ClosedPoly-p (/ s)
  2.   (princ "\n Select LWpolyline ..")
  3.   (and (setq s (ssget "_+.:S:E" '((0 . "LWPOLYLINE"))))
  4.        (vlax-curve-isclosed (ssname s 0))
  5.   )
  6. )
  7.  
Title: Re: Test if LwPoly Is Closed also apparently
Post by: Marc'Antonio Alessi on November 26, 2014, 11:18:57 AM
My attempt .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ClosedPoly-p (/ s)
  2.   (princ "\n Select LWpolyline ..")
  3.   (and (setq s (ssget "_+.:S:E" '((0 . "LWPOLYLINE"))))
  4.        (vlax-curve-isclosed (ssname s 0))
  5.   )
  6. )
  7.  
...but "also apparently" > perimeter is closed manually (flag 70 = 0)...
Title: Re: Test if LwPoly Is Closed also apparently
Post by: Jeff_M on November 26, 2014, 12:02:35 PM
Marc'Antonio, I use essentially what you have posted except I use the optional fuzz factor for the (equal) comparison. Using a fuzz of 0.0001 helps to eliminate any errors due to computer rounding issues.
Title: Re: Test if LwPoly Is Closed also apparently
Post by: Marc'Antonio Alessi on November 26, 2014, 12:30:27 PM
Marc'Antonio, I use essentially what you have posted except I use the optional fuzz factor for the (equal) comparison. Using a fuzz of 0.0001 helps to eliminate any errors due to computer rounding issues.
Ok, so vlax-curve-isclosed is not always valid.
Thanks.
Title: Re: Test if LwPoly Is Closed also apparently
Post by: Andrea on December 05, 2014, 01:11:44 PM
Code: [Select]
(defun closedPoly (entname / entdata res)
  (cond
    ((eq (type entname) 'ENAME) (setq entdata (entget entname)))
    ((eq (type entname) 'VLA-OBJECT) (setq entdata (entget (vlax-vla-object->ename entname))))
  )
  (if entdata
    (if
      (eq 1 (cdr (assoc 70 entdata)))
      (setq res 1)
(progn
  (if         
      (eq (vl-princ-to-string (assoc 10 entdata))
                   (vl-princ-to-string (assoc 10 (reverse entdata)))
       )
   (setq res 3)
(setq res 2)
)
       ) 
    )
    )
  res
  )

  ;(closedPoly (car (entsel)))

1 = Closed
2 = not closed
3 = not closed but the last point correspond to the first point
Title: Re: Test if LwPoly Is Closed also apparently
Post by: Marc'Antonio Alessi on December 06, 2014, 05:17:45 AM
Code: [Select]
...     
(eq (vl-princ-to-string (assoc 10 entdata))
      (vl-princ-to-string (assoc 10 (reverse entdata)))
)
...
Why not: (equal (assoc 10 entdata) (assoc 10 (reverse entdata)) [fuzz])  ?