Author Topic: Trying to extract area from Hatch but gives error  (Read 1397 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Trying to extract area from Hatch but gives error
« 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.
« Last Edit: September 20, 2023, 06:52:03 AM by HasanCAD »

dexus

  • Bull Frog
  • Posts: 208
Re: Trying to extract area from Hatch but gives error
« Reply #1 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. )
« Last Edit: September 20, 2023, 08:17:16 AM by dexus »