How to read current Initget bits value and Keywords string?

How to read current Initget bits value and Keywords string?

CodeDing
Advisor Advisor
1,154 Views
20 Replies
Message 1 of 21

How to read current Initget bits value and Keywords string?

CodeDing
Advisor
Advisor

Hello all,

 

Does anyone know if it's possible to read the current (initget ...) BITS value and KEYWORDS string via AutoLISP or Visual Lisp?

 

If you're asking "Why?", it's because it would be useful in creating your own (getxxx ...) function while utilizing an existing (getxxx ...) function inside of a while loop to account for invalid inputs (as current getxxx functions do).

 

So, for example, if I set initget somewhere in my code...

(initget 6 "Some Keywords")

... then I could read these values somehow..

Command: (setq bits (getvar '??????))
6
Command: (setq keywords (getvar '??????))
"Some Keywords"

 

Any help is appreciated.

Best,

~DD

0 Likes
1,155 Views
20 Replies
Replies (20)
Message 2 of 21

steve_carson
Enthusiast
Enthusiast

Can't you just set the bits and keywords variables the first time you use initget so you can refer to them where ever you want in the code? 

0 Likes
Message 3 of 21

john.uhden
Mentor
Mentor

Somehow I doubt that those things are accessible, at least via AutoLisp.

You may have to vl-catch any input errors.

John F. Uhden

0 Likes
Message 4 of 21

CodeDing
Advisor
Advisor

@steve_carson ,

 

Not really, if you're creating your own (getxxx) function. The idea is that your custom (getxxx) function will correlate similarly to (initget) as other (getxxx) functions would respond. But since a custom (getxxx) function would have OTHER requirements to check (other than just the (initget) bits..) then you would have to call the original (initget) again inside of a while loop inside your custom (getxxx) function... the original (initget) call could not account for all of your custom checks inside of your custom (getxxx) function.

 

Best,

~DD

0 Likes
Message 5 of 21

diagodose2009
Collaborator
Collaborator

You must very-fast myReadkey .. I tested inside GSt**Cad2009., and the function work fine

 

;;Inf:Wait until press keys k
(defun dfn_getx_readkey(k574 t469 / retc kbd msg two chk lei)
  (setq;|a41951|;
	 retc (chr 0)
	 kbd (if (>  k574 "") k574 "")) (setq;|a42011|;
	 msg (if (>  t469 "") t469 "\nByA:DragneAdrian2019=T469error<>Str:")) (prompt msg) (progn (setq;|a42061|;
	 chk (if (>  (strlen kbd) 1) 0 1)) (while (=  chk 0) (progn  (setq;|a42117|;
	 two 0) (while (/= two 2) (setq;|a42155|;
	 lei (grread)
	 two (car lei)) (setq;|a42203|;
	 retc (strcase (chr (cadr lei)))) (setq;|a42243|;
	 chk (if (>  kbd "") (if (wcmatch retc kbd) 1 0) 0)))))) (princ retc) 
retc)

 

How to work.You put 

(setq dyn (dfn_getx_readkey "[YN]" "\nCNavDialog(y.yes)(n.no): "))

(setq  YourPressHexKey (dfn_getx_readkey "[ABCDEFG]" "\nPomenirea Arhiepiscopului Pimen, la 1 an de la trecerea la cele veșniceA.10)(B.11)(C11: "))

0 Likes
Message 6 of 21

CodeDing
Advisor
Advisor

@diagodose2009 ,

 

I do not believe your function addresses my original question.

 

Best,

~DD

0 Likes
Message 7 of 21

CodeDing
Advisor
Advisor

@steve_carson ,

 

Here's a simple example of when this might be applied. If I create a function called (getfives ...) where the user should only enter a multiple of five. I could add this to a utility lisp that I always load, therefore when I'm programming I know that I can call this function whenever AND just call the (initget..) to suit my desire each time I use my custom function...

(defun getfives (str / bits keywords helpStr invalid i)
  ;(setq bits ???)
  ;(setq keywords ???)
  (setq helpStr "")
  (setq invalid t)
  (while (and invalid
              (setq i (getint (strcat helpStr str)))
         );and
    (if (setq invalid (not (zerop (rem i 5))))
      (progn
        (setq helpStr "\nNumber must be multiple of 5. ")
        ;(initget bits keywords)
      );progn
    );if
  );while
  i
);defun

Now, the problem is, that let's say for this case I only want the user to enter POSITIVE values of five. I would accomplish that like so:

(initget 6)
(getfives "\nEnter positive mulitple of five: ")

But, since I cannot read the initial (initget) values, if the user ultimately enters something like.. 4 ... then ... -5 ... the function would allow this input, when that was not the original intent.

 

And, YES there would be other ways to accomplish a "getfive" function, but the principle remains, and inside other custom (getxxx) functions it would be beneficial to access the original (initget) values.

 

Best,

~DD

 

0 Likes
Message 8 of 21

john.uhden
Mentor
Mentor
@CodeDing,
Can you make me a (getwinninglotteynumbers) function?
(while (not filthy_rich)
(setq filthy_rich (getwinninglotterynumbers "NJ"))
)

John F. Uhden

0 Likes
Message 9 of 21

ВeekeeCZ
Consultant
Consultant

It seems to me like your own getxxx functions would only work with your own initget. And is it so bad?!

 
0 Likes
Message 10 of 21

CodeDing
Advisor
Advisor

@john.uhden ,

 

Why duplicate work?

 

@ВeekeeCZ ,

 

Yes, my problem could be addressed or solved via other methods. I was just hoping to keep it as clean as possible.

If not possible, I might go with something like:

(getxxx '(initget 6 "Some Keywords") "\nMy prompt: ")

Then I can just evaluate it when necessary.

 

Best,

~DD

0 Likes
Message 11 of 21

john.uhden
Mentor
Mentor

No, you can't.

From the help...

"The initget bit values and keywords apply only to the next user-input function call."

John F. Uhden

0 Likes
Message 12 of 21

john.uhden
Mentor
Mentor

@CodeDing 

Um, plus you need to add the conditions of a user entering a non-numeric string, or a list, or a reference (unless you want to enable that, as in (eval (read "!p")).

John F. Uhden

0 Likes
Message 13 of 21

CodeDing
Advisor
Advisor

@john.uhden ,

 

If you're referring to me passing (initget) into a custom (getxxx) function, it should be pretty easy to detect:

(getxxx '(initget 6 "Key Words") "\nMy prompt: ")
.....
(defun getxxx (x y / )
  (if (and (listp x)
           (eq 'INITGET (car x)))
    (eval x)
.....

Best,

~DD

0 Likes
Message 14 of 21

john.uhden
Mentor
Mentor
I wasn't clear enough.
If you're planning to use an AutoCAD getxx function inside your custom
getxxx function, you may be shorting yourself. Only specified keywords are
permitted in getnum functions. I have recently found that using getstring
for numeric input works just fine (when you know how to handle it). I am
implying that you might not need any Autodesk getxx functions at all,
except for getstring, so to hell with initget.

John F. Uhden

0 Likes
Message 15 of 21

CodeDing
Advisor
Advisor

@john.uhden ,

 

I have a (getlong) function that would be the PERFECT candidate for this to work on, since the current (getint) only allows for Short Signed integers. Otherwise, it would be a pain in the bum to get working as expected without (initget).. (including keywords which (getint) allows).

(defun getlong (str / bits keywords helpStr valid tmp n)
  ;(setq bits ???)
  ;(setq keywords ???)
  (setq helpStr "")
  (while (and (not valid)
              (setq n (getreal (strcat helpStr str)))
         );and
    (setq valid
      (cond
        ((eq 'STR (type n)))
        ((= (setq tmp n) (setq n (atoi (rtos n 2 0)))))
        (t
          (setq helpStr "\nRequires a long integer value. ")
          nil ;(initget bits keywords)
        )
      );cond
    );setq
  );while
  n
);defun

 

Best,

~DD

0 Likes
Message 16 of 21

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:
.... Only specified keywords are permitted in getnum functions. ....

... unless you include the 128 bit in the (initget) bits argument, to allow arbitrary input.  Then you can enter any string you want, and you can enter a decimal number in response to (getint) [which it will accept, but as a text string].

 

I admit I'm not comprehending all of this very well [I hadn't heard of "short" and "long" integers before], but does that get you anything of what you're after?

Kent Cooper, AIA
0 Likes
Message 17 of 21

john.uhden
Mentor
Mentor

How about this?

(defun getlong (input / str n)
  (while (not n)
    (setq str (getstring input)
          n (read str)
    )
    (if (/= (type n) 'INT)
      (setq n (prompt "\n  Invalid input."))
    )
  )
  n
)
;; BTW, since around 2007, "Autolisp now uses a long integer format for integers thereby eliminating the 32,768 plus or minus limitation."

John F. Uhden

0 Likes
Message 18 of 21

CodeDing
Advisor
Advisor

@Kent1Cooper  & @john.uhden ,

 

While those are useful tools and good examples, the primary question of this post still remains, whether or not we can access these values after they have been set. I do not want to deviate too far away from that question. I was merely providing scenarios where knowing these values would be beneficial in a program.

 

Also John, while AutoLISP has updated to the Long integer format, the (getint ...) function still only accepts Short integers. As seen in the documentation.

 

Best,

~DD

0 Likes
Message 19 of 21

Kent1Cooper
Consultant
Consultant

@CodeDing wrote:

....

So, for example, if I set initget somewhere in my code...

(initget 6 "Some Keywords")

... then I could read these values somehow..

Command: (setq bits (getvar '??????))
6
Command: (setq keywords (getvar '??????))
"Some Keywords"

....


Why not just do the same in the other order?  If you're going to have the bits and keywords as variables, can you save them that way before (initget), rather than using (initget) and afterwards setting those as variables pulled from it?

 

(setq bits (getint))

(setq keywords (getstring))

(initget bits keywords)

(...whatever function uses that...)

Kent Cooper, AIA
0 Likes
Message 20 of 21

CodeDing
Advisor
Advisor

@Kent1Cooper ,

 

The goal is to save the programmer using the function some heartache. I'm trying to maintain as CLOSE to the normal workflow as possible.

 

For example,

If I gave you this piece of code, you could easily dissect what it does and why it is formatted this way:

(initget 6 "Dogs Cats")
(getint "\nEnter Number or [Dogs/Cats]: ")

Likewise, I am trying to accomplish the same:

(initget 6 "Dogs Cats")
(getlong "\nEnter Number or [Dogs/Cats]: ")

 

I do understand that there are other approaches such as..

Global Vars:

(setq *bits* 6)
(setq *keywords* "Dogs Cats")
(initget *bits* *keywords*)
(getlong "\nEnter Number or [Dogs/Cats]: ")

Passing unevaluated functions:

(getlong '(initget 6 "Dogs Cats") "\nEnter Number or [Dogs/Cats]: ")

Passing initget values as parameters:

(getlong 6 "Cats Dogs" "\nEnter Number or [Dogs/Cats]: ")

...etc.

 

...But they Just.. Aren't.. the Same..

Best,

~DD

 

0 Likes