CMDACTIVE and using MTEXT

CMDACTIVE and using MTEXT

CADaSchtroumpf
Advisor Advisor
892 Views
12 Replies
Message 1 of 13

CMDACTIVE and using MTEXT

CADaSchtroumpf
Advisor
Advisor

No more response from Autocad when using this little piece of code.
For my part, I think that the MTEXT editor is not managed by the CDMACTIVE variable.
How to circumvent this problem while preserving the principle?

 

Be careful before using this piece of code, you will have to kill the task.

((lambda ( / )
  (command "_.mtext")
  (while (not (zerop (getvar "CMDACTIVE")))
    (command pause)
  )
))

 

0 Likes
Accepted solutions (2)
893 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@CADaSchtroumpf wrote:

... I think that the MTEXT editor is not managed by the CDMACTIVE variable....


Do you want it to be?  If I set CMDACTIVE to 0, and do (command "_.mtext"), it asks for a box, but then takes content input only at the Command line, not as editing box on-screen, so the CMDACTIVE setting does make a difference.  If I establish points for the box ahead of time in variables, I can feed those into the command so I don't have to specify the box on-screen within it, and it goes right into taking content at the Command line.

 

Are you wanting it to work with the editing box on-screen even when CMDACTIVE is 0?  If so, preceding it with (initdia) works for me.  If not, what are you looking for, operationally?

 

[Why (lambda)?]

Kent Cooper, AIA
Message 3 of 13

ВeekeeCZ
Consultant
Consultant

I have this approach marked "Mtext - best dynamic solution for 2015+" in my archive... so hopefully it will suit you...

 

(defun c:MtextLisp nil
  (command "_.MTEXT" pause pause "Text" "")
  (setpropertyvalue (entlast) "Contents" "")
  (command "_.mtedit" "_last")
  (command "line" pause pause "") ;; test line
  (princ)
)

 

0 Likes
Message 4 of 13

CADaSchtroumpf
Advisor
Advisor

@Kent1Cooper 

Thank Kent,

Indeed (initdia) solved my problem.




@CADaSchtroumpf  a écrit :
what are you looking for, operationally?

 


Is for this, see the tempolary lisp code.

But now I also have a problem with the TEXT command which registers the pause symbol for me as a text value

 

0 Likes
Message 5 of 13

CADaSchtroumpf
Advisor
Advisor

Thanks BeekeeCZ, but my need is to use CMDACTIVE

0 Likes
Message 6 of 13

Kent1Cooper
Consultant
Consultant

Instead of starting the command and then using the (while) function checking whether the command is still active, try this method of having it continue to wait for User input until the command is completed:

 

(initdia)
(command-s "_.mtext")

Kent Cooper, AIA
0 Likes
Message 7 of 13

john.kaulB9QW2
Advocate
Advocate
Accepted solution

I use CAB's verion as a template in my shorty/helper thing that does text stuff. https://www.theswamp.org/index.php?topic=47305.msg523441#msg523441

 

Kent1Cooper,
The "((lambda ( / ) ... " Is a way/method to post an auto-running-example -i.e. "here is some code you can copy-paste to run a simple example". At least, that is how I do it so new users don't have to type anything to run a quick example I post.

another swamper
Message 8 of 13

Kent1Cooper
Consultant
Consultant

@john.kaulB9QW2 wrote:

.... The "((lambda ( / ) ... " Is a way/method to post an auto-running-example ....


It works just the same without the ((lambda)) wrapper, for me [including, in this case, locking up AutoCAD].  Try it, with [for example] "_.line" instead of "_.mtext".

Kent Cooper, AIA
0 Likes
Message 9 of 13

john.kaulB9QW2
Advocate
Advocate

What I tried to say is this "can be simpler"

((lambda ( / )
  (command "_.line")
  ...))

than either of these two

(defun foo ( / )
  (command "_.line")
  ...)

(defun c:bar ( / )
  (comand "_.line")
  ...)

because all WE would have to do is copy and paste the first into the command line and it would run. The latter two require US to type either (FOO) or BAR in the command line to run. -i.e. the OP was being kind (polite) by offering a way for us to quickly(er) test their concept.

 

However, this

(
 (lambda (x y z) (+ x y z))
 1 2 3)

is called the LET CONSTRUCT. -i.e. in this form of LAMBDA, the 1 2 3 values are "assigned" to the X Y Z variables.

 

Also, after I took the SICP course using SCHEME, I developed a habit of typing my functions like this:

(defun baz ()
 ((lambda ()
   (command "_.line")
   ...)))

but that was just a quirk and only lasted a little bit.

 

...That concludes our discussion into lambda.

another swamper
0 Likes
Message 10 of 13

CADaSchtroumpf
Advisor
Advisor

@john.kaulB9QW2 

Many thanks John
CAB's solution for text is superb, I didn't know about this option:
(while (= (logand (getvar "cmdactive") 1) 1)
(command "\\acedpause")
)

0 Likes
Message 11 of 13

CADaSchtroumpf
Advisor
Advisor

@Kent1Cooper  a écrit :

[Why (lambda)?


@Kent1Cooper 

For (lambda) I used it for; as John said, that copy-paste in command line works correctly.
If you copy-paste only:
(command "_.mtext")
(while (not (zerop (getvar "CMDACTIVE")))
(command pause)
)
It does not work!
But actually I could have used for example a progn for the sequence to be done.
I use ((lambda...)) a lot when I know that the code in it will only be used once in the drawing or it is executed on the fly

0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant

@CADaSchtroumpf wrote:

....

If you copy-paste only:
(command "_.mtext")
(while (not (zerop (getvar "CMDACTIVE")))
(command pause)
)
It does not work!
....


It does not work with the ((lambda) wrapper around it, either [that's the whole reason for this topic], so what's the benefit?  In either case, I get to define the Mtext box, and then it locks up.  That's an "_.mtext"-specific issue, because of the pause being taken as if it were text input, instead of waiting for User input.  Try it with "_line" instead -- it works with or without the wrapper.

Kent Cooper, AIA
0 Likes
Message 13 of 13

john.kaulB9QW2
Advocate
Advocate
Kent1Cooper,
I have no idea why you are focusing so hard on the lambda-wrapper but you are missing the point behind its use in this context. You also edited the quote (and removed the most important words in the post -i.e. you simplified the quote removing important words).

CADaSchtroumpf,
I think the lambda-wrapper--in this context--is also a very good visual. Yes, a progn would work as well--for the general task of grouping a series of statements--but a lambda-wrapper is nice because you can generally localize variables in examples). Same rule (localize variables) goes for when executing single-use-code in a "startup-lisp thing".
another swamper
0 Likes