Visual LISP, AutoLISP and General Customization
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Invalid input querying hatch object's Area
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
221 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
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
Re: Invalid input querying hatch object's Area
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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)
)
(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)
)
Re: Invalid input querying hatch object's Area
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Invalid input querying hatch object's Area
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
It also doesn't deal with arc edges, or interior islands.
--J
Re: Invalid input querying hatch object's Area
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
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
Re: Invalid input querying hatch object's Area
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
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

