Author Topic: GetBlockSize request  (Read 243 times)

honkinberry

  • Full Member
  • ***
  • Posts: 154
GetBlockSize request
« on: August 02, 2019, 09:12:17 AM »
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

  • Sr. Member
  • ****
  • Posts: 369
Re: GetBlockSize request
« Reply #1 on: August 04, 2019, 03:53:12 AM »
I am surprised that this function is part of OpenDCL. IMO it should be removed instead of extended.

roy_043

  • Sr. Member
  • ****
  • Posts: 369
Re: GetBlockSize request
« Reply #2 on: August 05, 2019, 05:27:08 AM »
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

  • Full Member
  • ***
  • Posts: 154
Re: GetBlockSize request
« Reply #3 on: August 05, 2019, 02:07:05 PM »
Roy,
Because we don't use the same bounding box function.
--J

roy_043

  • Sr. Member
  • ****
  • Posts: 369
Re: GetBlockSize request
« Reply #4 on: August 06, 2019, 05:42:19 AM »
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

  • Full Member
  • ***
  • Posts: 154
Re: GetBlockSize request
« Reply #5 on: August 06, 2019, 08:32:08 AM »
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

  • Sr. Member
  • ****
  • Posts: 369
Re: GetBlockSize request
« Reply #6 on: August 06, 2019, 10:42:49 AM »
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

  • Full Member
  • ***
  • Posts: 154
Re: GetBlockSize request
« Reply #7 on: August 06, 2019, 10:53:01 AM »
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

  • Sr. Member
  • ****
  • Posts: 369
Re: GetBlockSize request
« Reply #8 on: August 07, 2019, 03:09:36 AM »
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

  • Sr. Member
  • ****
  • Posts: 369
Re: GetBlockSize request
« Reply #9 on: August 07, 2019, 06:48:34 AM »
Creating a replacement for dcl-GetBlockSize would be relatively simple in BricsCAD. It would be a little harder in AutoCAD, but not much.
Code: [Select]
(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

  • Full Member
  • ***
  • Posts: 154
Re: GetBlockSize request
« Reply #10 on: August 07, 2019, 08:06:29 AM »
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

  • Sr. Member
  • ****
  • Posts: 369
Re: GetBlockSize request
« Reply #11 on: August 08, 2019, 01:05:00 AM »
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

  • Full Member
  • ***
  • Posts: 154
Re: GetBlockSize request
« Reply #12 on: August 08, 2019, 09:05:17 AM »
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

  • Sr. Member
  • ****
  • Posts: 369
Re: GetBlockSize request
« Reply #13 on: August 09, 2019, 12:16:02 AM »
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.