Author Topic: Redraw entup wrong selected object.?.  (Read 3288 times)

0 Members and 1 Guest are viewing this topic.

MvdP

  • Guest
Redraw entup wrong selected object.?.
« on: May 05, 2008, 09:54:11 AM »
Here is small ( selection )part of my routine.
And this is working the way it should.

Code: [Select]
(defun sl (/ e e1 qqq f f1 ppp)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; error handling
(setq temperr *error*)
(setq *error* trap1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; error handling
(while
(progn
(setq e (car (entsel "\nSelect 1st line......:  ")))
(setq e1 (entget e))
(setq qqq (cdr (assoc 0 e1)))
(if (/= qqq "LINE")
(print "\Sorry NO LINE.!!")
)
)
)


(while
(progn
(setq f (car (entsel "\nSelect 2nd line......:  ")))
(setq f1 (entget f))
(setq ppp (cdr (assoc 0 f1)))
(cond
((/= ppp "LINE") (princ "\nSorry NO LINE.!!"))
((eq e f) (princ "\nSorry selected the same line.!!"))
)
)
)
(setq pt1 (cdr (assoc 10 (entget e))))
(setq pt2 (cdr (assoc 11 (entget e))))
(setq pt3 (cdr (assoc 10 (entget f))))
(setq pt4 (cdr (assoc 11 (entget f))))
)
But i want it to make more fancy.I want the objects that i select being highlighted.But when i selected the wrong object this stays highlighted until a regen.Is it possible to un-hightlight the wrong selected object without a regen.?

Code: [Select]
(defun sl (/ e e1 qqq f f1 ppp)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; error handling
(setq temperr *error*)
(setq *error* trap1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; error handling
(while
(progn (setq e (car (entsel "\nSelect 1st line......:  ")))
  (redraw e 3)
(setq e1 (entget e))
(setq qqq (cdr (assoc 0 e1)))
(if (/= qqq "LINE")
(print "\Sorry NO LINE.!!")
)
)
)


(while
(progn
(setq f (car (entsel "\nSelect 2nd line......:  ")))
  (redraw f 3)
(setq f1 (entget f))
(setq ppp (cdr (assoc 0 f1)))
(cond
((/= ppp "LINE") (princ "\nSorry NO LINE.!!"))
((eq e f) (princ "\nSorry selected the same line.!!"))
)
)
)
(redraw e 4)
(redraw f 4)
(entupd e)
(entupd f)
(setq pt1 (cdr (assoc 10 (entget e))))
(setq pt2 (cdr (assoc 11 (entget e))))
(setq pt3 (cdr (assoc 10 (entget f))))
(setq pt4 (cdr (assoc 11 (entget f))))
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Redraw entup wrong selected object.?.
« Reply #1 on: May 05, 2008, 10:30:12 AM »
I saw no need to highlight the second line picked as the routine moved on and it's would be too brief a time for the user to see it.
Try this version out.
Code: [Select]
(defun sl (/ ent1 ent2 GetEntity)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; error handling
          ;  (setq temperr *error*)
          ;  (setq *error* trap1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; error handling

  ;;  Return user selected object
  (defun GetEntity (typeAllowed PreEnt / ent elst)
    (while
      (cond
        ((setq ent (car (entsel (strcat "\nSelect a " (strcase typeAllowed t)"......:  "))))
         (setq elst (entget ent))
         (setq entType (cdr (assoc 0 elst)))
         (cond
           ((equal ent PreEnt)
            (princ "\nAlready selected that object, Try Again.")
           )
           ((/= entType typeAllowed)
            (princ (strcat "\nWrong Type! Need to pick a " typeAllowed))
           )
         )
        )
        ((Princ "\nNothing selected, Try Again."))
      )
    )
    ent
  )

  (setq ent1 (GetEntity "LINE" nil))
  (redraw ent1 3)
  (setq ent2 (GetEntity "LINE" ent1))
  (redraw ent1 4)

  ;;  return a list of end points of two lines
  (list
    (cdr (assoc 10 (entget ent1)))
    (cdr (assoc 11 (entget ent1)))
    (cdr (assoc 10 (entget ent2)))
    (cdr (assoc 11 (entget ent2)))
  )
)
Code: [Select]
(defun c:test ()
  (setq result (sl))
  ;;  indirect set variables to value
  (mapcar '(lambda (x y) (set (read x) y)) '("pt1" "pt2" "pt3" "pt4") result)
  (print)
  (mapcar 'print (list pt1 pt2 pt3 pt4))
  (princ)
)

<edit: code update>
« Last Edit: May 05, 2008, 01:32:39 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MvdP

  • Guest
Re: Redraw entup wrong selected object.?.
« Reply #2 on: May 05, 2008, 12:11:25 PM »
Thanks CAB

I don't have acces to AutoCAD right now.So i can't give it a go.

I will  do that first thing tomorrow but if i am not mistaken is that the user gets prompted two times .

Select 1st line......: 


Or am i seeing it  wrong.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Redraw entup wrong selected object.?.
« Reply #3 on: May 05, 2008, 12:35:22 PM »
Picky, Picky, Picky :-)

I changed it.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DEVITG

  • Bull Frog
  • Posts: 481
Re: Redraw entup wrong selected object.?.
« Reply #4 on: May 05, 2008, 01:10:36 PM »
Hi Cab , nice routine , today I learn how to assign values  to a lot of variable names.
I notice if user pick twice at the same line, despite it is highlighted,   it does not alert about it , and end the lisp giving the start and end point of the same entity

Select a line......:
Select a line......:

(70.8153 213.708 0.0)
(302.528 213.708 0.0)
(70.8153 213.708 0.0)
(302.528 213.708 0.0)



Location @ Córdoba Argentina Using ACAD 2019  at Window 10

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Redraw entup wrong selected object.?.
« Reply #5 on: May 05, 2008, 01:34:04 PM »
My mistake, try the code again.
It is Monday after all. :lol:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DEVITG

  • Bull Frog
  • Posts: 481
Re: Redraw entup wrong selected object.?.
« Reply #6 on: May 05, 2008, 02:15:38 PM »
Can you tell us, where was  error?
I can not get it.
« Last Edit: May 05, 2008, 02:24:25 PM by DEVITG »
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Redraw entup wrong selected object.?.
« Reply #7 on: May 05, 2008, 02:53:30 PM »
There error in this code is in red.
Code: [Select]
  (setq ent1 (GetEntity "LINE" nil))
  (redraw ent1 3)
  (setq ent2 (GetEntity "LINE" [color=red]nil[/color]))
  (redraw ent1 4)
I changed it to this:
Code: [Select]
  (setq ent1 (GetEntity "LINE" nil))
  (redraw ent1 3)
  (setq ent2 (GetEntity "LINE" [color=red]ent1[/color]))
  (redraw ent1 4)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DEVITG

  • Bull Frog
  • Posts: 481
Re: Redraw entup wrong selected object.?.
« Reply #8 on: May 05, 2008, 07:00:50 PM »


Other trick from the hat.

Thanks
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

MvdP

  • Guest
Re: Redraw entup wrong selected object.?.
« Reply #9 on: May 06, 2008, 02:45:44 AM »
Thanks CAB.

Working great.

MvdP

  • Guest
Re: Redraw entup wrong selected object.?.
« Reply #10 on: May 09, 2008, 04:47:40 AM »
Now i want to use this great code for selecting 3 lines.
But it aint working perfectly .
It prompts to select lines 3 times but when you select the 2nd entity as the 3nd entity it must say already selected. but it aint.
How can this solved.??


Code: [Select]
;;====================================================================================================
(defun 3sl (/ ent1 ent2 GetEntity GetEntity2 GetEntity3)
 ;;  Return user selected object
  (defun GetEntity (typeAllowed PreEnt / ent elst)
    (while
      (cond
        ((setq ent (car (entsel (strcat "\nSelect 1st " (strcase typeAllowed t)"......:  "))))
         (setq elst (entget ent))
         (setq entType (cdr (assoc 0 elst)))
         (cond
           ((/= entType typeAllowed)
            (princ (strcat "\nWrong Type! Need to pick a " typeAllowed))
           )
         )
        )
        ((Princ "\nNothing selected, Try Again."))
      )
    )
    ent
  )

  (defun GetEntity2 (typeAllowed PreEnt / ent elst)
    (while
      (cond
        ((setq ent (car (entsel (strcat "\nSelect 2nd " (strcase typeAllowed t)".......:  "))))
         (setq elst (entget ent))
         (setq entType (cdr (assoc 0 elst)))
         (cond
           ((equal ent PreEnt)
            (princ "\nAlready selected that object, Try Again.")
           )
           ((/= entType typeAllowed)
            (princ (strcat "\nWrong Type! Need to pick a " typeAllowed))
           )
         )
        )
        ((Princ "\nNothing selected, Try Again."))
      )
    )
    ent
  )

  (defun GetEntity3 (typeAllowed PreEnt / ent elst)
    (while
      (cond
        ((setq ent (car (entsel (strcat "\nSelect  3th " (strcase typeAllowed t)".......:  "))))
         (setq elst (entget ent))
         (setq entType (cdr (assoc 0 elst)))
         (cond
           ((equal ent PreEnt )
            (princ "\nAlready selected that object, Try Again.")
           )
           ((/= entType typeAllowed)
            (princ (strcat "\nWrong Type! Need to pick a " typeAllowed))
           )
         )
        )
        ((Princ "\nNothing selected, Try Again."))
      )
    )
    ent
  )


  (setq ent1 (GetEntity "LINE" nil))
  (redraw ent1 3)
  (setq ent2 (GetEntity2 "LINE" ent1))
  (redraw ent2 3)
  (setq ent3 (GetEntity3 "LINE" ent1))
  (redraw ent3 3)
  (redraw ent1 4)
  (redraw ent2 4)
  (setq pt1 (cdr (assoc 10 (entget ent1))))
  (setq pt2 (cdr (assoc 11 (entget ent2))))
  (setq pt3 (cdr (assoc 10 (entget ent3))))
  (setq pt4 (cdr (assoc 11 (entget ent3))))
)
;;====================================================================================================

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Redraw entup wrong selected object.?.
« Reply #11 on: May 09, 2008, 10:04:55 AM »
You need to think more about creating reusable subroutines.
In this example I do not like the way vars pt1 through pt6 are returned.

Code: [Select]
(defun 3sl (/ ent1 ent2 ent3 GetEntity )
  (defun dxf (code ent)
    (cdr (assoc code (entget ent)))
  )
 ;;  Return user selected object
  (defun GetEntity (typeAllowed PreEnt prmp / ent elst)
    (while
      (cond
        ((setq ent (car (entsel (strcat prmp (strcase typeAllowed t)"......:  "))))
         (setq elst (entget ent))
         (setq entType (cdr (assoc 0 elst)))
         (cond
           ((member ent PreEnt)
            (princ "\nAlready selected that object, Try Again.")
           )
            ((/= entType typeAllowed)
            (princ (strcat "\nWrong Type! Need to pick a " typeAllowed))
           )
         )
        )
        ((Princ "\nNothing selected, Try Again."))
      )
    )
    ent
  )

  (setq ent1 (GetEntity "LINE" nil "\nSelect 1st "))
  (redraw ent1 3)
  (setq ent2 (GetEntity "LINE" (list ent1) "\nSelect 2nd "))
  (redraw ent2 3)
  (setq ent3 (GetEntity "LINE" (list ent1 ent2) "\nSelect  3th "))
  (redraw ent1 4)
  (redraw ent2 4)
  (setq pt1 (dxf 10 ent1))
  (setq pt2 (dxf 11 ent1))
  (setq pt3 (dxf 10 ent2))
  (setq pt4 (dxf 11 ent2))
  (setq pt5 (dxf 10 ent3))
  (setq pt6 (dxf 11 ent3))
)
This should be your return code:
Code: [Select]
  (list (dxf 10 ent1)(dxf 11 ent1)(dxf 10 ent2)(dxf 11 ent2)(dxf 10 ent3)(dxf 11 ent3))And you should use this to set the vars.
Code: [Select]
(defun c:test ()
  (setq result (sl))
  ;;  indirect set variables to value
  (mapcar '(lambda (x y) (set (read x) y)) '("pt1" "pt2" "pt3" "pt4" "pt5" "pt64")  result)
  (print)
  (mapcar 'print (list pt1 pt2 pt3 pt4 pt5 pt6))
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MvdP

  • Guest
Re: Redraw entup wrong selected object.?.
« Reply #12 on: May 13, 2008, 02:28:01 AM »
Thanx CAB.
Working great.
But i have a question.

Code: [Select]
(redraw ent1 4)
(redraw ent2 4)

This is a part of my error handling ,if one line is selected and i press the cancel buton the previous selected line is redrawn, but it gives an error becasue ent 2 does not exist for now.
If two lines are selcted and press the cancel button the two selected are redrawn without an error.
Is it possible to do the error handling without any errors when only one line seclected.?


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Redraw entup wrong selected object.?.
« Reply #13 on: May 13, 2008, 08:31:07 AM »
Change the error handler to this:
Code: [Select]
(and ent1 (redraw ent1 4))
(and ent2 (redraw ent2 4))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MvdP

  • Guest
Re: Redraw entup wrong selected object.?.
« Reply #14 on: May 13, 2008, 08:40:54 AM »
Thanks again.CAB