Bounding box lisp

Discussion in 'AutoCAD' started by Ralph Hampton, Oct 7, 2004.

  1. Hi,
    I need to draw the bounding box of a selected solid as a solid box.
    As I do it rather a lot I would like to do it more elegantly than
    listing the object, reading the coordinates, and typing into the box
    command.
    Does anyone know of or have any code that might help me do this?
    I have some limited alisp experience and use R14.

    TIA and regards,

    Ralph.
    -------------
     
    Ralph Hampton, Oct 7, 2004
    #1
  2. Ralph Hampton

    3ABTPA Guest

    I spend 15 minitutes to create this. It has very little error handling
    I usually require license if I spend more then 1 hour ;)

    (defun c:SolidOutline ( / enl pnt res cmd)
    (and (setq enl (entsel "\nSelect SOLID object to draw an outline: "))
    (setq enl (entget (car enl)))
    (= "SOLID" (cdr (assoc 0 enl)))

    (setq pnt (list (cons 'LIST (cdr (assoc 10 enl)))
    (cons 'LIST (cdr (assoc 11 enl)))
    (cons 'LIST (cdr (assoc 13 enl))) ))
    (or (equal (cdr (assoc 12 enl))
    (cdr (assoc 13 enl)) )
    (setq pnt (append pnt (list (cons 'LIST (cdr (assoc 12 enl))) ))))

    (or (initget "Polyline Line")
    (setq res (getkword "\nSelect outline object type
    [Polyline/Line]<Line>: "))
    (setq res "Line") ) ;_ Cancel/Esc will generate an error. Put some
    generic
    ;_ *error* function in the begining of this
    function
    (cond ( (= res "Line")
    (setq cmd "_LINE"))
    ( (= res "Polyline")
    (setq cmd "_PLINE")) )
    (setq cmd (cons 'command
    (append (list cmd)
    pnt
    '("_C") )))

    (setvar "CMDECHO" 0)
    (eval cmd)
    (setvar "CMDECHO" 1) )

    (princ)
    )
     
    3ABTPA, Oct 7, 2004
    #2
  3. Thanks very much - I should add that I am working with ACIS 3d solids.
    Sorry for not making that clear.
    If I get the assoc code of a simple sphere 100 dia drawn at 000 I get:

    ((-1 . <Entity name: 45708b0>) (0 . "3DSOLID") (5 . "196") (102 .
    "{ACAD_XDICTIONARY") (360 . <Entity name: 45708c0>) (102 . "}") (102 .
    "{ACAD_REACTORS") (330 . <Entity name: 45708c8>) (102 . "}") (100 .
    "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbModelerGeometry") (70 .
    1) (1 .
    "noi i n o ") (1 . "=0;& {rn {n {rn {rn |") (1 . "3*2/ {rn
    {rn {m {o
    |") (1 . ",7:33 {rn {rn {rn {l {n |") (1 . "9><: {k {rn {rn {m {rn {j 90-(>-;
    ,6183: |") (1 . "<030-r>;:,4r>++-6= {rn {rn {rn {l mji |") (1 .
    ",/7:-:r,*-9><:
    {rn o o o jo n o o o o n o V V V V |"))

    From which I cannot see where to extract the basic bounding box info:
    Lower Bound X = -50.00 , Y = -50.00 , Z = -50.00
    Upper Bound X = 50.00 , Y = 50.00 , Z = 50.00
    This I can get with the list command, and is instant whatever shape
    the solid. With complicated solids, just extracting the assoc data can
    grind my machine to a total halt.
    I was wondering if there was an elegant way of extracting this data
    from the "list" command - I've tried:
    (setq A (car (entsel)))
    (setq B (command "list" A ""))
    It runs the command and displays the data but doesn't assign it.
    I could use the massprop command, which has the option to write to a
    file, and extract it from that, but even that can take minutes with a
    complicated solid.

    Thanks for help anyway. Any further suggestions most appreciated.

    Regards,

    Ralph.


     
    Ralph Hampton, Oct 8, 2004
    #3
  4. Ralph Hampton

    Jeff Mishler Guest

    I believe this can be done in VBA in R14, but not lisp. It wouldn't take
    much of a routine to do what you want though.
    If you don't know VBA, I can look at it closer in the morning.
     
    Jeff Mishler, Oct 8, 2004
    #4
  5. Unfortunately I do not have VBA.
    I could use this as an excuse to learn it, but..
    Any help and your attention most appreciated.

    Regards,

    Ralph.
     
    Ralph Hampton, Oct 8, 2004
    #5
  6. Crikey, thanks.
    I will play with it tommorow.
    You wonderful people you.

    Regards,

    Ralph.
     
    Ralph Hampton, Oct 8, 2004
    #6
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.