Jump to content

Recommended Posts

Posted

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...

Posted

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.

Posted

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

Posted

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?

Posted

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

Posted

Oh.... I got it.. Thanks a lot...!!!:)

Posted

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 !!!")
 )

Posted

Thanks tharwat313....

Hmm... This is why I like this forum the most... Someone helps me out in no time, always.

Posted
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

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...