Author Topic: Test if LwPoly Is Closed also apparently  (Read 2339 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Test if LwPoly Is Closed also apparently
« 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))
  )
)

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Test if LwPoly Is Closed also apparently
« Reply #1 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.  

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Test if LwPoly Is Closed also apparently
« Reply #2 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)...

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Test if LwPoly Is Closed also apparently
« Reply #3 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.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Test if LwPoly Is Closed also apparently
« Reply #4 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.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Test if LwPoly Is Closed also apparently
« Reply #5 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
Keep smile...

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Test if LwPoly Is Closed also apparently
« Reply #6 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])  ?