Jump to content

Recommended Posts

Posted

Hi all, I'm new to this forum and to AutoLISP programming.

I've studied a tutorial and now I'm trying to do something by myself.

 

I have a 2D drawing with a square made using a polyline, now I want to create a routine which asks me to select a polyline and simply tells me that I have selected it correctly.

This is my code

(defun c:polysel(/ ent_name element)
 (setq ent_name (car(entsel "\n Select a polyline:")))
 (setq element (entget ent_name))
 (if (= (cdr(assoc 0 element)) "POLYLINE")
   (print "\n Polyline selected!")
 )
 (princ)
)

I select the polyline, but the message "Polyline selected!" doesn't appear, what's wrong?

Posted

Chech this out;

(defun c:polysel (/ ent_name element)
 (setq ent_name (car(entsel "\n Select a polyline:")))
 (setq element (entget ent_name))
 (if (= (cdr(assoc 0 element)) "POLYLINE")
   (alert " Your have selected POLYLINEs.")
   (alert (strcat "Your Selection is .." " "(cdr (assoc 0 element))"."))
 )
 (princ)
)

 

Welcome to CADTutor

 

Tharwat

Posted

Thanks, it says I have selected a LWPolyline, so I suppose I have to check for LWPolyline and not POLYLINE since I'm working on 2D drawings.

Posted
Thanks, it says I have selected a LWPolyline, so I suppose I have to check for LWPolyline and not POLYLINE since I'm working on 2D drawings.

 

Yes try to select any other entity, so it will give you the name of the selected entity....

 

Regards

 

Tharwat

Posted

Welcome to the forum!

 

Just a slightly different test expression from your code Alhazred

 

 

(if
   (wcmatch (setq etype (cdr(assoc 0 element))) "*POLYLINE")
   (princ (strcat  "\n[" etype "] selected"))
 )

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