(getvar 'NextToLastPrompt)

(getvar 'NextToLastPrompt)

Kent1Cooper
Consultant Consultant
1,776 Views
7 Replies
Message 1 of 8

(getvar 'NextToLastPrompt)

Kent1Cooper
Consultant
Consultant

I'm trying to get the last prompt of options in a PLINE command from the [aptly-named, or I used to think so] LASTPROMPT System Variable.  But it seems to return the Next-To-Last  prompt instead.  To see what I mean, put this into the Command line:

(progn (command "_.pline" pause pause) (setq test (getvar 'lastprompt)) (command ""))

 

That starts a PLINE command; just pick two points for one line segment.  It leaves the Pline command running, and saves the last prompt into the 'test' variable before ending the command.  So:


_.pline
Specify start point: {first pause -- pick a point}
Current line-width is 0'-0"
Specify next point or [Arc/Halfwidth/Length/Undo/Width]: {second pause -- pick a point}

{after which pick, the following shows at the Command line:}
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:

{and the LASTPROMPT value is saved to 'test', then the code ends the Pline command}
Command: nil {returned by concluding (command) function}

 

Now, what's in the 'test' variable?

 

Command: !test
"Specify next point or [Arc/Halfwidth/Length/Undo/Width]:"

 

That's the previous  prompt, at the time of the second pause, not  the current or latest prompt at the point in the command at which LASTPROMPT was saved.  The latter is what I want to get [specifically, to see the difference that it now has the Close option within it].

 

Help for LASTPROMPT says:

This string is identical to the last line seen at the Command prompt and includes any user input.

I suppose that last part means it takes the last prompt which was acted on by the User.  I had always thought it was the latest  prompt appearing at the Command line [isn't that what "last line seen" should mean?], i.e., if in mid-command at the time like this, the current  prompt.  But apparently that's not the case -- effectively, it seems to operate as though it's really the Subject line of this thread.  [No, that Subject is not  what I want  to do, but a description of what (getvar 'lastprompt) seems to actually  be doing, at least in this particular mid-command circumstance.]

 

Does anyone know of a way to extract the latest/current prompt in this situation?  If not, how about some other way of determining that a second point has been designated in PLINE [i.e. a first segment has been defined]?  I'm trying to limit a Polyline to one segment, but I can't just use two pauses as in the example, because I want to allow for options  first, such as changing the Width or going into Arc mode.  The Close [or when in Arc mode, 2-capitals CLose] option doesn't appear in the main prompt or option sub-prompts until a first segment has been drawn, which is why I was looking to that content in the prompt as the "clue" to proceed to what I want to do next, only after the first segment has been completed.

Kent Cooper, AIA
0 Likes
Accepted solutions (2)
1,777 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

Hm... well, it works little bit different than I used before...

 

The way as you have your code right now will your test variable capture "pre-last" prompt including the user option at the end:

Command: (progn (command "_.pline" pause pause) (setq test (getvar 'lastprompt)) (command pause))
_.pline
Specify start point:
Current line-width is 0.0000
Specify next point or [Arc/Halfwidth/Length/Undo/Width]: l
Specify length of line: 10
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]: nil
Specify next point or [Arc/Close/Halfwidth/Length/Undo/Width]:
Command: !test
"Specify next point or [Arc/Halfwidth/Length/Undo/Width]: l"

 

But more reliable for your purpose seems to be to check a definition of actual last entity:

(defun c:test ()
  (princ "Before:")
  (print (entlast))
  (command "_.pline")
  (while (> (getvar 'cmdactive) 0)
    (print (entlast))
    (princ (strcat "-Len: " (itoa (length (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))))
    (command pause)))

Edit: sorry, experiencing redesign formatting issue (= no format at all until edited)

0 Likes
Message 3 of 8

CodeDing
Advisor
Advisor
Accepted solution

Kent, I believe it technically is returning the last string echoed to the command prompt.. This is more evident when your command bar is minimized (Image 1).

 

It appears with your code it is never ECHOED to the USER. You will need to add another pause so it can be echoed to the user, or rearrange your code to until after your command to return as expected:

>>>(progn (command "_.pline" pause pause pause) (setq test (getvar 'lastprompt)) (command ""))<<<

>>>(progn (command "_.pline" pause pause) (command "") (setq test (getvar 'lastprompt)))<<<

 

...I cannot elaborate more as to why it will not accept the string as displayed in the command history since clearly it gets passed to the history at some point. Must be happening AFTER the command is finished.

 

After a little more messing around I got it to work when you introduce a new (terpri) command. I was experimenting with prompting the variable instead of storing (setq) it:

WORKS: (progn (command "_.pline" pause pause) (terpri) (prompt (getvar 'lastprompt)) (command ""))

WORKS: (progn (command "_.pline" pause pause) (terpri) (setq test (getvar 'lastprompt)) (command ""))

 

...perhaps that can help get you on track?

 

Best,

~DD

**EDITED SINCE COMMENT FORMATTING WAS WHACK VIA THE SITE**

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

@CodeDing wrote:

WORKS: (progn (command "_.pline" pause pause) (terpri) (setq test (getvar 'lastprompt)) (command ""))

 

This has little side effect. In case you want to continue in the command you can't select any option by pick (the options aren't blue anymore):

image.png

 

And for sure it isn't that smooth as when I used this in C3D where I could catch the prompt line currently on, like in HERE

 

Anyway, testing (entlast) works nice:

(defun c:test ()
  (setq enl (entlast))
  (command "_.pline")
  (while (> (getvar 'cmdactive) 0)
    (if (and (not (equal enl (entlast)))
             (= 2 (cdr (assoc 90 (entget (entlast)))))
             )
      (command "")
      (command PAUSE)))
  )

 

Message 5 of 8

Kent1Cooper
Consultant
Consultant

Thanks to both @ВeekeeCZ and @CodeDing -- (terpri) is the current answer, and @ВeekeeCZ's suggestions may soon be incorporated and also become a Solution.  The result is >>here<<.

Kent Cooper, AIA
0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

.... check a definition of actual last entity:

(defun c:test ()
  (princ "Before:")
  (print (entlast))
  (command "_.pline")
  (while (> (getvar 'cmdactive) 0)
    (print (entlast))
    (princ (strcat "-Len: " (itoa (length (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast)))))))
    (command pause)))

....


That looks very promising -- I wouldn't have thought (entlast) would register as the currently-being-drawn  Polyline while underway, but it looks like it does.  So far, I've used the (terpri) approach suggested by @CodeDing, but I will experiment with this further, and with incorporation of it into the rest of the routine, and update it if it all works out.  By the way, the (terpri) approach does  allow picking on options in the prompt at some  points in the Pline command, but not all, so if this approach overcomes that, I'll incorporate it.

[I had marked that Post as a Solution, but "demoted" it while (terpri) is the incorporated approach, but will mark it again if this all works out.]

Kent Cooper, AIA
Message 7 of 8

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

.... 

Anyway, testing (entlast) works nice:

.... 


That unexpected [to me] notion that a Polyline in process of being drawn  "qualifies" as (entlast) was key to greatly simplifying the routine [see the other thread], though I used it in a different way [but I've marked the suggestion as a Solution anyway, because I wouldn't have gotten to that different way without it].

 

The routine limits a Polyline to a maximum length.  It was  building it in single segments, and joining them together as it went along, so as to test the length of the cumulative result against the specified maximum after each segment with a newly-made (entlast) object, because I had assumed the object needed to be completed  before information could be extracted out of it.  This thread started about recognizing whether the first segment had been completed, while still allowing options, by the wording of the PLINE prompt.

 

But since the routine can, with this new notion, pull information about the Polyline along the way, it can read the length it's gotten up to after each segment, through multiple segments, while remaining in the same Polyline command.

 

So it doesn't check for number of vertices and stop when it reaches two of them as in the suggestion, for single segments to be joined, but rather checks the length as it goes along.  That eliminates not only the stepping in and out of separate PLINE commands, but also the PEDIT/Join part, so the whole thing got much simpler.

 

Thanks again,

Kent Cooper, AIA
0 Likes
Message 8 of 8

aaronlance
Contributor
Contributor

This is an old post, but it led me to a solution to a similar problem.

 

For this particular issue, I added a newline before getting LastPrompt.
(progn (command "_.pline" pause pause) (princ "\n" ) (setq test (getvar 'lastprompt)) (command ""))

 

My use was for the MLEADER command, so I could check for the arrowHead option before using it:

(initcommandversion 1)

(command "_.MLEADER")

(princ "\n" ) (if (wcmatch "*arrowHead* (getvar 'lastprompt)) (command "_Head"))

(command pnta) ; Input the arrowhead point
(while (> 0 (logand 1 (getvar "CMDACTIVE")) (command pause))

 

Without the check, users frequently see an invalid command option (even with cmdecho 0), if the arrowHead mode was the last one used.

 

In the end, abusing the command prompt this way was an abomination and I switched to addMleader, but maybe the technique will address other problems.

0 Likes