GetBlockSize bug?

Started by honkinberry · 2013-02-19 23:17 UTC · 11 replies · SMF topic #1947

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
Attachments
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.
FWIW: In BricsCAD attribute definitions are disregarded by (dcl_GetBlockSize). Tested with a non-constant attribute definition.

author=honkinberry link=topic=1947.msg9572#msg9572 date=1361315843 wrote:
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.
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.
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
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
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.
author=owenwengerd link=topic=1947.msg9576#msg9576 date=1361376446 wrote:
... 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:


; 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)
; =============================================
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
author=honkinberry link=topic=1947.msg9585#msg9585 date=1362096343 wrote:
Like pretty much any code from TT
What is TT?
author=roy_043 link=topic=1947.msg9586#msg9586 date=1362126160 wrote:
[quote author=honkinberry link=topic=1947.msg9585#msg9585 date=1362096343]
Like pretty much any code from TT
What is TT?


Tony Tanzillo

Like 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
author=Kerry link=topic=1947.msg9617#msg9617 date=1364535098 wrote:
[quote author=roy_043 link=topic=1947.msg9586#msg9586 date=1362126160]
[quote author=honkinberry link=topic=1947.msg9585#msg9585 date=1362096343]
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. ::)