Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Invalid input querying hatch object's Area

5 REPLIES 5
Reply
Message 1 of 6
honkinberry
2083 Views, 5 Replies

Invalid input querying hatch object's Area

I have a drawing with several hatch objects, and when I attempt to query some of the hatch's Area, I get an Invalid input Automation Error.
The hatch has an Area in the Properties dialog box, yet in the vlax-dump-object for the hatch object, it states
Area (RO) = AutoCAD.Applicaiton: Invalid input

Any thoughts on what would cause this?
As for how to test for it, should I just wrap the vla-get-area in a catch-all-error?

thanks for any thoughts!

--J
5 REPLIES 5
Message 2 of 6
tom_brabant
in reply to: honkinberry

Here might be a tool that dodges the issue and can return the area of a picked hatch.

(defun c:hatcharea ()
(setq lis (make_lwplis (car (entsel "choose hatch")))
lis (reverse (cdr (reverse (cdr lis))))
)
(command "pline")
(mapcar 'command lis)
(command "")
(setq bound (entlast))
(command "area" "o" bound)
(command "erase" bound "")
(setq thearea (getvar "area"))
)
(defun make_lwplis (e / lis eg)
(setq lis nil)
(setq eg (entget e))
(while
(setq eg (member (assoc 10 eg) eg))
(setq lis (cons (cdar eg) lis) eg (cdr eg))
)
(reverse lis)
)
Message 3 of 6
tom_brabant
in reply to: honkinberry

Object snaps might interfere with the results: the routine could be altered to turn them off or you could do it manually. Also, there is a bounding lightweight polyline made around the hatch that is erased. If you want to keep it for any reason you could remove (or comment out) the line (command "erase" bound ""). Edited by: Tom_Brabant on Mar 26, 2009 3:01 PM
Message 4 of 6
honkinberry
in reply to: honkinberry

Many hatch objects have their first group 10 code as 0,0,0 -- your routine doesn't check for that.
It also doesn't deal with arc edges, or interior islands.

--J
Message 5 of 6
tom_brabant
in reply to: honkinberry

You are right. It doesn't check the relevance of the 10 groups, but eliminates the first and last one assuming they are not on the boundary. But, arcs and islands are a bigger issue. What do you think of this?
1. Set an undo mark.
2. use (command "hatchedit" ) to convert the pattern to dots.
3 also adjust the hatch scale to make the dots proportional to your area measurement..
4. explode the hatch.
5. save the exploded entities (zero length lines) as a (previous) selection set
6. Count the entities in the set to approximate the area to the desired precision (depends on choice of hatch scale)
7. Undo back to mark to undo the hatch destruction. Edited by: Tom_Brabant on Mar 26, 2009 4:06 PM
Message 6 of 6
honkinberry
in reply to: honkinberry

I have a fine routine to rebuild a hatch bounding polyline if necessary.
I was just wondering why the Area property of some hatch objects was causing an automation error.

my adjusted code:
(setq entx (car (entsel "\nSelect hatch:"))
vlobj (vlax-ename->vla-object entx)
entx (entget entx)
) ; setq
(cond
( (and (vlax-property-available-p vlobj (quote Area)) ; hatch, 2007+
(not (vl-catch-all-error-p (setq areax (vl-catch-all-apply (quote vla-get-area) (list vlobj)))))
) ; and
areax
) ; query hatch area directly
( (and (setq polyx (HATCHOWNER entx)) ; has a bounding poly
(setq polyx (cdr (assoc -1 polyx)))
) ; and
(setq areax (vla-get-area (vlax-ename->vla-object polyx)))
) ; bounding polyline
; lastly, no bounding polyline found, let's recreate
( (setq polyx (REBUILDBOUNDARY entx))
(setq areax (vla-get-area (vlax-ename->vla-object polyx))
entx (entdel polyx)
) ; setq
) ; rebuild boundary
( t ; finally, no luck at all
(alert "Error querying hatch area.")
(setq areax 1.0)
) ; no luck
) ; cond

Would still like to know what causes the Automation error.

--J

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost