Jump to content

How to conquer entsel's defection?


Ahankhah

Recommended Posts

Hello friends,

 

as some of you know, entsel is a good function to select single objects, but it has a severe flaw in distinguishing between "pressing enter" and "selecting nothing":(.

 

Has Anyone a suggestion to conquer this defection:oops:?

Link to comment
Share on other sites

Here is the code:

(defun C:Length () (MT-TotalLength))

(defun MT-TotalLength (/ *error* ans layname cont len)
   (MT-Start)
   (initget "Name eXit _Name eXit")
   (setq ans nil)
   (setq ans
            (entsel
                "\nSelect an object on the layer to proceed [Name/eXit] <eXit>: "
            )
   )
   (cond
       ((member ans '(nil "eXit")) (exit))
       ((= "Name" ans)
        (setq cont T)
        (while cont
            (setq layname (getstring T "\nEnter layer name: "))
            (if (null (read layname))
                (progn (princ "\nNull name for layer not allowed, try again."))
                (progn (if (tblsearch "layer" layname)
                           (setq cont nil)
                           (princ (strcat "\nLayer \""
                                          layname
                                          "\" not exists, try again."
                                  )
                           )
                       )
                )
            )
        )
       )
       (T (setq layname (cdr (assoc 8 (entget (car ans))))))
   )
   (and (setq ss (ssget "_X"
                        (list (cons -4 "<OR")
                              (cons 0 "LINE")
                              (cons 0 "ARC")
                              (cons 0 "LWPOLYLINE")
                              (cons -4 "OR>")
                              (cons 8 layname)
                        )
                 )
        )
        (setq len (MT-Calc-Length ss))
   )
   (setq msg
            (strcat
                "Total length of objects (Lines, Arcs, Polylines) in layer:   \""
                layname
                "\"\n\nequals to:   "
                (rtos len)
            )
   )
   (princ msg)
   (alert msg)
   (MT-End)
)

(defun MT-Calc-Length (ss / sslist len)
   (setq sslist (MT-Conv-SS-To-List ss))
   (setq len 0)
   (foreach obj sslist (setq len (+ len (MT-Get-Obj-Length obj))))
)

(defun MT-Conv-SS-To-List (ss / entlist index)
   (setq entlist nil)
   (if (= 'PICKSET (type ss))
       (progn (setq index -1)
              (repeat (sslength ss)
                  (setq
                      entlist (append (list (ssname ss (setq index (1+ index))))
                                      entlist
                              )
                  )
              )
       )
   )
   (reverse entlist)
)

(defun MT-Error (msg)
   (or (member (read msg) '(nil *BREAK *CANCEL*)); *EXIT* isn't an error condition
       (princ (strcat "\n** Error: " msg " **"))
   )
   (setvar 'Cmdecho 1)
   (princ)
)

(defun MT-Start () (setq *error* MT-Error) (setvar 'Cmdecho 0))

(defun MT-End () (MT-Error ""))

(defun MT-Exit () (exit))

 

As you can check, there is no difference between pressing Enter and clicking mouse botton in an empty area in work space.

This is the above mentioned restriction.

Link to comment
Share on other sites

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