Extmin/Extmax for only objects selected?

Discussion in 'AutoCAD' started by Robert Grandmaison, Jul 8, 2003.

  1. Is there an easy, quick way of getting the minimum XYZ and maximum XYZ
    values for a selection set?

    Thanks,

    Robert
     
    Robert Grandmaison, Jul 8, 2003
    #1
  2. Robert Grandmaison

    Mark Propst Guest

    don't know if you consider it easy or quick, but you get the bounding box
    for each item, save the least and most points as variables, checking each
    ents least and most against them and updating if necessary, and when you're
    done you have the least and most of the whole grouping
    or I suppose you could make a block out of them, get the bounding box for
    the block, and then explode and purge the temp block?
     
    Mark Propst, Jul 8, 2003
    #2
  3. lol, I know I can do that- was hoping for some kind of VLA trick! The
    operative word there was EASY! ; )

    Robert
     
    Robert Grandmaison, Jul 8, 2003
    #3
  4. Robert Grandmaison

    Jason Wilder Guest

    Well, part of it may be a matter of understanding how you're getting your
    list of points and then creating a selection set of them?

    Are you trying to get the min/max XYZ of a selection set of objects? Or are
    you somehow generating a selection set of point lists?

    (vl-sort) may be what you're looking for, but you'll need to make the
    appropriate list/selection set. Also, what are you looking for? the
    min/max X, Y, or Z? or of each?

    You've left this fairly vague. :)
     
    Jason Wilder, Jul 8, 2003
    #4
  5. Okay, I'll be more specific! I want to allow a user to select multiple
    objects and then return the minimum and maximum XYZ points that would be
    required to place a bounding box around those objects.

    Specifically, I want to build a "zoom to objects" kind of thing. I was
    hoping there was an easy way to do this via properties and selection sets,
    rather than having to sort through/compare/replace potentially long lists of
    object point values with lower ones.

    Robert
     
    Robert Grandmaison, Jul 8, 2003
    #5
  6. Robert Grandmaison

    Jason Wilder Guest

    Sorry, didn't mean to prod... just thought that if there were a little more
    information, there might be a little more clarity for someone to help you,
    or someone may very well have a routine already done they can share. I
    apologize that I don't already, but I'm always willing to help when I can.
     
    Jason Wilder, Jul 8, 2003
    #6
  7. Robert Grandmaison

    morrisde Guest

    Yes you can do that fairly easily, the vla function you're after is vla-getboundingbox. Step through the selection set, do a vla-getboundingbox on each and check if the min/max points are smaller/bigger than the previous entities' points. Regards,
    Dave
     
    morrisde, Jul 9, 2003
    #7
  8. Robert Grandmaison

    Joe Burke Guest

    Just starting to get the hang of this vlisp stuff.

    ;;Joe Burke 7/8/2003
    ;;zoom to selection set bounding box
    (defun C:ZoomSS ( / SS i Vobj PtLst MinPt MaxPt Pts)
    (if (not (setq SS (ssget "I")))
    (progn
    (princ "\nSelect objects to zoom: ")
    (setq SS (ssget))
    )
    )
    (and SS
    (setq i 0)
    (repeat (sslength SS)
    (setq Vobj (vlax-ename->vla-object (ssname SS i)))
    (vla-getboundingbox Vobj 'MinPt 'MaxPt)
    (setq PtLst (cons (vlax-safearray->list MinPt) PtLst))
    (setq PtLst (cons (vlax-safearray->list MaxPt) PtLst))
    (setq i (1+ i))
    )
    (setq Pts
    (mapcar '(lambda (x) (trans x 0 1)) ;wcs to ucs
    (list (apply 'mapcar (cons 'min PtLst))
    (apply 'mapcar (cons 'max PtLst))
    )
    )
    )
    )
    (command "_zoom" "w" (car Pts) (cadr Pts) "zoom" ".9x")
    ;(sssetfirst nil SS)
    (princ)
    ) ;end
     
    Joe Burke, Jul 9, 2003
    #8
  9. Robert Grandmaison

    Joe Burke Guest

    Yes sir  :)



     



    Joe



    "morrisde" <> wrote in message news:...

    Yes you can do that fairly easily, the vla function you're after is vla-getboundingbox. Step through the selection set, do a vla-getboundingbox on each and check if the min/max points are smaller/bigger than the previous entities' points. Regards,
    Dave
     
    Joe Burke, Jul 9, 2003
    #9
  10. Beautiful! That's just what I wanted!

    I'll make sure to include your header credit.

    Thanks,

    Robert
     
    Robert Grandmaison, Jul 9, 2003
    #10
  11. Robert Grandmaison

    John Uhden Guest

    Nice work, Joe & Tony.
    The nasty downside is how to deal with twisted views since the bounding box is
    always orthogonal to the WCS. I finally built a PLBoundingBox function for
    polylines in a twisted view, but the rest of the object domain is more than I
    care to take on. Well, at least we could handle circles okay. :/
     
    John Uhden, Jul 10, 2003
    #11
  12. Robert Grandmaison

    Steve Doman Guest

    Excellenta! ;^)

    Steve Doman
     
    Steve Doman, Jul 10, 2003
    #12
  13. Robert Grandmaison

    Joe Burke Guest

    Thanks, John :)

    I don't quite follow the twisted view problem. I see the function I posted
    doesn't work right in some cases given a twisted view, but why isn't clear
    to me. In a twisted view you are still in WCS, right?

    Anyway, here's a revised version which tries to fix the problem. It's a bit
    of a hack, designed primarily so it's obvious what I'm trying to do. It
    seems to work. Though frankly, I don't know much about twisted views. When I
    want to do this, I rotate the UCS.

    Joe

    ;;Joe Burke revised 7/9/2003
    ;;zoom to selection set bounding box
    (defun C:ZoomSS ( / SS i Vobj PtLst MinPt MaxPt Pts LL UR)
    (vl-load-com)
    (if (not (setq SS (ssget "I")))
    (progn
    (princ "\nSelect objects to zoom: ")
    (setq SS (ssget))
    )
    )
    (and SS
    (setq i 0)
    (repeat (sslength SS)
    (setq Vobj (vlax-ename->vla-object (ssname SS i)))
    (vla-getboundingbox Vobj 'MinPt 'MaxPt)
    (setq PtLst (cons (vlax-safearray->list MinPt) PtLst))
    (setq PtLst (cons (vlax-safearray->list MaxPt) PtLst))
    (setq i (1+ i))
    )
    (setq Pts
    (mapcar '(lambda (x) (trans x 0 1)) ;wcs to ucs
    (list (apply 'mapcar (cons 'min PtLst))
    (apply 'mapcar (cons 'max PtLst))
    )
    )
    )
    ;move points out a bit
    (setq LL (car Pts) UR (cadr Pts)
    LL (polar UR (angle UR LL) (* 1.1 (distance LL UR)))
    UR (polar LL (angle LL UR) (* 1.1 (distance LL UR)))
    )
    ) ;and

    (if (not (equal 0.0 (getvar "viewtwist")))
    (progn
    (setq RotPts
    (RotatePts (list LL UR) (MidPoint LL UR) (getvar "viewtwist")))
    (command "_zoom" "w" (car RotPts) (cadr RotPts))
    )
    (command "_zoom" "w" LL UR) ;else
    ) ;if
    (princ)
    ) ;end

    ;arguments: point list, base point, angle
    (defun RotatePts (plst bp ang)
    (mapcar '(lambda (p)
    (polar bp (+ (angle bp p) ang) (distance bp p)))
    plst
    )
    )

    (defun MidPoint (p1 p2)
    (mapcar '/ (mapcar '+ p1 p2) '(2.0 2.0 2.0))
    )
    ;---------------------------
     
    Joe Burke, Jul 10, 2003
    #13
  14. Robert Grandmaison

    Joe Burke Guest

    Thanks, Steve.

    I recall when I was so stupid about this stuff... and you helped me. That
    exchange might have seemed pointless at the time. It wasn't.

    Joe
     
    Joe Burke, Jul 10, 2003
    #14
  15. Robert Grandmaison

    John Uhden Guest

    Interesting idea with the RotatePts, but the BoundingBox of any object except a
    circle will have different widths and heights depending on its orientation.
    For example, draw a line one unit long at 45 degrees (0,0,0 to 1,1,0).
    The BoundingBox (W x H) will be 0.707 x 0.707.
    Now do a DView;Twist by 45 degrees CCW, whatever, to make the line vertical.
    The BoundingBox relative to the screen should be 0.0 x 1.0, but the BoundingBox
    method will still return 0.707 x 0.707.
    It ain't so easy figuring out what the BoundingBox of a collection of objects
    would be if rotated without actually rotating them first, which I wouldn't
    recommend tryng in a topographic survey having 35000+ enitities.
     
    John Uhden, Jul 10, 2003
    #15
  16. Robert Grandmaison

    Joe Burke Guest

    John,

    Given your example, I see the problem. But of course, I don't know how to
    fix it.

    Interesting... ToolPac 7 has a similar command, which does seem to work
    right given your example. I guess Terry knows something we don't?

    Whatever, the problem is a tempest in a teapot as far as I'm concerned since
    I don't use twisted views.

    Here's a more important question. Should I use (vl-catch-all-apply 'function
    list) somewhere in the program? If so, how to do that is sure a mystery to
    me. When/if you have time, please show me how given my first post.

    Thanks
    Joe
     
    Joe Burke, Jul 11, 2003
    #16
  17. Robert Grandmaison

    Joe Burke Guest

    Doug,

    Thanks. That's very interesting. Interesting enough that I went back and
    tried John's twisted view one unit line example again using the first
    function I posted. Forget the second one, it's trash. Anyway, here's what I
    see. Pts is the variable in ZoomSS.



    Command: viewtwist
    VIEWTWIST = 45.00 (read only)

    Command: bounds
    1 found
    ((0.0 0.0 0.0) (0.707107 0.707107 0.0))

    Command: zoomss

    Command: !pts
    ((0.0 0.0 0.0) (0.707107 0.707107 0.0))

    Which is what John said. But unless I'm mistaken, that's the right answer in
    this case. Both Z2 and ZoomSS zoom exactly to the ends of the line.

    So John, what am I missing here...?

    Joe
     
    Joe Burke, Jul 12, 2003
    #17
  18. Robert Grandmaison

    Joe Burke Guest

    John,

    Maybe what I'm missing is just the fact the example you mentioned doesn't
    demonstrate the problem on screen? Both functions tend to zoom in too far in
    a twisted view. Testing with a zig-zag pline in a twisted view, I see why
    now.

    Doug,

    I probably misread your intent. I thought you were saying "bounds" would fix
    the twisted view thing. Now I think you were simply demonstrating a
    different way to arrive at the answer.

    Joe < thick as usual
     
    Joe Burke, Jul 12, 2003
    #18
  19. Robert Grandmaison

    John Uhden Guest

    What we're both missing is that Doug is a lot smarter than we look. :]
    I had my head screwed on in the manner of (command "_.zoom" ...) which provides
    the ugly results I described. Magically, Doug (either by psyche, luck,
    experimentation, or just plain smarts) found that the 'ZoomWindow method
    "thinks" the same as its ActiveX brother (er.. sister, cousin, whatever).

    Hats off (displaying our vaccuum brains) to Doug!
    Okay, okay... feel free to change "we" to "me" etc.
    Of course, now I'm sitting here dumbfounded as to what I was trying to do back
    when I had concluded there was a problem.
    Dunno, but I just found some code I actually sold back in 01/2002 that used the
    same approach as Doug's. Sheesh, I wish I could search my brain as easily as my
    hard drive. :/ Maybe my brain needs defragging.

    Then again, I did manage to create some kind of problem...
    Command: Z2
    Select objects: ALL
    4 found

    Select objects:
    ; error: Automation Error. Null extents

    We'll have to figure out whazupwithat.
     
    John Uhden, Jul 12, 2003
    #19
  20. Robert Grandmaison

    John Uhden Guest

    Baloney. At best I'm AAA. I figure you'll be called up to the majors pretty
    soon. Keep slugging.
    What's neat is that this topic can probably keep any number of us churning our
    grey matter for a while, unless of course Tony figured all this out 5 years ago.
    :)




     
    John Uhden, Jul 12, 2003
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.