Promt keywords in ENTSEL

Promt keywords in ENTSEL

Browning_Zed
Advocate Advocate
1,526 Views
22 Replies
Message 1 of 23

Promt keywords in ENTSEL

Browning_Zed
Advocate
Advocate

Hi All,
Help me please. I cannot understand how keywords work in promt. I need to execute the ENTSEL function using keywords.

 

First, I put keywords in INITGET:
(initget "Type Form")

 

Then I need to execute the ENTSEL function:
(entsel "\nPick: [Type/Form]")

During the execution of the ENTSEL function, before the entity is picked, I can select keywords [Type/Form].

 

After that, I need to return two variables with set values:
1. Entsel value of the picked entity in one variable.
2. The value of the keyword: "Type" or "Form" in another variable.

 

How can i do this?

0 Likes
Accepted solutions (2)
1,527 Views
22 Replies
Replies (22)
Message 2 of 23

ВeekeeCZ
Consultant
Consultant
Accepted solution

Unless you don't want to have two prompts, you need to have one with a default option the will be applied if the user just pass the prompt.

 

 

(defun c:Test ( / ent tmp)

  (or *option*
      (setq *option* "Type"))

  (while (not ent)
    (initget "Type Form")
    (princ "\nCurrent setting: ") (princ *option*)
    (setq tmp (entsel (strcat "\nPick or [Type/Form] <" (if (= *option* "Type") "Form" "Type") ">: ")))
    (cond ((not tmp)    (setq *option* (if (= *option* "Type") "Form" "Type")))
	  ((listp tmp)	(setq ent (car tmp)))
	  (T 		(setq *option* tmp))))
  (list ent *option*))

 

Message 3 of 23

Browning_Zed
Advocate
Advocate

Thank you, this is what I need!
I'm also wondering what the code will be if there are more than two keywords, for example:
[Type/Form/Item/Build]

0 Likes
Message 4 of 23

ВeekeeCZ
Consultant
Consultant
(defun c:Test ( / ent tmp)

  (or *option*
      (setq *option* "Type"))

  (while (not ent)
    (initget 1 "Type Form Item Build")
    (princ (strcat "\nCurrent setting: " *option*))
    (setq tmp (entsel "\nSelect entity or pick [Type/Form/Item/Build]: "))
    (if (listp tmp)
      (setq ent (car tmp))
      (setq *option* tmp)))
  (list ent *option*))
Message 5 of 23

Browning_Zed
Advocate
Advocate

Thanks for the help.

0 Likes
Message 6 of 23

ВeekeeCZ
Consultant
Consultant

Do you understand the code or do you need to add some comments?

0 Likes
Message 7 of 23

Browning_Zed
Advocate
Advocate

Thank you, the code is clear. One question: *option* variable set as global just to remember the last state of the keyword? Or is the global status of this variable needed for something else?

0 Likes
Message 8 of 23

ВeekeeCZ
Consultant
Consultant

Yes, just to remember the last one. Make it local if you want to have the default option always the same.

Message 9 of 23

Browning_Zed
Advocate
Advocate

Thanks!

0 Likes
Message 10 of 23

Browning_Zed
Advocate
Advocate

Can you help me a little more?
What if, when I select one of the options, I don't need to set it to a variable, but just run a specific action. I will explain:
(or *option* (setq *option* "Type")) ; set variable *option* to "Type"
(setq tmp (entsel "\nSelect entity or pick [Type/Form/Delete]: "))
here if selecting "Form", then this will set the variable *option* to "Form". But if selecting "Delete", then execute expression (entdel (entlast)), and leave the variable *option* with the same status, that is, do not change the value of this variable. The loop is not interrupted during the execution (entdel (entlast)).

0 Likes
Message 11 of 23

ВeekeeCZ
Consultant
Consultant

Then get back to the cond func and add one more condition... do you understand how cond works and where and why to put it?

0 Likes
Message 12 of 23

Browning_Zed
Advocate
Advocate

I understand how the cond works, but I do not understand how it can be put into this code.

0 Likes
Message 13 of 23

ВeekeeCZ
Consultant
Consultant
Accepted solution

Then tell me, how does the cond work? 

 

(defun c:Test ( / ent tmp)

  (or *option*
      (setq *option* "Type"))

  (while (not ent)
    (initget 1 " Type Form Delete")
    (princ "\nCurrent setting: ") (princ *option*)
    (setq tmp (entsel (strcat "\nPick or [Type/Form/Delete]: ")))
    (cond ((listp tmp)		(setq ent (car tmp)))
	  ((= tmp "Delete")	(entdel (entlast)))
	  (T 			(setq *option* tmp))))
  (list ent *option*))

 

Message 14 of 23

Browning_Zed
Advocate
Advocate

Thank you so much! Now I understand.

0 Likes
Message 15 of 23

ВeekeeCZ
Consultant
Consultant

Ok, good. Just tell me why it could not be the last condition.

0 Likes
Message 16 of 23

Browning_Zed
Advocate
Advocate

Because the last condition is to exit the loop?

0 Likes
Message 17 of 23

ВeekeeCZ
Consultant
Consultant

As matter of fact, in this case, is the first one responsible for exit if is true.

0 Likes
Message 18 of 23

Browning_Zed
Advocate
Advocate

Yes it is. Then I don't understand what T means in the expression (T (setq * option * tmp))

0 Likes
Message 19 of 23

ВeekeeCZ
Consultant
Consultant

Here is something to help you understand the cond.

 

; universally
(cond (test1		result1)
      (test2 		result2)
      (test3 		result3)
      (test4)
      (test5 		result5)
      )


(cond ((= tmp "Delete")       	(princ "It's Delete!")) 			; if tmp is "Delete",  test1 is T and result1 is taken and OVER - the cond returns the value if result1 (prints "It's Delete!"). Other conditions (like test2) are not even tested! 
      
      (tmp 			(princ "It's something else than Delete!"))     ; if tmp is some value (its not nothing but neither "Delete". Because if it was "Delete", it would have already been taken.). so if tmp was "Item", the cond returns "It's something else than Delete!" and over.

      ((and tmp T) 		(princ "I do understand the cond!"))		; can cond, in this example, ever return this line? 
    
      ((not tmp))		   						; if there is no result, the cond returns value of test itself! So when this line will be taken and what the result would be?

      (T 			(princ "Nothing is True"))			; T as True is test5 expression. But it's always True.... if non of previous tests were is taken. Can cond, in this case, ever return this line?
Message 20 of 23

ВeekeeCZ
Consultant
Consultant

@Browning_Zed wrote:

Yes it is. Then I don't understand what T means in the expression (T (setq * option * tmp))


*option* is one word! No spaces. Btw asterisks are just letters with no special functionality. Just convention.

it could also be +option+ for example... or goptiong It would work the same.

 
0 Likes