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

Draw multiple temporary box via 2-points

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Scottu2
1870 Views, 6 Replies

Draw multiple temporary box via 2-points

The program concept is like... discussing a drawing with serveral people and highlight areas on the drawing.  

 

How can I draw multiple bounding boxes by way of selecting 2-points to create the window?

 

I want to store the points in a selection set to recall and redraw the boxes, but not draw real objects stored in the drawing, just for the lisp routine only.

 

Thanks.

 

6 REPLIES 6
Message 2 of 7
_Tharwat
in reply to: Scottu2

Like this ?

(defun c:Test (/ s1 e1 s2 e2 1p 2p 3p 4p)
  ;;	Tharwat 03.07.2014	;
  (if (and (setq s1 (car (entsel "\n Select First point object :")))
           (eq (cdr (assoc 0 (setq e1 (entget s1)))) "POINT")
           (setq s2 (car (entsel "\n Select Second point object :")))
           (eq (cdr (assoc 0 (setq e2 (entget s2)))) "POINT")
      )
    (grvecs (list -1
                  (setq 1p (cdr (assoc 10 e1)))
                  (setq 2p (list (car 1p) (cadr (setq 3p (cdr (assoc 10 e2))))))
                  2p
                  3p
                  3p
                  (setq 4p (list (car 3p) (cadr 1p)))
                  4p
                  1p
            )
    )
  )
  (princ)
)

 

Message 3 of 7
Kent1Cooper
in reply to: Scottu2


@Scottu2 wrote:

.... discussing a drawing with serveral people and highlight areas on the drawing.  

 

How can I draw multiple bounding boxes by way of selecting 2-points to create the window?

 

I want to store the points in a selection set to recall and redraw the boxes, but not draw real objects stored in the drawing, just for the lisp routine only.

.... 


I'd like a little more explanation....  Does "highlight areas" mean highlight the objects in those areas in object-selection fashion, or just outline those areas with boxes?  Does "selecting 2 points" mean selecting 2 locations for each box, presumably defining opposite corners, or selecting Point entities [as _Tharwat interpreted it]?  Does "store the points" really mean in a selection set [for which Point entities would be necessary] or in something like a list of pairs of point locations, from which the boxes could be reconstructed?

Kent Cooper, AIA
Message 4 of 7
Scottu2
in reply to: Kent1Cooper

Thanks guys for the reply.

To clarify the routine will ask for points (getpoint) because i want to window the area of conversation.

Tharwat's test routine requires an entity. Perhaps I will use this code for something later thanks.

 

Kent1 the meaning of Highlight for this routine would be like a selected pline-rectangle.

I don't want to select objects within the window because the more objects the slower the routine.

As for the Store the points, yes place the (getpoint) object into a Selection Set to be redrawn as Highlighted areas base on points.

 

The key point is these areas are temporary, so if i cancel the routine and click save they do not save with the drawing, but are retained in the Selection Set.

 

Message 5 of 7
_Tharwat
in reply to: Scottu2

So this might be enough .

 

(and (setq 1p (getpoint "\n Specify first point :"))
           (setq 2p (getcorner "\n Specify opposite corner :" 1p))
      )

 

Message 6 of 7
Kent1Cooper
in reply to: Scottu2


@Scottu2 wrote:

.... 

Kent1 the meaning of Highlight for this routine would be like a selected pline-rectangle.

.....

As for the Store the points, yes place the (getpoint) object into a Selection Set to be redrawn as Highlighted areas base on points.

 

The key point is these areas are temporary, so if i cancel the routine and click save they do not save with the drawing, but are retained in the Selection Set.


Some terminology confusion....  They would not be "objects" [a.k.a. "entities"] -- that's not what (getpoint) returns -- but points in the locational sense [lists of XYZ coordinates], and what they would be saved in would not be a Selection Set [which can only contain "objects"], but probably most efficiently, a list as a variable.  Here's a way to do it for multiple boxes [minimally tested]:

 

(defun C:GetBoxes (/ pta ptb)
  (while
    (setq pta (getpoint "\nFirst corner of a box: "))
    (setq
      ptb (getcorner pta "\nOther corner: ")
      boxlist (cons (list pta ptb) boxlist)
    ); setq
  ); while
  (C:ShowBoxes)
); defun

 

(defun C:ShowBoxes ()
  (if boxlist
    (foreach pair boxlist ; then
      (grvecs
        (list
          -31 ; Edit for preferred color [negative = highlighted]
          (car pair) (list (caar pair) (cadadr pair))
          (car pair) (list (caadr pair) (cadar pair))
          (cadr pair) (list (caar pair) (cadadr pair))
          (cadr pair) (list (caadr pair) (cadar pair))
        ); list
      ); grvecs
    ); foreach
    (prompt "\nMust use GetBoxes first."); else
  ); if
); defun

 

Load those up, and type GetBoxes to specify your corners, after which they highlighted rectangles will appear.  They won't survive Panning or Zooming or Regening, but if you want them back, type ShowBoxes and they're re-appear.

Kent Cooper, AIA
Message 7 of 7
Scottu2
in reply to: Kent1Cooper

Kent,

Your awesome!

I now have a core program to work with.

I made some quick adjustmets to the code, shown below.

Thanks.

 

 

(defun C:GetBoxes (/ pta ptb)
(setvar "cmdecho" 0)
(c:ShowBoxes)
(while
(setq ok (strcase (getstring "\nClear Undo Show <W>indow:")))
(if (= ok "C") (progn (setq boxlist nil) (Prompt "Cleared boxes ") (command "redraw")))
(if (= ok "S") (c:showboxes))
(if (= ok "U") (progn
(setq boxlist (cdr boxlist))
(prompt "Undo last Box ")(command "redraw")(c:showboxes)
)
)
(setq pta (getpoint "\nFirst corner of a box: "))
(setq
ptb (getcorner pta " Other corner: ")
boxlist (cons (list pta ptb) boxlist)
); setq
(c:ShowBoxes)
); while
); defun

(defun C:ShowBoxes ()
(if boxlist
(foreach pair boxlist ; then
(grvecs
(list
-31 ; Edit for preferred color [negative = highlighted]
(car pair) (list (caar pair) (cadadr pair))
(car pair) (list (caadr pair) (cadar pair))
(cadr pair) (list (caar pair) (cadadr pair))
(cadr pair) (list (caadr pair) (cadar pair))
); list
); grvecs
); foreach
(prompt "\nMust use GetBoxes first."); else
); if
); defun

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

Post to forums  

Autodesk Design & Make Report

”Boost