TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: HasanCAD on September 20, 2023, 06:48:22 AM

Title: Trying to extract area from Hatch but gives error
Post by: HasanCAD on September 20, 2023, 06:48:22 AM
This part of code gives error

Code: [Select]
      (setq pp (getpoint "/nPick internal Point: "))
      (vl-cmdf "-bhatch" "Properties" "solid" "advance" "island" "yes" "S" "outer" "" pp "")
      (setq ph (entlast))
      (setq pa (/ (vlax-get-property (vlax-ename->vla-object (entlast)) 'Area) 1000000))

attached polyline which gives error.
Title: Re: Trying to extract area from Hatch but gives error
Post by: dexus on September 20, 2023, 07:46:54 AM
You have some segments in the polyline with a length of 0.
If you remove those, the code will probably work.

You can use something like this:
Code - Auto/Visual Lisp: [Select]
  1. ;; Removes zero length segs
  2. (defun remZeroLengthSegs (ent fuzz / a n lst e1 e2)
  3.   (if (setq e1 (entget ent))
  4.     (progn
  5.       (foreach a e1
  6.         (cond
  7.           ((not (equal 10 (car a))) (setq e2 (cons a e2)))
  8.           ((not (equal (car lst) a fuzz)) (setq lst (cons a lst) e2 (cons a e2)))
  9.         )
  10.       )
  11.       (setq e2 (reverse e2))
  12.       (if (and e2 (not (equal e1 e2)) lst)
  13.         (if (equal 1 (length lst))
  14.           (progn ; Remove whole polyline if total length is zero
  15.             (entdel (cdr (assoc -1 e1)))
  16.             (setq e2 nil)
  17.           )
  18.           (progn ; Remove zero length segments
  19.             (setq e2 (subst (cons 90 (length lst)) (assoc 90 e2) e2))
  20.             (entmod e2)
  21.           )
  22.         )
  23.       )
  24.     )
  25.   )
  26. )