Author Topic: choice for input type  (Read 5794 times)

0 Members and 1 Guest are viewing this topic.

curmudgeon

  • Newt
  • Posts: 194
choice for input type
« on: August 02, 2011, 10:39:04 AM »
just outside my experience, bet this one is a chestnut.

I have my own leader routine that sets lst_txt to be a variable so that when I repeat a note, the last text I used is the default, and I don't have to retype it. I also have a simple routine that picks a text entity already in the drawing and matches the text portion of selected entities.

I want to select a piece of text on screen and force that to the default text variable.

I could just make a new routine that picks that text, and then executes the leader routine.
But that would be ugly. I think I should be able, at the point when I can choose to enter new text or accept the default that I should be able to use a mouse button to pick with.

Code: [Select]
(setq str   (strcase (getstring T  (strcat "Text <" (eval lst_txt) ">  :"))))
Maybe I need to make a dialog box and select the method for what text to use there.
Any bright ideas?
Never express yourself more clearly than you are able to think.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: choice for input type
« Reply #1 on: August 02, 2011, 10:46:18 AM »
Does this help?

EDIT: Or maybe I have misunderstood, perhaps something like:

Code: [Select]
(if (not *myglobal*) (setq *myglobal* "Default"))

(setq tmp (getstring t (strcat "\nSpecify Text <" *myglobal* ">: ")))
(if (eq "" tmp)
    (setq tmp *myglobal*)
    (setq *myglobal* tmp)
)

JohnK

  • Administrator
  • Seagull
  • Posts: 10659
Re: choice for input type
« Reply #2 on: August 02, 2011, 10:56:31 AM »
A few of us back on another forum we used to frequent called this the ``RRB (R. Robert Bell) Default Method'' (the second EX was my contribution; derived from Paul Graham's Hygienic Variable statement).

Examples:
Code: [Select]
(cond
   (flag)
   (7) )

Code: [Select]
(setq i (cond (i (1+ i)) (0)))
Code: [Select]
(initget 0 "Length Width Depth Time")
(setq Inp
      (cond
        ( (getkword "\nSpecify a dimension [Length/Width/Depth/Time] <Time>: ") )
                ("Time")) )

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

curmudgeon

  • Newt
  • Posts: 194
Re: choice for input type
« Reply #3 on: August 02, 2011, 11:02:07 AM »
You used asterisks (*) and I used (eval) - but I am thinking they do the same thing.
I was not being clear, I am sure.

The routine already gives me a choice between the last text I used, and typing new text.
What I am wishing for is at that point to be able with (maybe) a mouse click to select an entity instead of typing or not typing.
And the logic of that may have faulty premise.

What I am quite certain I lack is how autocad handles return codes from mouse clicks. I am being unclear again.
I want a command that will work like (OR (entsel) (getstring)).

If that is making sense, you are very good at understanding.

@ Se7en - you posted whilst I was typing. I think you gave me a good answer, which is a little deep for me, and I will have to gnaw on it for a while. But thank you.
Never express yourself more clearly than you are able to think.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: choice for input type
« Reply #4 on: August 02, 2011, 11:09:11 AM »
« Last Edit: August 02, 2011, 11:12:29 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10659
Re: choice for input type
« Reply #5 on: August 02, 2011, 11:20:15 AM »
You used asterisks (*) and I used (eval) - but I am thinking they do the same thing.
I was not being clear, I am sure.

The routine already gives me a choice between the last text I used, and typing new text.
What I am wishing for is at that point to be able with (maybe) a mouse click to select an entity instead of typing or not typing.
And the logic of that may have faulty premise.

What I am quite certain I lack is how autocad handles return codes from mouse clicks. I am being unclear again.
I want a command that will work like (OR (entsel) (getstring)).

If that is making sense, you are very good at understanding.

@ Se7en - you posted whilst I was typing. I think you gave me a good answer, which is a little deep for me, and I will have to gnaw on it for a while. But thank you.

I apologize for being `deep'. I'm not sure I understand how it would be; can you explain or give me a chance to explain further?
At any rate, please look again at the third example I gave.

Can you also explain why you wrapped a Boolean function (OR) with two functions that return a value (that statement will only return TRUE or FALSE, never a value--that statement doesn't make sense to me)?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: choice for input type
« Reply #6 on: August 02, 2011, 11:21:44 AM »
You used asterisks (*) and I used (eval) - but I am thinking they do the same thing.

I used asterisks to both indicate the variable was global and also give this global variable a more unique name. The code would work identically without the use of asterisks.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: choice for input type
« Reply #7 on: August 02, 2011, 11:27:46 AM »
Maybe this:
Ops wrong link, back in a minute.

OK try this link
http://www.google.com/search?q=%22getpoint_or_text%22+site%3Atheswamp.org&hl=en&num=10&lr=&ft=i&cr=&safe=images&tbs=

Cab, that is an interesting way of searching TheSwamp muck.  I like it and have to remember that.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

curmudgeon

  • Newt
  • Posts: 194
Re: choice for input type
« Reply #8 on: August 02, 2011, 12:13:46 PM »
I think I have it - I was maybe overthinking it.

Code: [Select]
(if
(setq ent (entsel "\n Select text to match :"))
(setq str (car (assoc 1 ent)))
(setq str (strcase (getstring T  (strcat "Text <" (eval lst_txt) ">  :")))
)

typing in the edit box instead of Vlisp, typos very possible.

if entsel finds something, I use that for the text for the leader, and if it fails I go back to the default or typing new text.
thanks guys.

Never express yourself more clearly than you are able to think.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: choice for input type
« Reply #9 on: August 02, 2011, 03:53:54 PM »
Some food for thought, I believe this is something along the lines of what CAB was suggesting in his earlier post:

Code: [Select]
(defun LM:SelectionOrText ( msg filter / g1 g2 gr res ss ) (princ msg) (setq res "")
    (while
        (progn
            (setq gr (grread nil 14 2)
                  g1 (car  gr)
                  g2 (cadr gr)
            )
            (cond
                (   (= 3 g1)
                    (if (ssget g2)
                        (if (setq ss (ssget g2 filter))
                            (progn (setq res (ssname ss 0)) nil)
                            (princ (strcat "\nInvalid Object Selected." msg))
                        )
                        (princ (strcat "\nMissed, Try Again." msg))
                    )
                )
                (   (= 2 g1)
                    (cond
                        (   (<= 32 g2 126)
                            (setq res (strcat res (princ (chr g2))))
                        )
                        (   (= 13 g2)
                            nil
                        )
                        (   (and (= 8 g2) (< 0 (strlen res)))
                            (setq res (substr res 1 (1- (strlen res))))
                            (princ (vl-list->string '(8 32 8)))
                        )
                        (   t   )
                    )
                )
                (   (= 25 g1)
                    nil
                )
                (   t   )
            )
        )
    )
    res
)

Example:

Code: [Select]
(LM:SelectionOrText "\nSelect a Line: " '((0 . "LINE")))
User can either select a Line entity, or enter an arbitrary text string.

Function will return selected entity, or entered string (may be empty).

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: choice for input type
« Reply #10 on: August 04, 2011, 09:53:55 AM »
That's exactly what I was suggesting. Nice code Lee.  8-)

The Google search is often better than the one here.  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: choice for input type
« Reply #11 on: August 04, 2011, 09:55:16 AM »
Cheers Alan  :-)