harilalmn Posted January 24, 2011 Posted January 24, 2011 Hello All, I am just learning AutoLisp. So I know a little about it. I thought of writing a program to draw a line from the intersection (if not intersecting, when they are extended) of two lines. Thought of using Inters Function and it worked fine. But now I want to check if the selected entity is a line. How to do that? I wrote something like this but it fails; (defun c:Intr() (Setq Line1 (car (entsel "\nSelect First Line:"))) (CheckObject Line1) BLAH BLAH BLAH..... ) (defun CheckObject(Enty) (Setq ObjType(assoc 0 (entget (Enty)))) (if (/= ObjType "LINE") ( (alert "No Lines Selected... Ending") (exit) ) ) ) Please help... Quote
BIGAL Posted January 24, 2011 Posted January 24, 2011 You also need to check if its a polyline and maybe explode it so you can still inters it. Will post at work tomorrow code for this. Quote
Tharwat Posted January 24, 2011 Posted January 24, 2011 Check this out ...... (Setq Line1 (car (entsel "\nSelect First Line:"))) (if (eq (cdr(assoc 0 (entget Line1)))"LINE") (alert "That's Right") (alert "I am sorry, That's wrong") ) Tharwat Quote
harilalmn Posted January 24, 2011 Author Posted January 24, 2011 Wow... That Worked... Thats what I wanted. Could you please tell me where I went wrong in my code above? Also, If the user is not selecting a line, how can i repeat the step till he selects a line? Quote
MSasu Posted January 24, 2011 Posted January 24, 2011 The ENTGET will return a list of dotted pairs; to get the type of entity use only the second item - in your excerpt code you are trying to compare a list (dotted pair) with a string; also the entity name shouldn't be enclosed in parenthesis. Please find below your corrected code: (defun CheckObject(Enty) (Setq ObjType [color=red](cdr[/color] (assoc 0 (entget Enty))[color=red])[/color])[color=red] ;(Enty)))))[/color] (if (/= ObjType "LINE") ( (alert "No Lines Selected... Ending") (exit) ) ) ) Regards, Mircea Quote
harilalmn Posted January 24, 2011 Author Posted January 24, 2011 Oh.... I got it.. Thanks a lot...!!! Quote
Tharwat Posted January 24, 2011 Posted January 24, 2011 This one to force the user to select only a line .... (while (not (and (Setq Line1 (car (entsel "\nSelect First Line:"))) (eq (cdr (assoc 0 (entget Line1)))"LINE") )) (prompt "\n Please select Line onle !!!") ) Quote
harilalmn Posted January 24, 2011 Author Posted January 24, 2011 Thanks tharwat313.... Hmm... This is why I like this forum the most... Someone helps me out in no time, always. Quote
Tharwat Posted January 24, 2011 Posted January 24, 2011 Thanks tharwat313....Hmm... This is why I like this forum the most... Someone helps me out in no time, always. You're welcome any time. Regards, Tharwat Quote
Recommended Posts
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.