GetBlockSize request

Started by honkinberry, August 02, 2019, 09:12:17 AM

Previous topic - Next topic

honkinberry

We really enjoy GetBlockSize, it's been far more reliable and accurate than the non-trivial amount of code we had to accomplish the same purpose.
However, there's one thing our code had that GetBlockSize doesn't -- the ability to ignore objects on certain layers.
It would be *amazing* if GetBlockSize could have a second optional parameter added, of LayerFilterExclusion.  For us, we would most commonly pass "*NPLT" to ignore all non-plot layers named as such.  If possible to go even further, there are cases we have multiple layers we want ignored, so being able to pass "*NPLT,*SHAD*" would be the ultimate of ideal for us.
Any change a future build might have such capability?

--J

roy_043

I am surprised that this function is part of OpenDCL. IMO it should be removed instead of extended.

roy_043

I would be interested to know why the ODCL function is more accurate. If your own implementation and the ODCL implementation use the same bounding box function 'under the hood' you would expect the same accuracy.

honkinberry

Roy,
Because we don't use the same bounding box function.
--J

roy_043

Does this mean that vla-getboundingbox is inaccurate? And, if so, can you give an example?
The only vla-getboundingbox issue I am aware of is that the bounding box of a rotated insert is calculated based on the box around the unrotated insert.

honkinberry

Roy,
The vla-getboundingbox function requires inserting a block into modelspace.  Further, even if a layer is turned off, it is counted towards the block's extents, so it is quite pointless to use compared to dcl-GetBlockSize.
The only way we have been able to calculate a block's extents without counting certain layers, is to iterate through all entities in the block definition, and calculate their extremities.  This is what is less accurate than dcl-GetBlockSize.
So the dilemma, is to update our considerable amount of code, that has to deal with every possible entity type and block nesting, or to hope that dcl-GetBlockSize could be extended with a LayerExcludeFilter.
I hope that makes sense.

--J

roy_043

Here is what I would try:

  • Create a temp ODBX document.
  • Copy your insert to that document.
  • Iterate over the blocks collection and over each block definition in the temp document and delete objects on layers you want to exclude.
  • Grab the bounding box of the insert.
  • Release the temp document.
All in all a couple of hundred lines of code.

honkinberry

Along those lines, why not just make a copy of the block in question, without the undesirable layers, and then use dcl-GetBlockSize on that temp block?  More like 50 lines of code.
But before doing something like that, I thought I would reach out on here, to see if perhaps other users had similar desires from dcl-GetBlockSize.

--J

roy_043

Just did a quick test with dcl-GetBlockSize. I don't see improved accuracy. Layers that are off/frozen are not ignored. And rotated nested inserts are handled in the same manner as the vla-getboundingbox function would.
Note: I use BricsCAD.

roy_043

Creating a replacement for dcl-GetBlockSize would be relatively simple in BricsCAD. It would be a little harder in AutoCAD, but not much.
(defun BlockDefBox (nme)
  (if (tblobjname "block" nme)
    (vle-getgeomextents
      (mapcar
        'vlax-vla-object->ename
        (vle-collection->list
          (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) nme)
        )
      )
    )
  )
)

(defun AltGetBlockSize (nme / box)
  (if (setq box (BlockDefBox nme))
    (vle-remove-last (apply 'mapcar (cons '- (reverse box))))
  )
)

; (equal (dcl-GetBlockSize "MyBlock") (AltGetBlockSize "MyBlock")) => T

honkinberry

Roy,
Yes, it would a little bit harder in AutoCAD.
But even the code you posted... why?  I mean, seriously, why?  You literally just proved that dcl-GetBlockSize is an identically capable, cross-platform wrapper.  Which is why we will continue to use it.
We will make a helper function that makes a copy of a block without the desired layers, and use dcl-GetBlockSize on that copy.  Still just happy to share this wishlist and real-world usage of this highly useful and capable helper function.

--J

roy_043

You have made two arguments for dcl-GetBlockSize: Higher accuracy and creating your own version requires a non-trivial amount of code. I have demonstrated that both are incorrect. So IMO there is no reason for dcl-GetBlockSize.

honkinberry

hahaha, okay Roy.
Actually, you're the only one arguing here.
Oddly, I have to clarify again.  I said that our *previous* version had a non-trivial amount of code, specifically to be able to ignore objects on certain layers.  The code you offered, which is for Bricscad only, does nothing in that regard.  You literally posted nothing but a partial alternative to GetBlockSize.  Which is humorous to me.  The only thing you "proved", is that GetBlockSize is a fantastic little helper function!
Secondly, I told you that our implementation does not use vla-boundingbox, and here you are again saying I claimed that GetBlockSize was more accurate.  So to clarify that, again, GetBlockSize is more accurate than iterating through all entities in a block, and doing the math on each vertex.
But no matter how any sensible person shakes its, GetBlockSize is a great little helper function!  And this thread really backs that up!  Go Team GetBlockSize!  Keep on truckin'!

As to the original query of this thread, as I stated, we'll make a quick copy of the block in question, without the undesirable layers, and call GetBlockSize on that.  Yet another fantastic capability of GetBlockSize -- I don't have to insert the block to query its size!  So again, what a helpful tool!

Searching for a meme or gif or something to sum up how I feel about GetBlockSize, but I'll just leave it at this:
Thanks, Roy, for helping to show what a great helper function GetBlockSize is!

--J

roy_043

Quote from: honkinberry on August 05, 2019, 02:07:05 PM
Roy,
Because we don't use the same bounding box function.
--J
I now realize I have misunderstood this message. I concluded that your code would use vla-getboundingbox, and that dcl-GetBlockSize used an enhanced boundingbox function.