Jump to content

Recommended Posts

Posted

you may think this is silly or a stupid question, but is there a way for me to type the command, and wherever the mouse is, it will simulate a left click...

Posted

What exactly you are trying to do? Perhaps there would be a better approach.

Posted
What exactly you are trying to do? Perhaps there would be a better approach.

im writing an AutoHotkey Script that uses the COM on Autocad and COM from Excel... basically, what the script does is get the XYZ coordinates of a line in Autocad, and find it in excel(it was DataExtract). since i cant figure out how will i click a line on Autocad, and since i still have the Autolisp code that Lee Mac made.

i was thinking ill use that autolisp, instead of the VBA...

thats why i was asking if i could select o click on a line when i type the command...

 

BTW the proccess of the script is like this:

i right click

it will type the autolisp command

i select a line

and the script will press enter....

 

then from there, the script will find the line coordinates from Excel. if it finds the coordinate, I will type some values

then begin from the start again.

 

so you see, i was trying to lessen the time spent in pressing the right click and the pressing the left click again...

is there a way so that i could just type the lisp command, and it will select a line where the cursor is???

 

 

BTW here is the autolisp:

http://www.cadtutor.net/forum/showthread.php?97782-getting-X-Y-Z-Coordinates-of-a-line&p=667368&viewfull=1#post667368

 

what it does is copy to CLIPBOARD the selected line

and from there i use that clipboard to find the coordinates in excel

 

pretty much, i wanna tweak the autolisp code so it will select wherever the cursor at.

Posted

You could use this modified version of Lee's code:

(defun c:l2c ( / ent )
 (if ; http://www.cadtutor.net/forum/showthread.php?97782-getting-X-Y-Z-Coordinates-of-a-line&p=667368&viewfull=1#post667368
   (setq ent
     (cond
       (
         (
           (lambda ( / e r )
             (and
               (setq e (car (nentselp (cadr (grread t)))))
               (member '(0 . "LINE") (entget e))
               (setq r e)
             )
             r
           )
         )
       )
       ( 
         ( (lambda (f / SS) (if (setq SS (cadr (ssgetfirst))) (f SS 0)))
           (lambda ( SS i / e )
             (cond 
               ( (not (setq e (ssname SS i))) nil)
               ( (member '(0 . "LINE") (entget e)) e )
               ( (f SS (1+ i)) )
             )
           )
         )
       )
       ( (LM:selectifobject "\nSelect line: " "LINE") )
     ); cond
   ); setq ent
   (if (LM:copytoclipboard
     (LM:lst->str
       (mapcar 'rtos
         (append
           (cdr (assoc 10 (entget ent)))
           (cdr (assoc 11 (entget ent)))
         )
       )
       "\t"
     )
   )
   (princ "\nLine endpoints copied to clipboard.")
   )
 )
 (princ)
)

 

Run the command, and the code will use the line that matches the first critera (list by priority):

  • The cursor is over the LINE object, highlighting it (but it may be not selected)
  • A selection was made (implied), the code will check for the first LINE object and use it
  • User is prompted manually to select a LINE (with LM:selectifobject subfoo)

 

BTW In my mind was the SendKeys approach, but apparently it doesn't work with mouse buttons, altho found some documentation , where my plan would be:

(setq pxl (vk_Point2Pixel (cadr (grread t))))
(vlax-invoke ws 'SendKeys (strcat "{ClickLeft " (substr (apply 'strcat (mapcar '(lambda (x) (strcat ", " (vl-prin1-to-string x))) pxl)) 3)  "}"))

 

but the result is:

Error: Exception occurred

:unsure:

Posted
You could use this modified version of Lee's code:

(defun c:l2c ( / ent )
 (if ; http://www.cadtutor.net/forum/showthread.php?97782-getting-X-Y-Z-Coordinates-of-a-line&p=667368&viewfull=1#post667368
   (setq ent
     (cond
       (
         (
           (lambda ( / e r )
             (and
               (setq e (car (nentselp (cadr (grread t)))))
               (member '(0 . "LINE") (entget e))
               (setq r e)
             )
             r
           )
         )
       )
       ( 
         ( (lambda (f / SS) (if (setq SS (cadr (ssgetfirst))) (f SS 0)))
           (lambda ( SS i / e )
             (cond 
               ( (not (setq e (ssname SS i))) nil)
               ( (member '(0 . "LINE") (entget e)) e )
               ( (f SS (1+ i)) )
             )
           )
         )
       )
       ( (LM:selectifobject "\nSelect line: " "LINE") )
     ); cond
   ); setq ent
   (if (LM:copytoclipboard
     (LM:lst->str
       (mapcar 'rtos
         (append
           (cdr (assoc 10 (entget ent)))
           (cdr (assoc 11 (entget ent)))
         )
       )
       "\t"
     )
   )
   (princ "\nLine endpoints copied to clipboard.")
   )
 )
 (princ)
)

 

Run the command, and the code will use the line that matches the first critera (list by priority):

 

  • The cursor is over the LINE object, highlighting it (but it may be not selected)
  • A selection was made (implied), the code will check for the first LINE object and use it
  • User is prompted manually to select a LINE (with LM:selectifobject subfoo)

 

 

BTW In my mind was the SendKeys approach, but apparently it doesn't work with mouse buttons, altho found some documentation , where my plan would be:

(setq pxl (vk_Point2Pixel (cadr (grread t))))
(vlax-invoke ws 'SendKeys (strcat "{ClickLeft " (substr (apply 'strcat (mapcar '(lambda (x) (strcat ", " (vl-prin1-to-string x))) pxl)) 3)  "}"))

 

but the result is:

Error: Exception occurred

:unsure:

 

OMG! This is the one!!!! exactly what i have in mind!

you sir are a genius! now i don't have to left click! ill just hover the mouse to the line!

Posted
OMG! This is the one!!!! exactly what i have in mind!

you sir are a genius! now i don't have to left click! ill just hover the mouse to the line!

 

You are wellcome! :)

 

BTW if you don't want to be forced to hover directly over the line, and have the option to use the closest one to the cursor -

 

Replace the:

(setq ent ...)

With:

(setq ent
 (cond
   (
     (
       (lambda ( / e r )
         (and
           (setq e (car (nentselp (cadr (grread t)))))
           (member '(0 . "LINE") (entget e))
           (setq r e)
         )
         r
       )
     )
   )
   ( 
     ( (lambda (f / SS) (if (setq SS (cadr (ssgetfirst))) (f SS 0)))
       (lambda ( SS i / e )
         (cond 
           ( (not (setq e (ssname SS i))) nil)
           ( (member '(0 . "LINE") (entget e)) e )
           ( (f SS (1+ i)) )
         )
       )
     )
   )
   (
     (
       (lambda ( / SS p i tmp r )
         (and
           (setq SS (ssget "_X" (list '(0 . "LINE") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))))
           (setq p (cadr (grread t)))
           (repeat (setq i (sslength SS))
             (setq tmp (mapcar 'cdr (vl-remove-if-not (function (lambda (x) (member (car x) '(-1 10 11)))) (entget (ssname SS (setq i (1- i)))))))
             (setq tmp (cons (car tmp) (apply (function min) (mapcar (function (lambda (x) (distance p x))) (cdr tmp)))))
             (cond 
               ( (not r) (setq r tmp) )
               ( (apply '> (mapcar 'cdr (list r tmp))) (setq r tmp) )
             )
           )
         )
         (car r)
       )
     )
   )
   ( (LM:selectifobject "\nSelect line: " "LINE") )
 ); cond
); setq ent

 

Still a question remains if its possible to send a mouse click with the SendKeys method. :unsure: :geek:

Posted
Perhaps... :

 

It seems that you forgot ab this one Grrr...

 

http://www.cadtutor.net/forum/showthread.php?96083-Brush-Select-Circle-Select/page2&p=#11

 

I remember it, just didn't found a connection.

Still your code (expanding circle approach) requires rewriting to match OP's request here -

remove grread inputs and use optimal increment value for the fuzz, to reduce the requested input just to the lisp-call.

Posted
You could use this modified version of Lee's code:

(defun c:l2c ( / ent )
 (if ; http://www.cadtutor.net/forum/showthread.php?97782-getting-X-Y-Z-Coordinates-of-a-line&p=667368&viewfull=1#post667368
   (setq ent
     (cond
       (
         (
           (lambda ( / e r )
             (and
               (setq e (car (nentselp (cadr (grread t)))))
               (member '(0 . "LINE") (entget e))
               (setq r e)
             )
             r
           )
         )
       )
       ( 
         ( (lambda (f / SS) (if (setq SS (cadr (ssgetfirst))) (f SS 0)))
           (lambda ( SS i / e )
             (cond 
               ( (not (setq e (ssname SS i))) nil)
               ( (member '(0 . "LINE") (entget e)) e )
               ( (f SS (1+ i)) )
             )
           )
         )
       )
       ( (LM:selectifobject "\nSelect line: " "LINE") )
     ); cond
   ); setq ent
   (if (LM:copytoclipboard
     (LM:lst->str
       (mapcar 'rtos
         (append
           (cdr (assoc 10 (entget ent)))
           (cdr (assoc 11 (entget ent)))
         )
       )
       "\t"
     )
   )
   (princ "\nLine endpoints copied to clipboard.")
   )
 )
 (princ)
)

 

It appears as if this code is missing the Select If Object function, although I might just be reading it wrong.

 

;; Select if Object  -  Lee Mac
;; Continuously prompts the user for a selection of a specific object type

(defun LM:selectifobject ( msg typ / ent )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel msg)))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (not (wcmatch (cdr (assoc 0 (entget ent))) typ))
                   (princ "\nInvalid object selected.")
               )
           )
       )
   )
   ent
)

 

Perhaps... :

 

It seems that you forgot ab this one Grrr...

 

http://www.cadtutor.net/forum/showthread.php?96083-Brush-Select-Circle-Select/page2&p=#11

 

I still make use of this program almost daily. The version I use now is a heavily modified one that filters based on layers, but either way, it's been quite useful. Thanks again for it.

  • 5 years later...
Posted

Hi.

I need to do what is in the title:

to select the object where the mouse curssor is.

I wrote a short code that go from paper space to model space and use part of the code from the examples here to select an object where the curssor is but I get some other list.

here is the code I wrote:

(defun c:test3 ( / pt pt1)
(setq pt (getpoint)) ;;get point in paper space
;(setq pt1 (trans pt 3 0))
(command "._MSPACE")
(setq e (car (nentselp (cadr (grread t)))))
(command "._PSPACE")
(princ e)
(entget e)
)

 

in the attached drawing I'm in Layout1 tab.

run the code,

click on the elbow block,

but the return enthity is not the block...

I need to return to paper space with the block entity name...

 

thanks,

aridzv.

Drawing1.dwg

Posted

Try this:

 

(defun c:test3 ( / pt pt1)
  (setq pt (getpoint)) ;;get point in paper space
;  (setq pt1 (trans pt 3 0))
  (command "._MSPACE")
  (setq e (car (last (nentselp (cadr (grread t))))))
  (command "._PSPACE")
  (princ e)
  (entget e)
)

 

nentselp, like nentsel, returns a list, the first item, (car ) is the nested entity that was selected - so if you select a block it will be maybe the line within the block, info on the next two are online, the last item in the list is the parent entity - in your case the complete block "Welding Elbow"... so add a (last  ) into the code to get that

  • Thanks 1

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