Error control for selecting viewports

Error control for selecting viewports

Anonymous
Not applicable
467 Views
10 Replies
Message 1 of 11

Error control for selecting viewports

Anonymous
Not applicable
I'm using this code to select a viewport
(setq ENT (entget (car (entsel "\nSelect viewport: "))))
If the user selects anything else I get this error: "error: bad argument
type: lentityp"
How do I provide error checking so that the user can only select a viewport.

--

Mark A. Carter
CAD Administrator
NJRA Architects
www.njraarchitects.com
0 Likes
468 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
Try this outline ...

(defun c:test ( / ent dat)
(if (setq ent (entsel "\nSelect viewport: "))
(cond
( (eq "VIEWPORT" (cdr (assoc 0 (setq dat (entget (car ent))))))
(princ "\nEntity selected WAS a viewport.")
;
; other code
;
)
( t
(princ "\nEntity selected was not a viewport.")
;
; other code
;
)
)
(princ "\nNo entity selected.")
)
(princ)
)

________________________________

puckettm@bantrel.com
> Not < an AutoDESK classroom monitor
Imagination makes all things possible
________________________________

Mark Carter wrote in message <8b8pu5$6s321@adesknews2.autodesk.com>...
I'm using this code to select a viewport
(setq ENT (entget (car (entsel "\nSelect viewport: "))))
If the user selects anything else I get this error: "error: bad argument
type: lentityp"
How do I provide error checking so that the user can only select a viewport.

--

Mark A. Carter
CAD Administrator
NJRA Architects
www.njraarchitects.com
0 Likes
Message 3 of 11

Anonymous
Not applicable
I think you have to break your code into 2 steps to avoid an
error caused by no entity (lentityp) being selected.

(setq ENT (car (entsel)))
(if ENT
(setq ENTEAL (entget ENT))
(cond
((= (cdr (assoc 0 ENTEAL) "VIEWPORT"))
... do something entertaining & worthwhile
)
(T
(princ "\nEntity selected not a VIEWPORT")
)
)
)

Something like that would work.

"Mark Carter" wrote in message
news:8b8pu5$6s321@adesknews2.autodesk.com...
> I'm using this code to select a viewport
> (setq ENT (entget (car (entsel "\nSelect viewport: "))))
> If the user selects anything else I get this error: "error: bad argument
> type: lentityp"
> How do I provide error checking so that the user can only select a
viewport.
>
> --
>
> Mark A. Carter
> CAD Administrator
> NJRA Architects
> www.njraarchitects.com
>
>
>
0 Likes
Message 4 of 11

Anonymous
Not applicable
Try this. it allows you to specify what type of entity you will accept from
ENTSEL. (SelectEntity "viewport") for example. I'm sure there's a tighter
way to do this so I sure would appreciate any constructive criticism anyone
has to offer.

(defun SelectEntity (enttype / ent catch retval)
(while (not ent)
(setq
catch (vl-catch-all-apply
'entsel
(list (strcat "\nSelect a " (strcase enttype T) ": "))
)
)
(if (not (vl-catch-all-error-p catch))
(if (setq ent (car catch))
(if (= (cdr (assoc 0 (entget ent))) enttype)
ent
(progn
(princ
(strcat "\nThat entity is not a " (strcase enttype T))
)
(setq ent nil)
)
)
(princ "\nNothing selected. Try again.")
)
(progn
(setq ent T)
retval
)
)
)
)

--
Get free software and more at http://www2.stonemedia.com/franko

"Mark Carter" wrote in message
news:8b8pu5$6s321@adesknews2.autodesk.com...
> I'm using this code to select a viewport
> (setq ENT (entget (car (entsel "\nSelect viewport: "))))
> If the user selects anything else I get this error: "error: bad argument
> type: lentityp"
> How do I provide error checking so that the user can only select a
viewport.
>
> --
>
> Mark A. Carter
> CAD Administrator
> NJRA Architects
> www.njraarchitects.com
>
>
>
0 Likes
Message 5 of 11

Anonymous
Not applicable
That will still cause the error when someone picks
empty space (because you are attempting to (car nil). Do this:

 

(while (null (setq ENT (entsel
"\nSelect viewport: "))))

> (if ENT

color=#ff0000>     (setq ENTEAL (entget (car
ENT)))
>    
(cond
>         ((= (cdr (assoc 0
ENTEAL)
"VIEWPORT"))
>            
... do something entertaining &
worthwhile
>        
)
>        
(T
>           
(princ "\nEntity selected not a
VIEWPORT")
>        
)
>     )
> )


--
R. Robert Bell, MCSE
Network
Administrator (or, Modern-day Wizard)

 

 


face=Arial size=2>>     I think you have to break your code
into 2 steps to avoid an
> error caused by no entity (lentityp) being
selected.
>
> (setq ENT (car (entsel)))
> (if ENT
>
    (setq ENTEAL (entget ENT))
>    
(cond
>         ((= (cdr (assoc 0
ENTEAL) "VIEWPORT"))
>
            ... do
something entertaining & worthwhile
>
        )
>
        (T
>
           (princ "\nEntity
selected not a VIEWPORT")
>        
)
>     )
> )
>
>    
Something like that would work.
>
> "Mark Carter" <
href="mailto:marcar@njraarchitects.com">marcar@njraarchitects.com
> wrote
in message
>
href="news:8b8pu5$6s321@adesknews2.autodesk.com">news:8b8pu5$6s321@adesknews2.autodesk.com
...
>
> I'm using this code to select a viewport
> >   
(setq ENT (entget (car (entsel "\nSelect viewport: "))))
> > If the
user selects anything else I get this error: "error: bad argument
> >
type: lentityp"
> > How do I provide error checking so that the user
can only select a
> viewport.
> >
> > --
>
>
> > Mark A. Carter
> > CAD Administrator
> >
NJRA Architects
> >
href="http://www.njraarchitects.com">www.njraarchitects.com

>
>
> >
> >
>
>
0 Likes
Message 6 of 11

Anonymous
Not applicable
That's ok - I didn't see you either 🙂

________________________________

puckettm@bantrel.com
> Not < an AutoDESK classroom monitor
Imagination makes all things possible
________________________________

Joe Funk wrote in message <8b8seh$6s120@adesknews2.autodesk.com>...

(Sorry, Michael, I didn't see you.)

0 Likes
Message 7 of 11

Anonymous
Not applicable
(Sorry, Michael, I didn't see you.)

>(eq "VIEWPORT" (cdr (assoc 0 (setq dat (entget (car ent))))))

I've been using "=" in these situations forever. I take it the
"=" works because it's comparing the numerical values of the
2 strings?
At any rate, it's "eq" for me henceforth.

"Michael Puckett" wrote in message
news:8b8rcf$6td31@adesknews2.autodesk.com...
> Try this outline ...
>
> (defun c:test ( / ent dat)
> (if (setq ent (entsel "\nSelect viewport: "))
> (cond
> ( (eq "VIEWPORT" (cdr (assoc 0 (setq dat (entget (car ent))))))
> (princ "\nEntity selected WAS a viewport.")
> ;
> ; other code
> ;
> )
> ( t
> (princ "\nEntity selected was not a viewport.")
> ;
> ; other code
> ;
> )
> )
> (princ "\nNo entity selected.")
> )
> (princ)
> )
>
> ________________________________
>
> puckettm@bantrel.com
> > Not < an AutoDESK classroom monitor
> Imagination makes all things possible
> ________________________________
>
> Mark Carter wrote in message <8b8pu5$6s321@adesknews2.autodesk.com>...
> I'm using this code to select a viewport
> (setq ENT (entget (car (entsel "\nSelect viewport: "))))
> If the user selects anything else I get this error: "error: bad argument
> type: lentityp"
> How do I provide error checking so that the user can only select a
viewport.
>
> --
>
> Mark A. Carter
> CAD Administrator
> NJRA Architects
> www.njraarchitects.com
>
>
>
>
>
0 Likes
Message 8 of 11

Anonymous
Not applicable
Thanks, to both of you. That did the trick.
I had my (cond) in the wrong place.

--

Mark A. Carter
CAD Administrator
NJRA Architects
www.njraarchitects.com
0 Likes
Message 9 of 11

Anonymous
Not applicable
Be careful, there are laws against that in many states.

________________________________

puckettm@bantrel.com
> Not < an AutoDESK classroom monitor
Imagination makes all things possible
________________________________

Mark Carter wrote in message <8b8spq$6rk25@adesknews2.autodesk.com>...

> I had my (cond) in the wrong place <
0 Likes
Message 10 of 11

Anonymous
Not applicable
    Of course. You're right .


style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">

That will still cause the error when someone
picks empty space (because you are attempting to (car nil). Do
this:

 

(while (null (setq ENT (entsel
"\nSelect viewport: "))))

> (if ENT

color=#ff0000>     (setq ENTEAL (entget (car
ENT)))
>    
(cond
>         ((= (cdr (assoc
0 ENTEAL)
"VIEWPORT"))
>            
... do something entertaining &
worthwhile
>        
)
>        
(T
>           
(princ "\nEntity selected not a
VIEWPORT")
>        
)
>     )
> )


--
R. Robert Bell, MCSE
Network
Administrator (or, Modern-day Wizard)

 

 


face=Arial size=2>>     I think you have to break your code
into 2 steps to avoid an
> error caused by no entity (lentityp) being
selected.
>
> (setq ENT (car (entsel)))
> (if ENT
>
    (setq ENTEAL (entget ENT))
>    
(cond
>         ((= (cdr (assoc 0
ENTEAL) "VIEWPORT"))
>
            ... do
something entertaining & worthwhile
>
        )
>
        (T
>
           (princ "\nEntity
selected not a VIEWPORT")
>        
)
>     )
> )
>
>    
Something like that would work.
>
> "Mark Carter" <
href="mailto:marcar@njraarchitects.com">marcar@njraarchitects.com
>
wrote in message
>
href="news:8b8pu5$6s321@adesknews2.autodesk.com">news:8b8pu5$6s321@adesknews2.autodesk.com
...
>
> I'm using this code to select a viewport
> >   
(setq ENT (entget (car (entsel "\nSelect viewport: "))))
> > If the
user selects anything else I get this error: "error: bad argument
> >
type: lentityp"
> > How do I provide error checking so that the user
can only select a
> viewport.
> >
> > --
>
>
> > Mark A. Carter
> > CAD Administrator
> >
NJRA Architects
> >
href="http://www.njraarchitects.com">www.njraarchitects.com

>
>
> >
> >
>
>
0 Likes
Message 11 of 11

Anonymous
Not applicable
Let me rephrase, thanks to all who contributed.
P.S. Frank, I'm going to try your solution as well.

--

Mark A. Carter
CAD Administrator
NJRA Architects
www.njraarchitects.com
0 Likes