rodrigo_sjc_sp 发表于 2022-7-6 06:20:25

Handling in vla-get-area

In this code
 

(setq valor_area 0.0000)(setq sel (ssget "_x" (list '(0 . "HATCH")(cons 8 layer))))(if (/= sel nil)(progn(setq i 0)(repeat (sslength sel)      (setq entbh (ssname sel i))      (if (/= entbh nil)         (progn            (setq lentbh (entget entbh))         (setq layerbh (cdr(assoc 8 lentbh)))         (setq valor_area(+ valor_area (vla-get-area (vlax-ename->vla-object entbh)))))))
 
 
The error is in this line

(setq valor_area(+ valor_area (vla-get-area (vlax-ename->vla-object entbh))))
 
 
I received the Automation error,how to handling this problem ?
I need that when the error occurs and the system to zoom in on the problem with hatch.
 
Thanks

Tharwat 发表于 2022-7-6 06:31:42

Nothing is wrong with the code , unless you have this is a part of another routine

rodrigo_sjc_sp 发表于 2022-7-6 06:44:40

Tharwat ,
 
I could help to create a handling for this part of the code
 

vla-get-area (vlax-ename-> vla-object entbh)
 
If a problem arises you need to zoom in on the hatch and stop the process.

Tharwat 发表于 2022-7-6 06:53:54

Try it this way ..
 

(setq valor_area 0.0)(if (setq sel (ssget "_x" (list '(0 . "HATCH") (cons 8 layer)))) (repeat (setq i (sslength sel))   (setq entbh (ssname sel (setq i (1- i))))   (setq valor_area          (+ valor_area             (vla-get-area (vlax-ename->vla-object entbh))          )   ) ))

Lee Mac 发表于 2022-7-6 07:09:09

The ActiveX area property will not be available for Hatch objects with a self-intersecting boundary - this is likely causing the error you are experiencing.

Lee Mac 发表于 2022-7-6 07:17:24

Here is one way to bypass the issue:

(defun c:harea ( / a i j r s )   (setq r 0.0 j 0)   (if (setq s (ssget "_X" '((0 . "HATCH"))))       (repeat (setq i (sslength s))         (if               (vl-catch-all-error-p                   (setq a                     (vl-catch-all-apply 'vla-get-area                           (list (vlax-ename->vla-object (ssname s (setq i (1- i)))))                     )                   )               )               (setq j (1+ j))               (setq r (+ r a))         )       )   )   (if (< 0.0 r)       (princ (strcat "\nTotal Area: " (rtos r 2)))   )   (if (< 0 j)       (princ (strcat "\n" (itoa j) " had a self-intersecting boundary."))   )   (princ))

rodrigo_sjc_sp 发表于 2022-7-6 07:28:43

I need to do some tests and I'll be back.
 
Thanks to all!
页: [1]
查看完整版本: Handling in vla-get-area