Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Mentor
gjrcmb
Posts: 322
Registered: ‎06-21-2011
Message 1 of 14 (1,114 Views)
Accepted Solution

How to GETPOINT via Mouse Click Only??

1114 Views, 13 Replies
12-22-2011 04:54 PM

Hello LISPers,

 

I am trying to limit the input that can be processed when using the getpoint lisp function.  So the code below prevents the user from entering null input (i.e just hitting a carraige return) as specified by the initget bit code of 1, or a non-numeric entry (i.e. for instance, typing S and hitting a carriage return) as the getpoint function does not allow for a non-numeric entry.

 

    (initget 1)
    (setq PT1 (getpoint "\nPick Location of First Point: "))

 

However, the issue is that the code does NOT prevent the user from entering a number and hitting return.  For instance, if I enter the number 100 and hit return, getpoint accepts this as a valid entry and returns a point value that is projected, in some form or fashion, from I believe the last entered point or (0,0,0) if a point was not previously entered.  I only want the user to be able to select a point with a mouse click and not type in a number or point coordinate.

 

So is there some way with AutoLISP or Visual Lisp that you can prevent the user from typing in a numeric value and hitting a carraige return in conjuction with the getpoint function?  Or is there some other function that will provide the getpoint functionality while providing the entry limitations described?

Valued Mentor
gjrcmb
Posts: 322
Registered: ‎06-21-2011
Message 2 of 14 (1,108 Views)

Re: How to GETPOINT via Mouse Click Only??

12-22-2011 06:11 PM in reply to: gjrcmb

After thinking about this a bit more, I suppose that the getpoint is functioning in accordance with AutoCAD.  It is allowing for a point to be entered by Direct Distance Entry or Relative Coordinates in relation to the last point, or Absolute Coordinates, as well as allowing you to select a point.  Not sure if there is a system variable that affects the operability of coordinate input and whether this might have some affect.

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 3 of 14 (1,100 Views)

Re: How to GETPOINT via Mouse Click Only??

12-22-2011 09:40 PM in reply to: gjrcmb

gjrcmb wrote:

After thinking about this a bit more, I suppose that the getpoint is functioning in accordance with AutoCAD.  It is allowing for a point to be entered by Direct Distance Entry or Relative Coordinates in relation to the last point, or Absolute Coordinates, as well as allowing you to select a point.  Not sure if there is a system variable that affects the operability of coordinate input and whether this might have some affect.


Use initget 128 / 129. a keyboard entry will give you a string value.then use cond statement

 

(defun c:test (/ pt1)
  (while (and (null pt1)
    	 (progn
           (initget 129)
		(setq pt1 (getpoint "\npick location of first point: "))
             )
           )
 (cond
      ((listp pt1) (print pt1))
      ((eq (type pt1) 'Str) (setq pt1 nil)(princ "\nInvalid Input"))
      
      )
    )
 (princ)
  )

 HTH

 


 

Valued Mentor
gjrcmb
Posts: 322
Registered: ‎06-21-2011
Message 4 of 14 (1,086 Views)

Re: How to GETPOINT via Mouse Click Only??

12-23-2011 12:54 AM in reply to: pbejse

That definitely helps.  I have not previously used initget 128 or 129, as well as the listp or type functions.  After looking at the code a bit, I see how you are processing a keyboard entry to determine whether it is valid or not.

My original intention was to prevent the user from inadvertently typing in a number and/or force the user to mouse select a point location as opposed to specifying its location through keyboard entry.  Your solution prevents the user from using Direct Distance Entry and therefore would prevent the inadvertent entry of a single number.  So your solution does address the question:  "So is there some way with AutoLISP or Visual Lisp that you can prevent the user from typing in a numeric value and hitting a carraige return in conjuction with the getpoint function?"  Although, it still allows for entry through absolute or relative coordinates, but maybe that's not a bad thing.

So that brings up my earlier comment, "I suppose that getpoint is functioning in accordance with AutoCAD" that you took note of.  I am now questioning whether I want to override the built-in functionality of the AutoCAD coordinate entry options, especially if I can only override some of the coordinate entry options.  Perhaps it is better to not limit the user's entry options where not absolutely necessary, and allow them the latitude to interpret the outcome of their input.

Anyway, just sharing some of my thoughts with you.  I'm sure their must be a way to detect a carraige return, but perhaps I would need to look beyond LISP.  That probably is not warranted in this instance.  Thanks for your assistance.  Talk to you more on the boards.

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 5 of 14 (1,081 Views)

Re: How to GETPOINT via Mouse Click Only??

12-23-2011 01:18 AM in reply to: gjrcmb

You can use either VBscript <Sendkeys>

 

(setq Skeys (cond (Skeys) ((vlax-create-object "WScript.Shell"))))
            (vl-catch-all-apply 'vlax-invoke (list Skeys 'sendkeys "{ENTER}"))

 

or you can use the not so complicated as VB script grread

wherein you can detects user input if via keyboard/mouse drag/mouse button

 

See attached sample by Lee Mac.(with descrioption to boot)

 

HTH

 

 

 

 

Valued Mentor
CADaStroumph
Posts: 322
Registered: ‎10-15-2008
Message 6 of 14 (1,079 Views)

Re: How to GETPOINT via Mouse Click Only??

12-23-2011 01:29 AM in reply to: gjrcmb

You can try with (grread).

 

((lambda ( / key)
	(princ "\nPick Location of First Point: ")
	(while (and (setq key (grread T 4 0)) (/= (car key) 3))
		(cond
			((eq (car key) 5)
				(cadr key)
			)
		)
	)
))

 

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 7 of 14 (1,070 Views)

Re: How to GETPOINT via Mouse Click Only??

12-23-2011 03:20 AM in reply to: CADaStroumph

CADaStroumph wrote:

You can try with (grread).

 

((lambda ( / key)
	(princ "\nPick Location of First Point: ")
	(while (and (setq key (grread T 4 0)) (/= (car key) 3))
		(cond
			((eq (car key) 5)
				(cadr key)
			)
		)
	)
))

 


Yeah, like that. :smileyhappy:

*Expert Elite*
Lee_Mac
Posts: 1,101
Registered: ‎12-29-2009
Message 8 of 14 (1,060 Views)

Re: How to GETPOINT via Mouse Click Only??

12-23-2011 05:00 AM in reply to: gjrcmb

One more, to match the parameters of the standard getpoint function:

 

(defun _getpoint ( msg pt )
    (princ msg)
    (
        (eval
            (list 'lambda '( / gr )
                (list 'while '(/= 3 (car (setq gr (grread t 13 0))))
                    (if pt
                       '(if (= 5 (car gr))
                            (progn (redraw) (grdraw pt (cadr gr) -1))
                        )
                    )
                )
               '(redraw) '(cadr gr)
            )
        )
    )
)

 

However, using grread is not a practical solution since standard AutoCAD functionality such as ObjectSnap / Tracking / Orthomode is not available to the user.

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Mentor
stevor
Posts: 835
Registered: ‎12-26-2005
Message 9 of 14 (1,058 Views)

Re: How to GETPOINT via Mouse Click Only??

12-23-2011 05:19 AM in reply to: CADaStroumph

This can be expanded to provide features more specific than vanilla Acad, like showing the object snaps of objects on certain layers while ignoring others, or entring a single key to instigate a function.

 

A function to apply his method:

 

 ; Mouse Point/ deriv:CADaStroumph-12-23-2011, etal
 (defun M_SP ( ps / key) (princ ps ) ; Prompt String
   (while (and (setq key (grread T 4 0)) ; add other
               (/= (car key) 3)) ; sel/exit opts here
    (cond ((eq (car key) 5) (cadr key) ) ) )
   (car (cdr key))  )

 As a demo, a graphic X:
 
 ; point proof, 2D or 3D,  AusCadd.com
 (DEFUN PNT_p (p / e l) ; quaLify List as a 2D or 3D point
  (if (and p (Listp p) (or (= (Length p) 3) (= (Length p) 2) ) )
   (progn (foreach e P (if (not (numberp e)) (setq P Nil ) )) P )) ) ;
 
 ; Graphic X in UCS: Pt, DiameterRatio, ColorInt; AusCadd.com
 (defun gr_Xdc (p d c  / sz 1qp p0) ; graphic X size, coLor
  (if (Pnt_P p) (progn ; replace viewsize factors for absolutes
   (setq sz (* d (/ (getvar "viewsize") 50))  1qp (/ pi 4))
   (grdraw (poLar p 1qp sz) (poLar p (* 5 1qp) sz) c)
   (grdraw (poLar p (* 3 1qp) sz) (poLar p (* 7 1qp) sz) c)
  p)) ) ;
 
The app:
 (setq sp (M_SP " Pick Pt " ))
 (gr_xdc sp 2 1)  
 Or, fop  a point entity:
 ;(command "point" sp ) ; etc

 

S
Valued Mentor
gjrcmb
Posts: 322
Registered: ‎06-21-2011
Message 10 of 14 (1,041 Views)

Re: How to GETPOINT via Mouse Click Only??

12-23-2011 11:19 AM in reply to: stevor

Wow, thanks for all the input!  I have not dug into using the Autolisp graphics functions, so I guess time has come.  Also need to start diving into the visual lisp code more to discover the added fuctionality over Autolisp.  I'll check out the code over the weekend and let you know my findings.

Thanks for the help,

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community