Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
honkinberry
Posts: 123
Registered: ‎05-09-2008
Message 1 of 6 (403 Views)

Invalid input querying hatch object's Area

403 Views, 5 Replies
03-25-2009 07:47 PM
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
Distinguished Contributor
tom_brabant
Posts: 404
Registered: ‎12-08-2003
Message 2 of 6 (403 Views)

Re: Invalid input querying hatch object's Area

03-26-2009 07:46 AM 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)
)
Distinguished Contributor
tom_brabant
Posts: 404
Registered: ‎12-08-2003
Message 3 of 6 (403 Views)

Re: Invalid input querying hatch object's Area

03-26-2009 08:01 AM 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
Distinguished Contributor
honkinberry
Posts: 123
Registered: ‎05-09-2008
Message 4 of 6 (403 Views)

Re: Invalid input querying hatch object's Area

03-26-2009 08:39 AM 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
Distinguished Contributor
tom_brabant
Posts: 404
Registered: ‎12-08-2003
Message 5 of 6 (403 Views)

Re: Invalid input querying hatch object's Area

03-26-2009 09:02 AM 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
Distinguished Contributor
honkinberry
Posts: 123
Registered: ‎05-09-2008
Message 6 of 6 (403 Views)

Re: Invalid input querying hatch object's Area

03-26-2009 10:28 AM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.