Extmin/Extmax for only objects selected?

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

  1. Robert Grandmaison

    John Uhden Guest

    Here's a version of Doug's that has probably more error trapping than needed...
    (defun c:bounds (/ llc urc ll ur ss doc bad limits)
    ;;c. 07-10-03
    ;;D. C. Broad, Jr. Demonstration for bounds selection
    ;;Returns the bounds of a selection set
    ;;Modified (07-12-03) by John Uhden to look for failures
    (and
    (vl-load-com)
    (setq bad 0)
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (ssget
    (list
    (cons 410
    (if (= (getvar "cvport") 0)
    (getvar "ctab")
    "Model"
    )
    )
    )
    )
    (or
    (setq ss (vla-get-activeselectionset doc))
    (prompt "\nFailed to get ActiveSelectionSet")
    )
    (vlax-for n ss
    (vla-getboundingbox n 'll 'ur)
    (cond
    ((not (and ll ur))(setq bad (1+ bad)))
    (llc
    (setq llc (mapcar 'min llc (vlax-safearray->list ll)))
    (setq urc (mapcar 'max urc (vlax-safearray->list ur)))
    )
    (1
    (setq llc (vlax-safearray->list ll))
    (setq urc (vlax-safearray->list ur))
    )
    )
    )
    (or
    (= bad 0)
    (princ (strcat "\nFailed to get " (itoa bad) " object boundaries"))
    )
    llc
    urc
    (setq limits (list llc urc))
    )
    limits
    )

    I do notice that (vla-zoomwindow) will still leave extra space around the edges
    in a twisted view, but at least it's actually a little less than what a
    ZoomExtents would give. This is understandable since AutoCAD is probably
    accounting for pixel sizes. Or the ENTEXTS variable may have an effect.
    Anyway, close enough.
     
    John Uhden, Jul 12, 2003
    #21
  2. Robert Grandmaison

    Doug Broad Guest

    Hi John,
    Mine still stinks in paper space.
    1) It should apply the zoom to the current paperspace viewport
    but the vla-zoomwindow method does not support pspace viewport
    zooming. I'll have to look into options here when I have more time.
    (command "zoom"....) looks like the best choice for Q&D.

    2) When in paper space, mine finds the system paperspace viewport
    as well as user defined viewports when using "ALL" selection.
    That makes it poor when trying to simulate a zoom extents.

    Back to the drawing board...
     
    Doug Broad, Jul 12, 2003
    #22
  3. Robert Grandmaison

    John Uhden Guest

    Look back up to my reply to Joe this morning. Just hafta add the filter.
     
    John Uhden, Jul 12, 2003
    #23
  4. Robert Grandmaison

    Doug Broad Guest

    John,
    Yes I see. But either the filter needs tweaking or there needs to be
    a way to eliminate the system pspace viewport from the selection set.
    Here is another version that uses your filter. Thanks. I'm going
    to look more closely at the other features of your version.

    (vl-load-com)
    ;;D. C. Broad, Jr. Demonstration for bounds selection
    ;;Returns the bounds of a selection set
    (defun c:bounds (/ llc urc ll ur ss doc)
    (setq doc (vla-get-activedocument (vlax-get-acad-object))
    )
    (if (ssget
    (list
    (cons 410
    (if (= (getvar "cvport") 1)
    (getvar "ctab")
    "Model"
    )
    )
    )
    )
    ;;proceed if any objects selected
    (progn
    (vlax-for n (vla-get-activeselectionset doc)
    (if
    ;;only consider those having a bounding box
    (vlax-method-applicable-p n 'getboundingbox)
    (progn
    (vla-getboundingbox n 'll 'ur)
    (setq llc
    (if llc
    (mapcar 'min llc (vlax-safearray->list ll))
    (vlax-safearray->list ll))
    urc
    (if urc
    (mapcar 'max urc (vlax-safearray->list ur))
    (vlax-safearray->list ur))
    ))))))
    ;;return value is the list of points or
    ;;(nil nil)
    (list llc urc))

    (defun c:z2 ()
    (setq bounds (c:bounds))
    ;;unlike the zoom command, vla-zoomwindow uses world
    ;;coordinate system points to paint the view. This
    ;;makes the current UCS and viewtwist irrelevant.
    ;;The following doesn't assume bounds were found.
    (if (car bounds)
    (vla-zoomwindow
    (vlax-get-acad-object)
    (vlax-3d-point (car bounds))
    (vlax-3d-point (cadr bounds))
    )
    (princ "\nNo bounds found"))
    (princ))
     
    Doug Broad, Jul 12, 2003
    #24
  5. Robert Grandmaison

    John Uhden Guest

    Along with fixing my stupid (= (getvar "cvport") 0), this'll take take of some
    more problems...
    (defun c:bounds (/ llc urc ll ur ss doc bad limits avp)
    ;;c. 07-10-03
    ;;D. C. Broad, Jr. Demonstration for bounds selection
    ;;Returns the bounds of a selection set
    ;;Modified (07-12-03) by John Uhden to look for failures
    (and
    (vl-load-com)
    (setq bad 0)
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (setq avp (vla-get-activepviewport doc))
    (ssget
    (list
    (cons 410
    (if (= (getvar "cvport") 1)
    (getvar "ctab")
    "Model"
    )
    )
    )
    )
    (or
    (setq ss (vla-get-activeselectionset doc))
    (prompt "\nFailed to get ActiveSelectionSet")
    )
    (vlax-for n ss
    (setq ll nil ur nil)
    (vl-catch-all-apply
    'vla-getboundingbox
    (list n 'll 'ur)
    )
    (cond
    ((equal n avp))
    ((not (and ll ur))(setq bad (1+ bad)))
    (llc
    (setq llc (mapcar 'min llc (vlax-safearray->list ll)))
    (setq urc (mapcar 'max urc (vlax-safearray->list ur)))
    )
    (1
    (setq llc (vlax-safearray->list ll))
    (setq urc (vlax-safearray->list ur))
    )
    )
    )
    (or
    (= bad 0)
    (princ (strcat "\nFailed to get " (itoa bad) " object boundaries"))
    )
    llc
    urc
    (setq limits (list llc urc))
    )
    limits
    )
     
    John Uhden, Jul 12, 2003
    #25
  6. Robert Grandmaison

    Joe Burke Guest

    John,

    You're reading my brain.
    Yes, "anyway close enough" when it doesn't zoom in as close as it should. I
    think for cosmetic reasons it should not zoom tight. But what about when it
    zooms in too far in a twisted view? That's as likely, and doesn't seem
    acceptable to me. I was thinking (watch out) maybe check the point list
    against the view coordinates after zoom. If a point falls outside, do
    something to fix the zoom, i.e., zoom out a bit.

    Joe
     
    Joe Burke, Jul 12, 2003
    #26
  7. Robert Grandmaison

    John Uhden Guest

    Never mind. That's really sloppy.
     
    John Uhden, Jul 12, 2003
    #27
  8. Robert Grandmaison

    John Uhden Guest

    I haven't noticed a "too tight" result as yet.
     
    John Uhden, Jul 12, 2003
    #28
  9. Robert Grandmaison

    John Uhden Guest

    It really doesn't matter where you put (vl-load-com) so long as you call it
    before doing vl-thingies.

    Here we go:
    (defun c:bounds (/ llc urc ll ur ss doc bad limits avp)
    ;;c. 07-10-03
    ;;D. C. Broad, Jr. Demonstration for bounds selection
    ;;Returns the bounds of a selection set
    ;;Modified (07-12-03) by John Uhden to look for failures
    (vl-load-com)
    (and
    (setq bad 0)
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (or
    (= (getvar "ctab") "Model")
    (setq avp (vla-get-activepviewport doc))
    )
    (ssget
    (list
    (cons 410
    (if (= (getvar "cvport") 1)
    (getvar "ctab")
    "Model"
    )
    )
    )
    )
    (or
    (setq ss (vla-get-activeselectionset doc))
    (prompt "\nFailed to get ActiveSelectionSet")
    )
    (vlax-for n ss
    (setq ll nil ur nil)
    (vl-catch-all-apply
    'vla-getboundingbox
    (list n 'll 'ur)
    )
    (cond
    ((equal n avp))
    ((not (and ll ur))(setq bad (1+ bad)))
    (llc
    (setq llc (mapcar 'min llc (vlax-safearray->list ll)))
    (setq urc (mapcar 'max urc (vlax-safearray->list ur)))
    )
    (1
    (setq llc (vlax-safearray->list ll))
    (setq urc (vlax-safearray->list ur))
    )
    )
    )
    (or
    (= bad 0)
    (princ (strcat "\nFailed to get " (itoa bad) " object boundaries"))
    )
    (setq limits (vl-remove nil (list llc urc)))
    )
    limits
    )

    Gotta go; sun is shining!
     
    John Uhden, Jul 12, 2003
    #29
  10. Robert Grandmaison

    Joe Burke Guest

    John,

    There's an example file in CF.

    Joe


     
    Joe Burke, Jul 12, 2003
    #30
  11. Robert Grandmaison

    John Uhden Guest

    AUGH! I downloaded and tried it. You're absolutely right. Too close!
    Methinks it's those blasted LWPOLYLINEs again. Nope; exploded it and got the
    same results.
    Hmmm... there's something different in your drawings from mine. I erased all
    your objects, drew a circle, and got the same truncated results. It's not
    ENTEXTS. Don't know what it is!?

    Gotta go, get some sleep, take care of a client in the morning, and prime the
    other side of 300' of fence in the afternoon.
     
    John Uhden, Jul 13, 2003
    #31
  12. Robert Grandmaison

    Joe Burke Guest

    John,

    Ain't no mystery. :)

    Try this. Take "limits" or "llc urc" out of bounds local vars. Run bounds on
    the pline. Draw a rectangle using the two coordinates. Zoom window with the
    coordinates.

    Later... Joe
     
    Joe Burke, Jul 13, 2003
    #32
  13. Robert Grandmaison

    John Uhden Guest

    I would but I'm too tired. You do it for me, and let me know. :]
     
    John Uhden, Jul 14, 2003
    #33
  14. Robert Grandmaison

    Doug Broad Guest

    Joe,
    Since the vl-get-bounding box returns the WCS coordinates, it assumes a
    certain orientation. In order to adjust the bounding box to the correct
    viewtwist, you would need to temporarily rotate the objects, obtain that
    bounding box and then rotate them back before zooming. Rotating the
    bounding box coordinates after the fact would not help IMO because
    it would not return an appropriate box. For this technique you would
    need to get the boundingbox twice, once to determine the central rotation
    point and once to determine the bounds with the correct rotation.

    Another workaround (not recommended) would be to have the program
    temporarily erase all the objects in the current space except those selected,
    do a zoomextents, and then undelete the other objects.

    Since I rarely use viewtwist, such a programming task would not have
    a payback given the marginal improvement.

    I look forward to seeing your solution.
    Regards,
    Doug
     
    Doug Broad, Jul 14, 2003
    #34
  15. Robert Grandmaison

    Joe Burke Guest

    Too much fence painting, John?

    Joe


     
    Joe Burke, Jul 14, 2003
    #35
  16. Robert Grandmaison

    mhr Guest

    ------------Specifically, I want to build a "zoom to objects" kind of thing

    I'm not trying to be mean, but I'm curious as to why something like this would even be needed. If you have to make a selection anyway then why not just use "Zoom Window" and simply select two points around the objects you want to view? What am I missing that you are trying to accomplish? Selecting objects seems far more cumbersome then just two corners.
     
    mhr, Jul 14, 2003
    #36
  17. Robert Grandmaison

    mhr Guest

    OOPS

    ------------Specifically, I want to build a "zoom to objects" kind of thing.

    I'm not trying to be mean, but I'm curious as to why something like this would even be needed. If you have to make a selection anyway then why not just use "Zoom Window" and simply select two points around the objects you want to view? What am I missing that you are trying to accomplish? Selecting objects seems far more cumbersome then just two corners.
     
    mhr, Jul 14, 2003
    #37
  18. Robert Grandmaison

    Joe Burke Guest

    mhr,



     



    Ever seen objects shot into outer space due to user error? This is a good way to zoom in on them, then decide whether they should be moved back or deleted.



     



    Joe Burke



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

    OOPS

    ------------Specifically, I want to build a "zoom to objects" kind of thing.


    I'm not trying to be mean, but I'm curious as to why something like this would even be needed. If you have to make a selection anyway then why not just use "Zoom Window" and simply select two points around the objects you want to view? What am I missing that you are trying to accomplish? Selecting objects seems far more cumbersome then just two corners.
     
    Joe Burke, Jul 14, 2003
    #38
  19. Robert Grandmaison

    Joe Burke Guest

    Doug and John,

    I tried my "recent thought" below. It didn't help. Which proves one thing: I
    don't understand the problem.

    I haven't given up. It's just on the back-burner for now. I still think
    there's an elegant solution out there somewhere. Seems to me there's enough
    information known, or can be derived, to solve it.

    Joe
     
    Joe Burke, Jul 15, 2003
    #39
  20. Robert Grandmaison

    John Uhden Guest

    I understand it. Just have no time to write it. As either you or Doug pointed
    out, you have to check all four corners of the boundingbox because twist angles
    like your 300 degrees cause the "zoom in too far" symptom, whereas like 45
    degrees works about the same as a stock AutoCAD ZoomExtents. I was thinking of
    using ZoomCenter instead, with the height derived from the min/max of all four
    corners translated to OCS (0 2). Actually, the width and height should both be
    checked against the ViewSize proportion.
     
    John Uhden, Jul 16, 2003
    #40
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.