Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

vla_getBoundingBox return bad results for Z value

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Scottu2
545 Views, 5 Replies

vla_getBoundingBox return bad results for Z value

The lisp routine displays point values of a boundry (window) of an object using the vla_getBoundingBox.

The concept of the routine is to select any object and return two Point window value.

This routine works, but I noticed the Z point is changing depending on the object type drawn in 2d space elevation 0.0.

Did I miss something in the code?

 

Test: Open a new drawing.  Set the snap value to 1.0 just to make is easy to see values.

Draw three objects: A horizonal line, A Rectangle and Arc.

Load the gbb.lsp and run it, gbb

Select all three objects and notice the results.

It appears that objects the have an curve change the Z value (very little), but Z should be zero.

Try it with a polyline and then PEdit and FIT and re-check the Z value.

 

See the attached Code.

 

5 REPLIES 5
Message 2 of 6
dbroad
in reply to: Scottu2

See the following command prompt sequence:

Command: (vla-getboundingbox a 'llc 'urc)
nil

Command: !llc
#<safearray...>

Command: (setq llc (vlax-safearray->list llc))
(8.96083 9.49023 0.0)

Command: (cons llc 0)
((8.96083 9.49023 0.0) . 0)

 

As you can see, vla-getboundingbox returns a full 3d coordinate.  No need to add a z coordinate.

 

Cons normally takes a list as the second element.  The exception is for a dotted list (association list).  Your cons is not resulting in an xyz list.

 

I am not sure that the undo group and end commands do any good here.  At most you can begin with an undo end if you don't want to group the current command.  You should be using *error* if you do want to group the undo.  I normally keep cmdecho set to 0 so no need to toggle it off with every lisp.

 

Hope this helps.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 6
Kent1Cooper
in reply to: Scottu2


@Scottu2 wrote:

The lisp routine displays point values of a boundry (window) of an object using the vla_getBoundingBox.

....

This routine works, but I noticed the Z point is changing depending on the object type drawn in 2d space elevation 0.0.

....


I think this is just "one of those things" about the way AutoCAD calculates or derives certain values.  Those Z components are, for most practical purposes, pretty much the same as zero [10 to the minus-8 is really tiny], but no, they're not all being returned as absolutely zero as you would rightly expect.  This is why, if testing for equality of values when any of them result from a calculation or derivation such as this, it is often necessary to use the (equal) function with a little bit of a fuzz factor, rather than use (=).  If you need to use the resulting Z components for something, and need them to be truly zero in this situation, you may need to round them off [there are various rounding-to-the-nearest-multiple-of-something routines on this forum].

Kent Cooper, AIA
Message 4 of 6
Lee_Mac
in reply to: Scottu2


@Scottu2 wrote:

This routine works, but I noticed the Z point is changing depending on the object type drawn in 2d space elevation 0.0.


This is a known issue with the ActiveX getboundingbox method; however, if you are using the method solely to calculate the extents of 2D objects, since the method calculates the bounding box with respect to the WCS plane and also returns points wrt WCS, you can ignore the Z-coordinate for 2D objects, e.g.:

 

(vla-getboundingbox <VLA-Object> 'llp 'urp)
(setq llp (mapcar '+ (vlax-safearray->list llp) '(0 0))
      urp (mapcar '+ (vlax-safearray->list urp) '(0 0))
)

 

Message 5 of 6
Scottu2
in reply to: Lee_Mac

Thanks guys for the quick reply.

I revised the code per your comments. 

The Undo Group & Undo End places a marker to stop the undo command; otherwise, the undo includes the lisp and previous command.

The Z components are not needed for this routine.  The rounding routines sound interesting.

Revised code attached.

Thank again.

Message 6 of 6
Lee_Mac
in reply to: Scottu2

Here is another version to consider:

(defun c:gbb3 ( / idx llp obj urp )
    (setq idx 0)
    (while
        (progn (setvar 'errno 0) (setq obj (car (entsel)))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (= 'ename (type obj))
                    (setq obj (vlax-ename->vla-object obj))
                    (if (vlax-method-applicable-p obj 'getboundingbox)
                        (progn
                            (vla-getboundingbox obj 'llp 'urp)
                            (setq llp (vlax-safearray->list llp)
                                  urp (vlax-safearray->list urp)
                            )
                            (princ 
                                (strcat "\n" (itoa (setq idx (1+ idx)))
                                    " pt1: " (rtos (car llp)) "," (rtos (cadr llp))
                                    " pt2: " (rtos (car urp)) "," (rtos (cadr urp))
                                )
                            )
                        )
                        (princ "\nInvalid object selected.")
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Or, for a touch of obfuscation:

(defun c:gbb4 ( / idx llp obj urp )
    (setq idx 0)
    (while
        (progn (setvar 'errno 0) (setq obj (car (entsel)))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (= 'ename (type obj))
                    (setq obj (vlax-ename->vla-object obj))
                    (if (vlax-method-applicable-p obj 'getboundingbox)
                        (princ
                            (strcat "\n" (itoa (setq idx (1+ idx)))
                                (apply 'strcat
                                    (mapcar
                                        (function
                                            (lambda ( a b )
                                                (strcat a
                                                    (apply 'strcat
                                                        (mapcar 'strcat
                                                            (mapcar 'rtos (vlax-safearray->list b))
                                                           '("," "")
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                       '(" pt1: " " pt2: ")
                                        (progn (vla-getboundingbox obj 'llp 'urp) (list llp urp))
                                    )
                                )
                            )
                        )
                        (princ "\nInvalid object selected.")
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost