Author Topic: why this hatch has no area?  (Read 1790 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1250
why this hatch has no area?
« on: May 06, 2013, 03:57:16 PM »
I am tring tp get hatch area using
Code: [Select]
(setq obj  (vlax-ename->vla-object (ssname sset cnt)))
(setq ar (+ ar (vla-get-area obj)))
but gives error
Code: [Select]
Select objects:  ; error: Automation Error. Invalid input

alanjt

  • Needs a day job
  • Posts: 5320
  • Standby for witty remark...
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12019
  • AutoCAD 2015 Windows 7 London, England
Re: why this hatch has no area?
« Reply #2 on: May 06, 2013, 04:09:02 PM »
Check for self-intersecting hatch boundary.

cadplayer

  • Bull Frog
  • Posts: 384
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: why this hatch has no area?
« Reply #3 on: May 07, 2013, 01:13:43 AM »
Yes the problem I have often with unclosed, arc or Polylines with dubbel lines (Intersection in Polyline). That why I have a routine which check first if Polyline have a area value, if not it draws a line to them.

Code: [Select]
(if (= T (vl-catch-all-error-p (setq A (vl-catch-all-apply 'vla-get-area (list Vobj)))))
  (progn
            (princ (strcat "\nwrong area " (cdr (assoc 8 (entget ent))) ))
            (setq l (cdr (vl-remove-if-not (function (lambda (x) (= (car x) 10))) (entget ent))))
            (entmakex
                (list
                   '(0 . "LINE")
                    (cons 10 '(0 0 0))
                    (cons 11  (list (cadr (nth 1 l)) (caddr (nth 1 l))))
                   '(62 . 256)
                   (assoc 8 (entget ent))
                   )
                 )

Lee Mac

  • Seagull
  • Posts: 12019
  • AutoCAD 2015 Windows 7 London, England
Re: why this hatch has no area?
« Reply #4 on: May 07, 2013, 07:26:30 AM »
Some minor points Dirk, but the following may help with your understanding of AutoLISP:

Code - Auto/Visual Lisp: [Select]
  1. (if (= T (vl-catch-all-error-p (setq A (vl-catch-all-apply 'vla-get-area (list Vobj)))))

The '=' function is redundant since it will return T if the vl-catch-all-error-p expression being compared returns T; hence the above is equivalent to:
Code - Auto/Visual Lisp: [Select]
  1. (if (vl-catch-all-error-p (setq A (vl-catch-all-apply 'vla-get-area (list Vobj))))



Code - Auto/Visual Lisp: [Select]
  1. (cons 10 '(0 0 0))

Note that:
Code - Auto/Visual Lisp: [Select]
  1. (cons 10 '(0 0 0)) == '(10 0 0 0) == (list 10 0 0 0)



Code - Auto/Visual Lisp: [Select]
  1. (cons 11 (list (cadr (nth 1 l)) (caddr (nth 1 l))))

The above could be written:
Code - Auto/Visual Lisp: [Select]
  1. (cons 11 (cdadr l))



Incorporating these and some other changes:
Code - Auto/Visual Lisp: [Select]
  1. (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-area (list Vobj)))
  2.    (progn
  3.        (princ (strcat "\nWrong area " (vla-get-layer Vobj)))
  4.        (setq l (vlax-get Vobj 'coordinates))
  5.        (entmake
  6.            (list
  7.               '(0 . "LINE")
  8.               '(10 0.0 0.0 0.0)
  9.                (list 11 (car l) (cadr l) (vla-get-elevation Vobj))
  10.               '(62 . 256)
  11.                (cons 8 (vla-get-layer Vobj))
  12.            )
  13.        )
  14.    )
  15. )
« Last Edit: May 07, 2013, 07:29:54 AM by Lee Mac »

irneb

  • Water Moccasin
  • Posts: 1793
  • ACad R9-2016, Revit Arch 6-2016
Re: why this hatch has no area?
« Reply #5 on: May 07, 2013, 07:53:58 AM »
http://www.theswamp.org/index.php?topic=32571.0
Alan. Regarding that other thread - do you remember if the hatch was made using a pick-point or through selecting the polyline(s)? If the former it might have picked up some strange stuff from OFF layers (or I've even seen it pick up lines outside the boundary).

But why it would have an area on one PC but not the other on the same DWG on the same hatch is beyond comprehension. Is acad using some form of GPU acceleration to calculate the areas?

Other than that as Lee and Dirk's stated: Either it's self-intersecting (like a bow-tie) or it's not fully enclosed (e.g. using gap tolerances). In my experience these are 99.9999% of the time the culprits for non-areas.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

alanjt

  • Needs a day job
  • Posts: 5320
  • Standby for witty remark...
Re: why this hatch has no area?
« Reply #6 on: May 07, 2013, 07:57:07 AM »
http://www.theswamp.org/index.php?topic=32571.0
Alan. Regarding that other thread - do you remember if the hatch was made using a pick-point or through selecting the polyline(s)? If the former it might have picked up some strange stuff from OFF layers (or I've even seen it pick up lines outside the boundary).

But why it would have an area on one PC but not the other on the same DWG on the same hatch is beyond comprehension. Is acad using some form of GPU acceleration to calculate the areas?

Other than that as Lee and Dirk's stated: Either it's self-intersecting (like a bow-tie) or it's not fully enclosed (e.g. using gap tolerances). In my experience these are 99.9999% of the time the culprits for non-areas.
Honestly, I don't remember. I didn't create the hatches, another user had and has posted about them. It started with me posting a hatch area LISP, but I guess that thread was removed.
What you are saying, in agreement with Lee, makes sense.
Civil 3D 2017 ~ Windohz 7 64bit
Dropbox

cadplayer

  • Bull Frog
  • Posts: 384
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: why this hatch has no area?
« Reply #7 on: May 07, 2013, 09:50:59 AM »
Thanks Lee, Iīm alway open for correcction. :-o

Lee Mac

  • Seagull
  • Posts: 12019
  • AutoCAD 2015 Windows 7 London, England
Re: why this hatch has no area?
« Reply #8 on: May 07, 2013, 10:05:17 AM »
Thanks Lee, Iīm alway open for correcction. :-o
Me too  :wink:

HasanCAD

  • Swamp Rat
  • Posts: 1250
Re: why this hatch has no area?
« Reply #9 on: May 16, 2013, 03:22:57 AM »
is this good solution
Code: [Select]
(defun c:HatchAreas (/ AREA CNT OBJ OBJVL ORC SSET )
  (defun NLayer (Nme)
  (if (not (tblsearch "LAYER" Nme))
    (progn
      (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord")
     (cons 100 "AcDbLayerTableRecord") (cons 2  Nme)
     (cons 70 0) (cons 62 1)))))) 
  (nlayer "HatchHasNoArea")
 
  (if (>= (atof (substr (getvar "acadver") 1 4)) 16.2)
    (progn
      (prompt "\nSelect hatches: ")
      (if (and (setq sset (ssget '((0 . "hatch"))) cnt 0 area 0))
(progn
  (repeat (sslength sset)
    (setq obj   (ssname sset cnt))
    (setq objvl (vlax-ename->vla-object obj))
    (if (vl-catch-all-error-p
  (vl-catch-all-apply 'vla-get-area (list objvl)))
      (progn
(vla-put-color objvl 256)
(vla-put-layer objvl "HatchHasNoArea")
) ;prgn
      (setq area (+ area (vla-get-area objvl)))
      ) ;if
    (setq cnt (1+ cnt))
    ) ; repeat
  )
) ;if
      )) ; if
  (alert
    (strcat
      "\nTotal area = "
      (if (or (= (getvar "lunits") 3) (= (getvar "lunits") 4))
(strcat (rtos area 2) " sq. in. (" (rtos (/ area 144) 2) " sq. ft.)"
"\nHatchs with RED color DID NOT calculated")
(strcat (rtos area) "\nHatchs with RED color DID NOT calculated"))
      ) ; strcat
    ) ;alert
  ) ; defun