initget and entsel - different Lisp behaviour AutoCAD - BricsCAD

Hi all,
i have used a combination of initget and entsel very frequently in AutoCAD.
By porting to BricsCAD i have to recognize there's a different behaviour.
I have tracked it down to a very simple demo lisp function:

(defun test_entsel ( / inpvar)
(initget "L K ")
(setq inpvar (entsel "\rTest entsel with nitget: "))
(print "inpvar1 : ")(princ "-")(princ inpvar)(princ "-\n")
(princ)
)

The intention is to allow a key at the entsel-prompt to be interpreted as a "" string (empty string) as a alternative selection-input.
AutoCAD provides the desired result for a key input because of the spaces in initget behind the K code.

The command-prompt in AutoCAD is like this:

Befehl: (test_entsel)
Test entsel with initget:
"inpvar1 : " --

In BricsCAD it looks like this:

(test_entsel)
Test entsel with initget:
"inpvar1 : " -NIL-

It seems that the additional spaces are not recognized in BricsCAD while they are recognized in AutoCAD.

Is there an alternative way for BricsCAD to get the same behaviour as in AutoCAD?

Many thanks in advance for comments or tips to overcome this issue.

Richard

Comments

  • Dear Richard,

    which version of AutoCAD do you refer to ?
    I tried with AutoCAD 2009 ... 2018, and behaviour is identical - which is even logical :
    the 1 trailing space is only the delimiter for the next keyword (which is not following), so you will need to add 2 spaces at the end ...

    But even then, BricsCAD does indeed not recognise the extra "space" as input keyword :-(

    Unfortunately, as (entsel) does not, by definition, honor the 128 flag (arbitrary input), I found no other way, same results as you reported.

    Please send us a Support Request, to handle and fix this input defect.

    many greetings !

  • Roy Klein Gebbinck
    edited January 2018

    (n)entsel(p) does honor the 128 flag. If that flag is set any string can be entered. But just pressing enter will return nil. It seems quite easy to work around this issue...

  • Hi Torsten and Roy,
    thank you for investigating this.

    My AutoCAD version is 2010.
    In the AutoCAD lisp source there are 2 spaces behind the K.
    (initget "L K ")
    I did some testing with the initget option and so removed one of the spaces in the sample function (shame on me :-().
    With the 2 spaces it works in AutoCAD 2010 as described: results in an empty string ""

    I use this construct inside a while loop.
    The advantage is it provides more input options.
    The L and K keys switch the mode of the command.
    The key simply restarts the while loop with a counter incremented or decremented.

    A example is the placement of a standard part like a screw:
    repeated press of steps through the various screw lemgths defined and updates the display.
    L or K give the direction (l = longer, k (german kurz) = shorter)
    To leave this very flexible loop i use a click on the left mouse button or pick button with a tablet puck (this selects the current length).
    At this point the last displayed screw size is inserted in the drawing.
    With this design it's not necessary to enter another key to accept the selected size to go further.

    Regards,
    Richard

  • If you want to differentiate between Enter and a failed pick you can use the ERRNO variable.
    BTW:
    Using "L" as a keyword in this context is not possible in the English version of BricsCAD as it stands for "Last" and is a valid response to the (entsel) function.
    (defun c:test ( / inp) (setvar 'errno 0) (initget "K M") (setq inp (entsel)) (cond ((= 7 (getvar 'errno)) (princ "\nPick failed ") ) ((= 52 (getvar 'errno)) (princ "\nEnter key ") ) ((= "K" inp) (princ "\nK keyword ") ) ((= "M" inp) (princ "\nM keyword ") ) ((vl-consp inp) (princ (strcat "\Selected entity: " (vl-princ-to-string (car inp)))) ) ) (princ) )

  • Hi Roy,
    thank you for the suggestion of the ERRNO variable.
    I have implemented a function to check for NIL value in the entsel input and a corresponding ERRNO of 52.
    So far this seems to work.
    To get as close to AutoCAD as possible it would be fine to extend initget in BricsCAD to recognize the 2 spaces as a input of a empty string (as Torsten has mentioned).
    For me, the workaround with ERRNO seems acceptable.
    Many thanks again,
    Richard

  • Meanwhile, the Lisp engine has been improved/fixed/updated to particulary check for the "2-spaces-keyword" problem ... and original code works as expected;
    so for backward-compatibility, relying on that extra check (NIL + errno=52) seems safest, and still compatible with future BricsCAD version, containing that Lisp engine fix.

    many greetings !

  • Hi Torsten,
    you guys are really smart...

    In the meantime i have stepped further in the porting process.
    It's as always: once it compiles it does not mean it works :-)

    In case of initget: the BRx companion acedInitGet shows exactly the same behaviour.
    I have overcome this by implementing the same check as in Lisp.
    Probably you could adjust the source code in BRx as well.

    Again, many thanks for your quick response and hard work in implementing missing functions.

    Kind regards,
    Richard

  • Dear Richard,

    indeed, acedGetXxx() functions will show same problem ... will be fixed as well, similar to Lisp.

    many thanks for feedback & many greetings !

  • Here is my take, incorporating Roy's errno checks

    (defun C:Test-init ()
     (setvar 'errno 0)
     (initget (strcat "S M " (chr 32)))
     (setq *initret* (entsel "\nType option: "))
     (Cond
        ((= *initret* "S")(Princ "\nYou entered \"S\""))
        ((= *initret* "M")(Princ "\nYou entered \"M\""))
        ((= *initret* (chr 0)) (Princ "\nYou pressed Enter/Space bar in AutoCAD")) ; This condition will only work in AutoCAD
        ((= (Type *initret*) 'LIST)(Princ (strcat "\nYou selected a: " (vle-entget 0 (car *initret*)))))
        ((and (not *initret*)(= 7 (getvar 'errno))) (Princ "\nYou picked in a blank Space"))
        ((and (not *initret*)(= 52 (getvar 'errno))) (Princ "\nYou pressed Enter/Space bar"))
     )
     (prin1)
    )
    

    I used (chr 32) to make the space more identifiable when used with initget. I also found that AutoCAD returns an Enter, not a Space in this situation. BTW picking in a blank space can be useful, such as opening a dialogue box to make a selection from.

    Regards,
    Jason Bourhill
    CAD Concepts

  • Dear Richard, Dear All,

    same fix as for Lisp engine has been added to BRX' acedEntSel/AcedEntSelP/acedNEntSelP functions, seems to work as expected.
    many greetings !

This discussion has been closed.