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

If statement?

51 REPLIES 51
Reply
Message 1 of 52
Anonymous
578 Views, 51 Replies

If statement?

I have written the following lisp, but am unsure how to go about adding a
section to it. If no object is selected show "\nNo entities selected" on
the command line and then repeat the entsel process. I think I should be
using an if statement. Any hints are appreciated
;one click break
(defun c:bb ()
(command ".break" (ENTSEL "\nSelect object to break") "F" (GETPOINT
"\nSelect point to break at" "@"))
(princ)
)

Thank you,
Beau Turner
51 REPLIES 51
Message 41 of 52
Anonymous
in reply to: Anonymous

Actually, I've used that very same idea in some of my code too. Just seems
like a natural test, if you know about the function.

--
R. Robert Bell, MCSE
http://www.acadx.com


"Doug Broad" wrote in message
news:3F7656F6A04049BAA0627564EACA2E2D@in.WebX.maYIadrTaRb...
| Yes that seems like it would work well. I also really liked the way John
| used the vlax-method-applicable-p function in his object_ok function
| to eliminate all sorts of object types that couldn't be broken. I wonder
| what inspired him to use that test?
|
Message 42 of 52
Anonymous
in reply to: Anonymous

Inspiration?? Heck, we just snag any tool we think might work! Remember
that I work almost exclusively with LDD which has all kinds of custom
objects today and probably many more as evolution progresses. Now if
ActiveX had included a "Break" method, then this thread wouldn't have been
long enough to wrap around my pinky.

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juhden@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332


"Doug Broad" wrote in message
news:3F7656F6A04049BAA0627564EACA2E2D@in.WebX.maYIadrTaRb...
> Yes that seems like it would work well. I also really liked the way John
> used the vlax-method-applicable-p function in his object_ok function
> to eliminate all sorts of object types that couldn't be broken. I wonder
> what inspired him to use that test?
Message 43 of 52
Anonymous
in reply to: Anonymous

OK, let's beat this horse one last time. This one identifies entities that
can be offset, but can't be broken at a single point and filters them out.
It also checks for entities that can't be offset, but can be broken. If it
passes all that, and it's not on a locked layer, then it's tested for an
offset method. If it passes all those tests, we ask for a break point and
pass it to the break command. Now who's going to do the research to
determine if we caught all the entities to test for 🙂

Let's all be sure to thank, or is that blame 🙂 , John Uhden for pointing
out the need to check for objects on locked layers and for the offset method
test. I've stolen his ideas and put them into this code.

Now I just want to see a show of hands for those that are still going to
use:
(defun c:bb () (command "break" pause "f" pause "@")(princ))
instead of this wonderfull little command that we've cooked up.
--
Bobby C. Jones
http://www.acadx.com
Message 44 of 52
Anonymous
in reply to: Anonymous

Great example. One question though, how/where would redraw be used to
highlight the object selected to break?

-Beau

Bobby C. Jones wrote in message
news:B31096499A0274B46D76D81C2E305A72@in.WebX.maYIadrTaRb...
> OK, let's beat this horse one last time. This one identifies entities
that
> can be offset, but can't be broken at a single point and filters them out.
> It also checks for entities that can't be offset, but can be broken. If
it
> passes all that, and it's not on a locked layer, then it's tested for an
> offset method. If it passes all those tests, we ask for a break point and
> pass it to the break command. Now who's going to do the research to
> determine if we caught all the entities to test for 🙂
>
> Let's all be sure to thank, or is that blame 🙂 , John Uhden for pointing
> out the need to check for objects on locked layers and for the offset
method
> test. I've stolen his ideas and put them into this code.
>
> Now I just want to see a show of hands for those that are still going to
> use:
> (defun c:bb () (command "break" pause "f" pause "@")(princ))
> instead of this wonderfull little command that we've cooked up.
> --
> Bobby C. Jones
> http://www.acadx.com
>
>


----------------------------------------------------------------------------
----


(defun c:bb (/ ent pnt cmd elist *error*)

(defun *error* (msg)
(if (not (member Msg '(nil "console break" "Function cancelled" "quit /
exit abort")))
(princ (strcat "\nError: # " (itoa (getvar "errno")) Msg))
)
(setvar "errno" 0)
(setvar "cmdecho" cmd)
(princ)
)

(setq cmd (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setvar "errno" 7)
(while (= (getvar "errno") 7)
(setvar "errno" 0)
(setq ent (entsel "\nSelect object to break: "))
(cond
;;;-------------------------------------
;;;Stop testing on mispick or enter key
;;;-------------------------------------
((= (getvar "errno") 7))
((= (getvar "errno") 52))
;;;-------------------------------------
;;;Stop testing & reset loop on locked layer
;;;-------------------------------------
((= (logand (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 (setq
elist (entget (car ent)))))))) 4) 4)
(prompt "The object is on a locked layer.")
(setvar "errno" 7)
)
;;;-------------------------------------
;;;Stop testing & reset loop on entities
;;;that can be offset, but cannot be broken
;;;at one point
;;;-------------------------------------
((equal (cdr (assoc 0 elist)) "CIRCLE")
(prompt "Arc cannot be full 360 degrees.")
(setvar "errno" 7)
)
((equal (cdr (assoc 0 elist)) "ELLIPSE")
(prompt "Cannot break a closed, periodic curve at only one point.")
(setvar "errno" 7)
)
((and
(equal (cdr (assoc 0 elist)) "SPLINE")
(/= (logand (cdr (assoc 70 elist)) 1) 0)
)
(prompt "Cannot break a closed, periodic curve at only one point.")
(setvar "errno" 7)
)
;;;-------------------------------------
;;;Stop testing on entities that cannot be
;;;offset, but can be broken at one point
;;;-------------------------------------
;;trace is OK
((equal (cdr (assoc 0 elist)) "TRACE"))
;;3dmesh is OK
((and
(equal (cdr (assoc 0 elist)) "POLYLINE")
(/= (logand (cdr (assoc 70 elist)) 16) 16)
)
)
;;;-------------------------------------
;;;If it can't be offset, then don't fix it.
;;;Or is that don't mess with it?
;;;-------------------------------------
((not (vlax-method-applicable-p (vlax-ename->vla-object (car ent))
"Offset"))
(prompt "Can't break object")
(setvar "errno" 7)
)
)
)
(if ent
(progn
(initget 1)
(setq pnt (getpoint "\nSelect break point: "))
(command "_.break" ent "_f" "_non" pnt "_non" pnt)
;;;-------------------------------------
;;;If some custom object slipped by our
;;;previous testing, catch it here
;;;-------------------------------------
(if (> (getvar "cmdactive") 0)
(progn
(command)(command)
(prompt "\nCan't break object.")
)
)
)
)
(*error* nil)
)
Message 45 of 52
Anonymous
in reply to: Anonymous

Oh sure... blame it Uhden again! Notice how the originator hasn't
participated since Oct. 12. 😕

Not bad, Bobby, but speaking critically...

1. I think the locked layer checking should be done after checking the
object, since we don't want to PO some user who troubles him/herself to
unlock the layer and try again only to find out the object can't be broken
anyway.
2. I don't like the (initget) for having to pick a break point.
3. We haven't covered an informative means of ensuring that the break point
is a valid point at which to break the object.
4. We also forgot to place:
(vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
(vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
at the head of the program, and:
(vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
in the *error* function.

(setq Bottom_Line "I think I like your one-liner best.") ;

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juhden@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332

"Bobby C. Jones" wrote in message
news:B31096499A0274B46D76D81C2E305A72@in.WebX.maYIadrTaRb...
> Let's all be sure to thank, or is that blame 🙂 , John Uhden for pointing
> out the need to check for objects on locked layers and for the offset
method
> test. I've stolen his ideas and put them into this code.
>
> Now I just want to see a show of hands for those that are still going to
> use:
> (defun c:bb () (command "break" pause "f" pause "@")(princ))
> ...
Message 46 of 52
Anonymous
in reply to: Anonymous

Excellent catch. See partial code below:

(if ent
(progn
(redraw (car ent) 3);<---code to highlight ent.
(initget 1)
(setq pnt (getpoint "\nSelect break point: "))
(command "_.break" ent "_f" "_non" pnt "_non" pnt)
;;;-------------------------------------
;;;If some custom object slipped by our
;;;previous testing, catch it here
;;;-------------------------------------
(if (> (getvar "cmdactive") 0)
(progn
(command)(command)
(prompt "\nCan't break object.")
)
)
)
)
(*error* nil)
)
--
Bobby C. Jones
http://www.acadx.com
Message 47 of 52
Anonymous
in reply to: Anonymous

Also, you'll need to add code to the *error* handler to un-highlight the
entity in case the user hits escape.
--
Bobby C. Jones
http://www.acadx.com
Message 48 of 52
Anonymous
in reply to: Anonymous

> Oh sure... blame it Uhden again!

I just couldn't bring myself to take all the credit/blame for this code for
myself. I had to drag someone else in with me 🙂

> Not bad, Bobby, but speaking critically...
>
> 1. I think the locked layer checking should be done after checking the
> object, since we don't want to PO some user who troubles him/herself to
> unlock the layer and try again only to find out the object can't be broken
> anyway.

I agree with you on this one, however the developers at adesk don't. They
check for locked layers prior to any entity type checking. This may be one
where we get to make a command that's smarter than their's 🙂

> 2. I don't like the (initget) for having to pick a break point.

Just imitating the original break command. By this point in the command the
user should be commited enough that if he really wants to bail, he'll be OK
with reaching all the way over to that Esc key.

> 3. We haven't covered an informative means of ensuring that the break
point
> is a valid point at which to break the object.

Do we need to? The break command does a pretty good job of this on it's
own.

> 4. We also forgot to place:
> (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
> (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
> at the head of the program, and:
> (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
> in the *error* function.

While generally a great idea, I don't think that these are needed in this
case since we're simply issuing a single call to COMMAND.

> (setq Bottom_Line "I think I like your one-liner best.") ;

What!?! You must be kidding. After writing all this code, you can bet that
I'm going to use it 🙂 And besides, it's really Doug's one liner...
--
Bobby C. Jones
http://www.acadx.com
Message 49 of 52
Anonymous
in reply to: Anonymous

To quote Robert Bell, "Bwa ha ha"
and to quote Proverbs,
"As iron sharpens iron, so one man sharpens another."

Bobby: Great code and comment style. It works for me.
John: Sharp eye for the details but don't see the need for
wrapping a single command with undo marks.

I enjoyed the thread and was fascinated by the code, but I'm afraid I'll
keep my little one liner to save the memory space. My school machine
is still running on 64Mb. After OS and virus checker, its amazing that
AutoCAD runs at all.

Doug

"John Uhden" wrote in message
news:8F54128FC65BA401ABB9308E52FF049A@in.WebX.maYIadrTaRb...
> Oh sure... blame it Uhden again! Notice how the originator hasn't
> participated since Oct. 12. 😕
>
> Not bad, Bobby, but speaking critically...
>
> 1. I think the locked layer checking should be done after checking the
> object, since we don't want to PO some user who troubles him/herself to
> unlock the layer and try again only to find out the object can't be broken
> anyway.
> 2. I don't like the (initget) for having to pick a break point.
> 3. We haven't covered an informative means of ensuring that the break point
> is a valid point at which to break the object.
> 4. We also forgot to place:
> (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
> (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
> at the head of the program, and:
> (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
> in the *error* function.
>
> (setq Bottom_Line "I think I like your one-liner best.") ;
>
> --
> John Uhden, Cadlantic/formerly CADvantage
> --> mailto:juhden@cadlantic.com
> --> http://www.cadlantic.com
> 2 Village Road
> Sea Girt, NJ 08750
> Tel. 732-974-1711
> FAX 732-528-1332
>
> "Bobby C. Jones" wrote in message
> news:B31096499A0274B46D76D81C2E305A72@in.WebX.maYIadrTaRb...
> > Let's all be sure to thank, or is that blame 🙂 , John Uhden for pointing
> > out the need to check for objects on locked layers and for the offset
> method
> > test. I've stolen his ideas and put them into this code.
> >
> > Now I just want to see a show of hands for those that are still going to
> > use:
> > (defun c:bb () (command "break" pause "f" pause "@")(princ))
> > ...
>
>
Message 50 of 52
Anonymous
in reply to: Anonymous

> > 2. I don't like the (initget) for having to pick a break point.
>
> Just imitating the original break command. By this point in the command
the
> user should be commited enough that if he really wants to bail, he'll be
OK
> with reaching all the way over to that Esc key.
>
Hey, we don't want to raise the anxiety level of any user more than it
already is, let alone causing him to be committed, or making him either post
bail or attempt escape!

> > 3. We haven't covered an informative means of ensuring that the break
> point
> > is a valid point at which to break the object.
>
> Do we need to? The break command does a pretty good job of this on it's
> own.
I dunno. Try to "break" it.

> > 4. We also forgot to place:
> > (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
> > (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
> > at the head of the program, and:
> > (vla-EndUndoMark (vla-get-activedocument (vlax-get-acad-object)))
> > in the *error* function.
>
> While generally a great idea, I don't think that these are needed in this
> case since we're simply issuing a single call to COMMAND.
>
I do since the code itself may never get to (command) thereby causing a
subsequent UNDO to undo what was done before the program.

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juhden@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332
Message 51 of 52
Anonymous
in reply to: Anonymous

I don't know about you guys but if I'm exposed to anymore sharpening today,
there won't be anything left to sharpen! I have thoroughly enjoyed this
thread and have remembered many things forgotten & learned many things never
known before. Now I'm going to go and put a block on this thread...

John,
After examining the code and commands, you are correct. We do need the undo
marks to maintain consistency with the standard acad commands. It's
interesting to note that the last four items that you brought up all relate
to how our custom command compares to how standard acad commands act. This
brings up the question of how close should our commands imitate acad
commands? But that's another mile long thread altogether...
--
Bobby C. Jones
http://www.acadx.com
Message 52 of 52
Anonymous
in reply to: Anonymous

Bobby:

We don't really have this one totally covered (maybe I'll get around to it),
but what we're recognizing is all that goes into "professional strength"
code. Thanks to all for making this one fun!

--
John Uhden, Cadlantic/formerly CADvantage
--> mailto:juhden@cadlantic.com
--> http://www.cadlantic.com
2 Village Road
Sea Girt, NJ 08750
Tel. 732-974-1711
FAX 732-528-1332


"Bobby C. Jones" wrote in message
news:12B20A3CDA20C3B56420B082EA60138F@in.WebX.maYIadrTaRb...
> I don't know about you guys but if I'm exposed to anymore sharpening
today,
> there won't be anything left to sharpen! I have thoroughly enjoyed this
> thread and have remembered many things forgotten & learned many things
never
> known before. Now I'm going to go and put a block on this thread...
>
> John,
> After examining the code and commands, you are correct. We do need the
undo
> marks to maintain consistency with the standard acad commands. It's
> interesting to note that the last four items that you brought up all
relate
> to how our custom command compares to how standard acad commands act.
This
> brings up the question of how close should our commands imitate acad
> commands? But that's another mile long thread altogether...
> --
> Bobby C. Jones
> http://www.acadx.com

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

Post to forums  

Autodesk Design & Make Report

”Boost