GetBlockSize bug?

Started by honkinberry, February 19, 2013, 03:17:23 PM

Previous topic - Next topic

honkinberry

dcl_GetBlockSize appears to be returning (Height Width), not (Width Height) as the documentation states.

I have attached a couple blocks that are clearly wider than they are tall.

Speaking of those blocks, the reason came up due to the shadow layers in the block.  I would love an expansion of GetBlockSize to include some overload capabilities.  Namely, being able to exclude objects by type (Attribute Definitions most commonly, but also Solid Hatches), or to supply a layer list or even layer wildcard pattern to ignore.  Often we have non-plot or other layered linework around our blocks that we don't want counted with the block width.

--J

owenwengerd

That is a bug, now fixed for the next build. Apparently that function isn't used very often, because that bug has been there for a very long time.

roy_043

FWIW: In BricsCAD attribute definitions are disregarded by (dcl_GetBlockSize). Tested with a non-constant attribute definition.

Quote from: honkinberry on February 19, 2013, 03:17:23 PM
I would love an expansion of GetBlockSize
As a workaround I was going to suggest making nested objects temporarily invisible. I use this method to get the (vla-getboundingbox) function to disregard attribute references. But (dcl_GetBlockSize) does not take the visibility of objects into account. And (vla-getboundingbox) doesn't work on block definitions.

owenwengerd

I think (vla-getboundingbox) should work on the entities in a block definition. The OP wanted to ignore some entities, so the correct way to calculate the desired size is to iterate over all entities in the block and accumulate the extents of each.

honkinberry

Thank you Owen!
And yes, my intention was to get some of the same functionality that we currently have in our troublesome iteration function, I much prefer offloading to Owen, and I'll just tell him when it doesn't work, like this time!  :)

Thanks again, you rock.

--J

honkinberry

And hey, Owen, now that I think about....

What are the chances of just changing the *documentation*, rather than the code?

You know, the problem of different users with different version, etc, etc.
What do you think?

--J

owenwengerd

When the code and documentation don't match, there is no getting around the risk of someone's code breaking no matter what you do. Remember, the original OpenDCL code did not have this bug, so there is very possibly still code out there that expects the width first. In any case, it's consistent with other functions to return width before height, so it's a pretty easy call to change the code. Look for an update this weekend.

roy_043

Quote from: owenwengerd on February 20, 2013, 08:07:26 AM
... so the correct way to calculate the desired size is to iterate over all entities in the block and accumulate the extents of each.

Perhaps something like this:

Code (autolisp) Select

; Source:    Tony Tanzillo
;            Via: http://www.theswamp.org/index.php?topic=35254.msg404955#msg404955
; Principle: (mapcar 'min '(1 2) '(3 4 6) '(0 5 0) '(-1 8 -1))
(defun PointListBoundingbox (lst)
  (if lst
    (list
      (apply 'mapcar (cons 'min lst))
      (apply 'mapcar (cons 'max lst))
    )
  )
)

(defun ObjectBoundingbox (object / ptBL ptTR)
  (vla-getboundingbox object 'ptBL 'ptTR)
  (list (vlax-safearray->list ptBL) (vlax-safearray->list ptTR))
)

; BlockDefObject: Valid block definition (as vla-object)
; PredFunc:       Predicate function that takes an object as its single argument (as subr or sym)
(defun BlockDefObjectBoundingbox (blockDefObject predFunc / return)
  (if (= (type predFunc) 'sym) (setq predFunc (eval predFunc)))
  (vlax-for object blockDefObject
    (if (predFunc object)
      (setq return (cons (ObjectBoundingbox object) return))
    )
  )
  (PointListBoundingbox (apply 'append return))
)

; Example:
; =============================================
(defun MyPredicate (object)
  (/= (strcase (vla-get-objectname object)) "ACDBLINE")
)
(setq myBlockDefObject
  (vla-item
    (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    "MyBlock"
  )
)
(BlockDefObjectBoundingbox myBlockDefObject 'MyPredicate)
; =============================================

honkinberry

vla-getboundingbox fails every once in a while, depending on the object.
Like pretty much any code from TT, it looks elegant, but doesn't work.

I'm not sure what magic juju beans Owen used with GetBlockSize, but I've seen several instances where vla-getboundingbox fails, and GetBlockSize works.

--J

roy_043


Kerry

Quote from: roy_043 on March 01, 2013, 12:22:40 AM
Quote from: honkinberry on February 28, 2013, 04:05:43 PM
Like pretty much any code from TT
What is TT?

Tony Tanzillo

QuoteLike pretty much any code from TT, it looks elegant, but doesn't work.
The grammar here makes this sound like NONE of Tony's code works.
I'm sure honkinberry meant something like :
'This code is elegant, like most of Tony's code. Unfortunately I cant get it to work for the following reasons : ..... "

Regards
Kerry
Perfection is not optional.
My other home is TheSwamp

roy_043

Quote from: Kerry on March 28, 2013, 10:31:38 PM
Quote from: roy_043 on March 01, 2013, 12:22:40 AM
Quote from: honkinberry on February 28, 2013, 04:05:43 PM
Like pretty much any code from TT
What is TT?
Tony Tanzillo
Ah, of course. My powers of deduction must have been dormant when I asked that question. ::)