Author Topic: Problem with redraw in lisp  (Read 1939 times)

0 Members and 1 Guest are viewing this topic.

wkplan

  • Mosquito
  • Posts: 9
Problem with redraw in lisp
« on: June 02, 2009, 04:38:22 AM »
Hello all,

I found this lisp-routine here:
http://www.theswamp.org/index.php?topic=10248.15

Here is a piece of code from it, just to show were my problem starts:

(defun c:AreaReact (/ Sel EntData PolyObj TextObj ReactList Pos TextSel)

;|  Adds a presistant reactor to a polyline object that
    updates a selected text object to the polylines area
    in square feet.  You will have to have the subs loaded
    in everydrawing for it to work, so that it know what
    to do with the reactor, because it is saved with the
    drawing.  Saves the association between the text
    and the polyline in the extension dictionary of the
    polyline.  If the text object is deleted, then the
    program will remove the reactor related to the polyline.
    Thanks to Luis Esquivel for his help and guidance.
    v1.0 2/2006 Tim Willey
    v1.1 5/2006 Added the ability to select an attribute.
|;

(if
 (and
  (setq Sel (entsel "\n Select polyline to get area of: "))
  (setq EntData (entget (car Sel)))
  (= (cdr (assoc 0 EntData)) "LWPOLYLINE")
  (setq PolyObj (vlax-ename->vla-object (car Sel)))
  (setq Sel (nentsel "\n Select text of hold area value: "))

  (setq EntData (entget (car Sel)))
  (or
   (if (vl-position (cdr (assoc 0 EntData)) '("TEXT" "MTEXT"))
    (setq TextSel T)
   )
   (= (cdr (assoc 0 EntData))  "ATTRIB")
  )
  (if TextSel
   (if (equal (length Sel) 2)
    T
    (prompt "\n Cannot select nested text.")

Well its working fine, but I thought it might be better, to show the user which polyline ist selected.
I tried to insert
(redraw Sel 3)
after the selction statement, but if iI'm trying to run the programm, I only receive an error-message, "bad argumenttyp: lentityp "

The code looks like this:

(if
 (and
  (setq Sel (entsel "\n Select polyline to get area of: "))
(redraw Sel 3)
  (setq EntData (entget (car Sel)))
  (= (cdr (assoc 0 EntData)) "LWPOLYLINE")
  (setq PolyObj (vlax-ename->vla-object (car Sel)))


Has anyone an idea, how to change the code in a way, the selected polyline is highlighted?

Best regards
Wolfgang

Lee Mac

  • Seagull
  • Posts: 12292
  • London, England
Re: Problem with redraw in lisp
« Reply #1 on: June 02, 2009, 05:24:17 AM »
Try

Code: [Select]
(redraw (car Sel) 3)

wkplan

  • Mosquito
  • Posts: 9
Re: Problem with redraw in lisp
« Reply #2 on: June 02, 2009, 07:23:31 AM »
Hello Lee,

(redraw (car Sel) 3)

This will highlight the selected polyline, but after this the lisp-function stops.
Rest of programm isn't continued.

I don't know how to fix this, any idea?

Regards
Wolfgang

Joe Burke

  • Guest
Re: Problem with redraw in lisp
« Reply #3 on: June 02, 2009, 08:12:02 AM »
Wolfgang,

Redraw returns nil so the AND function stops there.

You could do this: (not (redraw (car Sel) 3)) or move the redraw call out of the AND function. The latter makes more sense IMO.

wkplan

  • Mosquito
  • Posts: 9
Re: Problem with redraw in lisp
« Reply #4 on: June 02, 2009, 08:36:30 AM »
Thank you Joe!

I put the redraw-setting like this:

(if
 (and
  (setq Sel (entsel "\n Select polyline to get area of: "))
(not (redraw (car Sel) 3))

And the function works know exactly the way I wish.

Kind regards
Wolfgang


Joe Burke

  • Guest
Re: Problem with redraw in lisp
« Reply #5 on: June 02, 2009, 11:35:10 AM »
You're welcome.

Just keep in mind, including a redraw call within an AND test is pointless because it always returns nil.

Lee Mac

  • Seagull
  • Posts: 12292
  • London, England
Re: Problem with redraw in lisp
« Reply #6 on: June 02, 2009, 12:03:31 PM »
Cheers Joe, forgot about the inclusion in the AND...  :angel: