Hi all,
I'm putting together some quick function that I can send 2 arguments and get from it the total area of a given hatch on the given layer.
I think everything is in order but I'm having trouble with the selection set filter:
(DEFUN GET-HATCH-AREA (HATCH LAYR / area sset) (COND ((AND (ssget "X" '((0 . "HATCH") (2 . HATCH) (8 . LAYR))) (SETQ area 0) (VLAX-FOR H (SETQ sset (VLA-GET-ACTIVESELECTIONSET (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))) (SETQ area (+ (VLA-GET-AREA h) area)) ) (ALERT (STRCAT "\nTotal area = " (IF (OR (= (GETVAR "lunits") 3) (= (GETVAR "lunits") 4) ) (STRCAT (RTOS area 2) " sq. in. (" (RTOS (/ area 144) 2) " sq. ft.)") (RTOS area) ) ) ) (VLA-DELETE sset) ) ) ) )
I'm not sure what I've done wrong but given how tired I am, it could be something real dumb. If you see my mistake, please let me know, thank you.
Solved! Go to Solution.
Solved by BlackBox_. Go to Solution.
BTW - The error I get when using the function is:
error: bad SSGET list value
Thank you in advance for any help.
In order to supply your variables, in this case two arguments, to your selection set filter, you cannot employ the Quote " ' " symbol, as the precludes evaluation of the quoted list.
Instead try:
(setq ss (ssget "_x" (list '(0 . "HATCH") (cons 2 (strcase hatchPattern)) (cons 8 (strcase layerName)) (cons 410 (getvar 'ctab)) ) ) )
... Here's a complete example, with slight modification to your original code:
(defun Get-Hatch-Area (hatchPattern layerName / ss area i msg n fail total) (if (and (setq ss (ssget "_x" (list '(0 . "HATCH") (cons 2 (strcase hatchPattern)) (cons 8 (strcase layerName)) (cons 410 (getvar 'ctab)) ) ) ) (setq area 0) (setq i (sslength ss)) (setq msg "Total area = ") ) (progn (vlax-for x (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)) ) ) (if (not (vl-catch-all-error-p (setq n (vl-catch-all-apply 'vla-get-area (list x))) ) ) (setq area (append (list n) (list area))) (or fail (setq fail T)) ) ) (vla-delete ss) (setq total (apply '+ area)) (if fail (setq msg (strcat "** Unable to extract area for " (itoa (- i (length area))) " hatch patterns ** \n\n" msg ) ) ) (alert (strcat msg (if (vl-position (getvar 'lunits) '(3 4)) (apply 'strcat (list (rtos total 2) " sq. in. (" (rtos (/ total 144) 2) " sq. ft.)" ) ) (rtos total) ) ) ) ) (prompt "\n** Nothing selected ** ") ) (princ) )
HTH
"How we think determines what we do, and what we do determines what we get."
Thank you very much. You definitely got me thinking differently about this. Although, when I tried your code I recieved the following error.
error: bad argument list tail: 0
Any idea what is going on? (Only thing that I can mention is that I am creating the hatch in the drawing and then calling the sub-function all in the same function. Do I need to do anything for VL to see the hatch object?)
Thank you again.
@mid-awe wrote:Thank you very much. You definitely got me thinking differently about this. Although, when I tried your code I recieved the following error.
error: bad argument list tail: 0
Any idea what is going on? (Only thing that I can mention is that I am creating the hatch in the drawing and then calling the sub-function all in the same function. Do I need to do anything for VL to see the hatch object?)
Thank you again.
That is kind of you to say.
I did not experience any errors when running the code on my end, although I did have already generated hatch entities within my drawing... More specifically, I did receive an error when attempting to extract Area property from custom hatch patterns, hence the additional code.
Perhaps someone more knowledgeable than I (not exactly hard to do), will be able to see where I've made a mistake in the code I posted?
In any event, to your issue, perhaps if you posted your working code, I could better help identify the issue my code is generating.
"How we think determines what we do, and what we do determines what we get."
Thank you again
I found that my suspission was correct, although I don't understand why.
Originally I used a line like:
(vl-cmdf "-HATCH" "P" "GRAVEL" "10" "0" PAUSE "")
to create the hatch. But, for some reason there is no GEOMETRY properties when created that way.
I solved it by breaking the command into parts like:
(vl-cmdf "-HATCH" "P" "GRAVEL" "10" "0" "")
(vl-cmdf "-HATCH" PAUSE "")
And this works with the sub-function and reports no error.
BlackBoxCAD you have been a great help. Thank you.
@BlackBoxCAD wrote:
(setq ss (ssget "_x" (list '(0 . "HATCH") (cons 2 (strcase hatchPattern)) (cons 8 (strcase layerName)) (cons 410 (getvar 'ctab)) ) ) )
I seriously did not know that pattern name is case sensitive.
Good one BlackBox
@pbejse wrote:
@BlackBoxCAD wrote:
(setq ss (ssget "_x" (list '(0 . "HATCH") (cons 2 (strcase hatchPattern)) (cons 8 (strcase layerName)) (cons 410 (getvar 'ctab)) ) ) )
I seriously did not know that pattern name is case sensitive.
Good one BlackBox
That is kind of you to say, pbesje.
To the best of my knowledge, the case sensativity here is a byproduct of the DXF / Selection Set Filter relationship... As the AcDbHatch Object's PatternName Property (read-only) is upper case... Which stems from the upper case name contained within the *.pat file which defines the Hatch Pattern itself.
I am unsure if a given Hatch Pattern definition *must* be upper case or not, given that I have no knowledge of how a .pat file is processed behind the scenes... It's an old, presumably unchanged mechanism that has been a part of AutoCAD since well before my time (just a handful of years ago).
"How we think determines what we do, and what we do determines what we get."