Bounding box with offset code help

Bounding box with offset code help

atrotto
Enthusiast Enthusiast
938 Views
12 Replies
Message 1 of 13

Bounding box with offset code help

atrotto
Enthusiast
Enthusiast

Hello folks,

 

I'm just getting started with AutoLISP / Active X, and I cannot figure out why this isn't working. The bottom left corner of the rectangle drew with offset when I was testing with just mno, but when I replicated it with mxo, the code stops working. The bulk of this code is borrowed, leaving honorable mention in the comments. 

 

 

;;Foamstamp.lsp
;;Bounding code borrowed from BlackBox on CadTutor

(defun c:FoamStamp (/ eName mn mx mno mxo)
 (vl-load-com)
 (if (setq eName (car (entsel "\n  >>  Select Object  >> ")))
   (progn
     (vla-getboundingbox (vlax-ename->vla-object eName) 'mn 'mx)
     
     (vl-cmdf "._rectang" (
                            (setq mno (mapcar (lambda (a)(- a 0.25))(vlax-safearray->list mn)))
			    (setq mxo (mapcar (lambda (b)(+ b 0.25))(vlax-safearray->list mx)))
                          )
     ) 
    (princ)
   )
 )
)

 

0 Likes
Accepted solutions (1)
939 Views
12 Replies
Replies (12)
Message 2 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

It must be '(lambda... or (function (lambda...

Message 3 of 13

atrotto
Enthusiast
Enthusiast
Thanks, figured it was something simple...
0 Likes
Message 4 of 13

ВeekeeCZ
Consultant
Consultant

But this way would be more readable

 

(defun c:FoamStamp (/ eName mn mx mno mxo)
  (vl-load-com)
  (if (setq eName (car (entsel "\n  >>  Select Object  >> ")))
    (progn
      (vla-getboundingbox (vlax-ename->vla-object eName) 'mn 'mx)
      (vl-cmdf "._rectang"
	       (mapcar '+ (vlax-safearray->list mn) '(-0.25 -0.25))
	       (mapcar '+ (vlax-safearray->list mx) '(+0.25 +0.25)))))
  (princ)
  )

 

Message 5 of 13

atrotto
Enthusiast
Enthusiast
Even better. I was going down a rabbit hole with lambda mostly because it was the Neat New Thing I read about on the Autodesk resource. Thank you so much.
0 Likes
Message 6 of 13

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:
....
	       (mapcar '+ (vlax-safearray->list mn) '(-0.25 -0.25))
	       (mapcar '+ (vlax-safearray->list mx) '(+0.25 +0.25)))))
....

A small thing, but it seems a little odd to add negative numbers to the coordinates....  [And the plus signs on the numbers for the upper right are not needed.]  How about:

  (mapcar '- (vlax-safearray->list mn) '(0.25 0.25))

  (mapcar '+ (vlax-safearray->list mx) '(0.25 0.25)))))

Kent Cooper, AIA
Message 7 of 13

ВeekeeCZ
Consultant
Consultant

That is what I like about it. Directly see that it goes left and down. Don't have to think about what is subtracted from what... But I guess it's just a matter of personal preference.

Message 8 of 13

atrotto
Enthusiast
Enthusiast

@bee @Kent1Cooper 

 

Secondary question, does get-boundingbox work with multiple selected entities? As in, could I feed this code multiple objects, and would it be able to make a large bounding box around them?

0 Likes
Message 9 of 13

ВeekeeCZ
Consultant
Consultant
Message 10 of 13

Kent1Cooper
Consultant
Consultant

@atrotto wrote:

.... does get-boundingbox work with multiple selected entities? As in, could I feed this code multiple objects, and would it be able to make a large bounding box around them?


Not this Topic's code directly, but in addition to @ВeekeeCZ 's link, I also have a routine that will do that, called DrawBoundingBoxMult.lsp, >here<.  I imagine there are more out there for the Searching.  Any of them would need to be adjusted similarly to this topic if you want the box outboard of the actual extents by some distance.

Kent Cooper, AIA
Message 11 of 13

atrotto
Enthusiast
Enthusiast
Hello, I started looking into this code, but the way Lee approaches handling creating the polyline has me scratching my head as to where to sneak in the offset. Ideally, I'd like to do it in the testcode he gave, so that I could reference the bounding box protocol in a few other programs that would have different offsets.
Am I right in saying that I can't just jam the calculation into his block creating the point coordinates starting at line 21?
0 Likes
Message 12 of 13

ВeekeeCZ
Consultant
Consultant

Your line is this one

(setq box (LM:ssboundingbox sel))

(setq box (:offset box))

 

So add one more line below it and figure out the :offset function. It does not necessarily be a function, possibly just an expression that does the offset to coords saved as a list in box variable. 

0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor

Like BeekeeCZ the 'box'

 

 

(setq box (LM:SSBOUNDINGBOX (ssget)))
!pts ((20.0 38.0 0.0) (179.0 201.0 0.0))
so offset pts (car box) & (cadr box)

 

 

is 2 points as a list, so can apply the offset.

 

 

0 Likes