Jump to content

Recommended Posts

Posted

Hi All,

 

I wrote:

 

(setq entitylist (entget (car (entsel))))

 

in the middle of my code and when I click on the screen by mistake instead of an object, I receive this error:

"Select object: ; error: bad argument type: lentityp nil" and it jumps out of program!

how can I keep the user in that step till the user select an object?

 

Cheers

 

Ali

  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    8

  • Se7en

    5

  • BlackBox

    5

  • alijahed

    4

Posted

Look at the 'INITGET' function...

Posted

Perhaps something like :

 

 (setq pickedEnt nil)
 (while (not pickedEnt)
   (setvar "ERRNO" 0)
   (if (setq returnvalue (entsel "\nPick a thingy."))
     (setq pickedEnt  (car returnvalue)
           entitylist (entget pickedEnt)
     )
   )
 )

Posted

The error occurs because

 

(entget nil)

 

Will throw an error. You will need to test the return of (entsel) or even (car (entsel)) for a non-nil value before calling entget. Take a look at Kerry's example.

Posted

Unfortunately, I didn't understand the kerry's example I think it is a little bit higher than my level of understanding. I would appreciate it if somebody explain it to me line by line.

 

But according to the situation I wrote:

(setq a "w")

(while a

(setq object (car (entsel)))

(if (/= object nil) (setq a nil))

(setq entitylist (entget object))

)

 

and for some reasons it comes up with a same error.

 

Thanks in advance for helping me

 

Cheers

 

Ali

Posted
Perhaps something like :

 

 (setq pickedEnt nil)
 (while (not pickedEnt)
   (setvar "ERRNO" 0)
   (if (setq returnvalue (entsel "\nPick a thingy."))
     (setq pickedEnt  (car returnvalue)
           entitylist (entget pickedEnt)
     )
   )
 )

 

Missed a spot. :wink:

 

(setq pickedEnt nil)
(setvar "ERRNO" 0)
(while (and (not pickedEnt) (/= 52 (getvar "ERRNO")))
 (if (setq returnvalue (entsel "\nPick a thingy."))
   (setq pickedEnt  (car returnvalue)
         entitylist (entget pickedEnt)
   )
 )
)

Posted
Missed a spot. :wink:

 

(setq pickedEnt nil)
(setvar "ERRNO" 0)
(while (and (not pickedEnt) (/= 52 (getvar "ERRNO")))
 (if (setq returnvalue (entsel "\nPick a thingy."))
   (setq pickedEnt  (car returnvalue)
         entitylist (entget pickedEnt)
   )
 )
)

 

well! more complicated! Can you please explain what is happening line by line for dummies like me? ;)

Posted
Missed a spot. :wink:

 

 

No I didn't ..:P

 

alijahed only wanted to identify missed picks, not the user pressing ENTER.

Posted

See if this helps ...

 

(setq pickedent nil)
(while (not pickedent)                  ; while the pickedEnt variable is not set           
                                           
 (if                                        ; conditional
   (setq returnvalue (entsel "\nPick a thingy."))
                                            ; select an entity, set result to variable returnvalue
                                            ; if something is selected 
    (setq pickedent  (car returnvalue)      ; set the entity name to variable pickedEnt
          entitylist (entget pickedent)     ; extract the entity data to variable entitylist
    )
 )
)                                            ; loop back to the top untill something is selected or untill ENTER is pressed
(if (not pickedent)
 (exit)
)                                            ; quit if nothing was selected
                                            ; .... or decide what else to do ?? 

Posted

alijahed, you could always play with something like this ...

 

;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;; (KDUB:OBJSEL <Promptmsg> <typelist > <nentselflag > )
;; (KDUB:objsel "Select Arc Object" (list "ARC" "CIRCLE") T)
(defun kdub:objsel (promptmsg                ;
                   typelist                 ; List of entity types allowed to be selected
                   nentselflag              ; If true nentsel permitted , otherwise use entsel.
                   /           pickok      returnvalue tmp
                   etype
                  )
 (setq promptmsg (strcat "\n"
                         (cond (promptmsg)
                               ("Select object")
                         )
                         " : "
                 )
 )
 (while (not pickok)
   (setvar "ERRNO" 0)
   (setq returnvalue (if nentselflag
                       (nentsel promptmsg)
                       (entsel promptmsg)
                     )
   )
   (cond
     ((= (getvar "ERRNO") 52)               ; enter
      ;; skip out
      (setq pickok t)
     )
     ((= (getvar "ERRNO") 7)
      (princ "Nothing found at selectedpoint. ")
     )
     ((and
        (setq tmp (entget (car returnvalue))) ; object type
        ;; If selection is for Nested Entity, 
        ;; If the entity type is a VERTEX 
        ;; Return the Parent 2dPOLYLINE
        ;;
        typelist
        (if (and nentselflag (= (cdr (assoc 0 tmp)) "VERTEX"))
          (setq returnvalue (list (cdar (entget (cdr (assoc 330 tmp))))
                                  (cadr returnvalue)
                            )
                tmp         (entget (car returnvalue))
          )
          ;; else
          t
        )
        (setq etype (cdr (assoc 0 tmp)))
        (not (member (cdr (assoc 0 tmp)) (mapcar 'strcase typelist)))
      )                                     ; wrong type
      (alert
        (strcat "Selected object is not"
                "\na "
                (apply 'strcat
                       (cons (car typelist)
                             (mapcar '(lambda (x) (strcat "\nor " x))
                                     (cdr typelist)
                             )
                       )
                )
                ". "
        )
      )
     )
     ;; skip out
     ((setq pickok t))
   )
 )
 returnvalue
)

Posted

Thank you very much for your helping.

 

much appreciate it

  • 3 months later...
Posted
Missed a spot. :wink:

 

(setq pickedEnt nil)
(setvar "ERRNO" 0)
(while (and (not pickedEnt) (/= 52 (getvar "ERRNO")))
(if (setq returnvalue (entsel "\nPick a thingy."))
(setq pickedEnt (car returnvalue)
entitylist (entget pickedEnt)
)
)
)

 

Hi guys, Ive been playing around with error trapping on my 1st LSP routine and found the above very helpful. I think i understand what its doing and I've dropped this in. It traps if the user selects nothing and if the user selects anything other than a line, but it still errors and quits the function if the user hits enter (or any text on the command line) or right clicks the mouse. From what Alanjt says above shouldn't (/=52(getvar "ERRNO"")) fix at least the enter part?..or am i doing something wrong? My code is below. Thanks in advance.

 

PS I'm thinking the two different error traps here can probably be combined together but I can experiment with that once I have it fully working (hopefully) :)

 

 
(setq oldCmdecho (getvar "cmdecho"))  
(setq oldLayer  (getvar "clayer"))


(defun c:Edge()
(setvar "cmdecho" 0)

(command "_.layer" "_new" "TEST" "c" "4" "TEST" "_set" "TEST" "")
(Crt)
)

(defun Crt (/ aks pp aks_hand acd_en)
 (setq pickedEnt nil)
(setvar "ERRNO" 0)
(while (and (not pickedEnt) (/= 52 (getvar "ERRNO")))
 (if (setq aks (entsel "\nPick an Edge."))
   (setq pickedEnt  (car aks)
         entitylist (entget pickedEnt)
   )
 )
)

(Setq pp (cadr aks)    ; Selection point (PICKPOINT)
aks_hand (entget (car aks))  ; List of axis member
acd_en (cdr (assoc 0 aks_hand)) ; Name of the selected entity      
)
;If the selected entity is not LINE, then restart the program
(if (/= acd_en "LINE")
(progn
(princ "\nSelected entity is not LINE!")
(crt)
)
(princ)
)
 )

Posted

I've always preferred (ssget) calls:

 

 [b][color=BLACK]([/color][/b]while [b][color=FUCHSIA]([/color][/b]or [b][color=NAVY]([/color][/b]not ss[b][color=NAVY])[/color][/b]
            [b][color=NAVY]([/color][/b]/= [b][color=MAROON]([/color][/b]sslength ss[b][color=MAROON])[/color][/b] 1[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
        [b][color=FUCHSIA]([/color][/b]princ [color=#2f4f4f]"\nSelect 1 LINE"[/color][b][color=FUCHSIA])[/color][/b]
        [b][color=FUCHSIA]([/color][/b]setq ss [b][color=NAVY]([/color][/b]ssget '[b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]0 . [color=#2f4f4f]"LINE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 [b][color=BLACK]([/color][/b]setq en [b][color=FUCHSIA]([/color][/b]sname ss 0[b][color=FUCHSIA])[/color][/b]    [color=#8b4513];;;Selction's ename[/color]
       ed [b][color=FUCHSIA]([/color][/b]entget en[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]    [color=#8b4513];;;Selection's entity definition[/color]

 

 

It allows for filtering as well as Last/Prev/Window/Crossing etc selections

 

Points on most entities can be extracted from the definition.

 

 

Also errno hasn't been the most reliable feature over the years. My $0.02 -David

 

PS Just remember to declare ss as local or force it to nil (setq ss nil) prior to calling

Posted (edited)

method by Lee Mac

(while
 (not
   (and 
     (setq ent (car (entsel "\nSelect Text: ")))
     (eq "TEXT" (cdr (assoc 0 (setq ent (entget ent)))))
   )
 )
 (prompt "Please Select a Single Line Text!")
)

Edited by Lt Dan's legs
Posted
(defun foo (/ e g)
 (setvar 'errno 0)
 (while (not g)
   (if (setq e (car (entsel "\nSelect line: ")))
     (cond ((eq "LINE" (cdr (assoc 0 (entget e)))) (setq g e))
           ((setq g (prompt "\nInvalid object!")))
     )
     (cond ((setq g (eq 52 (getvar 'errno))) nil)
           ((eq 7 (getvar 'errno)) (setq g (prompt "\nMissed, try again.")))
     )
   )
 )
)

Posted
I've always preferred (ssget) calls:

 

[b][color=black]([/color][/b]while [b][color=fuchsia]([/color][/b]or [b][color=navy]([/color][/b]not ss[b][color=navy])[/color][/b]
[b][color=navy]([/color][/b]/= [b][color=maroon]([/color][/b]sslength ss[b][color=maroon])[/color][/b] 1[b][color=navy])[/color][/b][b][color=fuchsia])[/color][/b]
[b][color=fuchsia]([/color][/b]princ [color=#2f4f4f]"\nSelect 1 LINE"[/color][b][color=fuchsia])[/color][/b]
[b][color=fuchsia]([/color][/b]setq ss [b][color=navy]([/color][/b]ssget '[b][color=maroon]([/color][/b][b][color=green]([/color][/b]0 . [color=#2f4f4f]"LINE"[/color][b][color=green])[/color][/b][b][color=maroon])[/color][/b][b][color=navy])[/color][/b][b][color=fuchsia])[/color][/b][b][color=black])[/color][/b]

[b][color=black]([/color][/b]setq en [b][color=fuchsia]([/color][/b]sname ss 0[b][color=fuchsia])[/color][/b] [color=#8b4513];;;Selction's ename[/color]
ed [b][color=fuchsia]([/color][/b]entget en[b][color=fuchsia])[/color][/b][b][color=black])[/color][/b] [color=#8b4513];;;Selection's entity definition[/color]

 

 

It allows for filtering as well as Last/Prev/Window/Crossing etc selections

 

Points on most entities can be extracted from the definition.

 

 

Also errno hasn't been the most reliable feature over the years. My $0.02 -David

 

PS Just remember to declare ss as local or force it to nil (setq ss nil) prior to calling

 

Thanks David, I tried it out but I came across two problems I couldnt resolve, 1 was I need the coordinates of the selection point later on, which I couldnt get back from using ssget (a bit above my head at the moment) and 2 I only want to select a point not allow them to fence etc for the above reason. But ssget is definately something I want to look into, maybe on my next try at lisp.

 

method by Lee Mac

(while
(not
(and 
(setq ent (car (entsel "\nSelect Text: ")))
(eq "TEXT" (cdr (assoc 0 (setq ent (entget ent)))))
)
)
(prompt "Please Select a Single Line Text!")
)

 

Dan (and Lee Mac!) Thanks! I amended this to suit my code and it works perfectly here it is below:-

 

(while
 (not
   (and 
     (setq ent1 (entsel "\nSelect Line: "))
     (setq ent (car ent1))
     (eq "LINE" (cdr (assoc 0 (setq ent (entget ent)))))
   )
 )
 (prompt "Please Select a Single Line!")
)

 

I needed the user to select a line not text but I worked that one out quite easily, what stumped me was the selection point mentioned above, so I seperated ent and ent1 to keep both variables. It works but is this the right way to do it?

 

Thanks again that completes my 1st fully working lisp routine! :D

Posted
(defun foo (/ e g)
 (setvar 'errno 0)
 (while (not g)
   (if (setq e (entsel "\nSelect line: "))
     (cond ((eq "LINE" (cdr (assoc 0 (entget (car e))))) (setq g e))
           ((setq g (prompt "\nInvalid object!")))
     )
     (cond ((setq g (eq 52 (getvar 'errno))) nil)
           ((eq 7 (getvar 'errno)) (setq g (prompt "\nMissed, try again.")))
     )
   )
 )
)

Posted

Just out of curiosity, what do you need the point value for? How are you going to use it?

Posted

Don't mind me, just playing around (because i can).

 

Sans Variable:

(
(lambda ( / )
  (while
    (not
      (eq "LINE"
          (cdr
            (assoc 0
                   (entget
                     (car (entsel "\nSelect Line: "))))))))
  (entget (entlast))
  )
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...