Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to GETPOINT via Mouse Click Only??

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
gjrcmb
4849 Views, 13 Replies

How to GETPOINT via Mouse Click Only??

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?

13 REPLIES 13
Message 2 of 14
gjrcmb
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.

Message 3 of 14
pbejse
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

 


 

Message 4 of 14
gjrcmb
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.

Message 5 of 14
pbejse
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

 

 

 

 

Message 6 of 14
CADaSchtroumpf
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)
			)
		)
	)
))

 

Message 7 of 14
pbejse
in reply to: CADaSchtroumpf


@CADaSchtroumpf 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. Smiley Happy

Message 8 of 14
Lee_Mac
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.

Message 9 of 14
stevor
in reply to: CADaSchtroumpf

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
Message 10 of 14
gjrcmb
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,

Message 11 of 14
gjrcmb
in reply to: CADaSchtroumpf

Grread does provide the functionality that I was describing, so I will accept that as a solution, but at the sametime it also does have the shortcoming that Lee Mac describes.  It seems that the VBScript Sendkeys may be able to provide that type of fuctionality, however, at this time I don't think that the issue warrants me digging any deeper.  So I think that I may just keep the built-in AutoCAD coordinate input options, as that may be the best fuctionality compromise, and call it good.  I appreciate everyone's thoughts and assistance.  Nice to know I have options.  Smiley Happy

Message 12 of 14
stevor
in reply to: gjrcmb

 Plenty of options, in addition to the relative point by data entry:  @X,Y, and  @2D<.

 If you have some code to apply this to, post it,

 try to save the formatting with the RichText tab.

 

S
Message 13 of 14
gjrcmb
in reply to: stevor

The question that I posed is in relation to a program that I put together as part of another posting, where you can find an attached lisp program:

http://forums.autodesk.com/t5/AutoCAD-2012/Dynamic-blocks-with-text-increments/m-p/3260670#M9263

Not really up on how to save in a format with Rich Text tabs, so perhaps you can enlighten me.  I actually have been using NotePad++ as opposed to the Visual Lisp window as of late, as I seem to have an easier time interpreting my opening and closing parenthesis.  However, that may just be that I need to be more versed in using the Visual Lisp application.

As I already have indicated to Lee Mac separately, a couple of his prior postings, albeit unknowingly, contributed to the development of my lisp program.  At any rate, I am essentially a newbie in the AutoLISP world, and if you all have any comments feel free to post a comment or drop me a private message.

Message 14 of 14
stevor
in reply to: gjrcmb

1. Incremented array is a common application of autolisp, 

in its 2 decades of automation. 

LeeMac's site probably has an analog, as others do; and this forum has many.

Those methods can be applied to yours; but I avoid the dynamic type of blocks.

 

2. The 'Rich Text' tab should appear in the Reply page, this very window;

left side, under 'Body' or does in XP, etal.

It usually retains the paragraph formating, helpful in reading any code.

 

3. The only uses I can imagine for the GrRead function would be to reveal more

data as the cursor covers an object, like attached data, or to show certain

snap sites as in electrical wiring.

S

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost