Rotate, Radians - Select & have to press 2xEnter not 1x

Rotate, Radians - Select & have to press 2xEnter not 1x

Anonymous
Not applicable
739 Views
4 Replies
Message 1 of 5

Rotate, Radians - Select & have to press 2xEnter not 1x

Anonymous
Not applicable

Hello,

I made lisp for rotating about an angle given by some number of PI

 

(DEFUN C:RTRAD
 (/ NumberOfRadians AngRad AngDeg)
 (setq zbior (ssget))
 (COMMAND "_ROTATE"
  ;Select objects:
   zbior ""
  ;Specify base point:
   pause
 )
 ;Specify rotation angle or [Copy/Reference] <270>:
 (setq NumberOfRadians (getreal "\nSpecify number of PI: "))
 (setq AngRad (* NumberOfRadians PI))
 (setq AngDeg (* (/ 180 PI) AngRad))
 (COMMAND AngDeg)
)

 Great thanks to Kent1Cooper, who show me that you can ask the user for data not only before you run command, but also when it is running.

(I mean this situatiion: http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/draw-line-under-angle-work-bad-bad-an...

Thank to your advice, I did this lisp. Thank you.

 

But I have one prolem with this command. I see at it and I can't find where the error could be.

What is this error? When you run RTRAD, Enter, then you are asked to select objects to rotate. You select, Enter, and... And nothing,

You press Enter seconf time, and now you are asked for picking BasePoint.

My question is: Why is this in hat way? What causes it? And how can I repair it?

0 Likes
740 Views
4 Replies
Replies (4)
Message 2 of 5

Lee_Mac
Advisor
Advisor

Note that your code prompts the user to make a selection of objects and issues the selection to the ROTATE command; the ROTATE command then prompts the user to specify a base point (this is the prompt issued at the 'pause' in the code); if the user responds with a valid base point, the code will proceed to prompt for a rotation angle via the getreal function, however, if the user fails to specify the base point, the getreal function will still be evaluated and will attempt to submit a single numerical value (or nil) to the ROTATE command at the base point prompt (which has yet to be satisfied).

 

To overcome this, you need to check that the user has responded with valid data before continuing evaluation of the program - this can be achieved in a number of ways, one way is to use an if statement to validate the user input before invoking the command:

 

(defun c:rtrad ( / bpt mlt sel ) ;; Define function & declare local variables
    (if ;; If the following expressions return a non-nil value
        (and ;; All of the enclosed expressions must return a non-nil value for AND to return T
            (setq sel (ssget "_:L")) ;; Prompt for a selection of objects on unlocked layers
            (setq bpt (getpoint "\nSpecify base point: ")) ;; Prompt for a base point
            (setq mlt (getreal "\nSpecify number of PI: ")) ;; Prompt for a multiple of pi radians
        ) ;; end AND
        ;; The following is the 'then' argument for the IF function:
        (command
            "_.rotate"
            sel "" ;; Submit the selection of objects
            "_non" ;; Command modifier to ignore any active Object Snap modes
            bpt    ;; Submit the UCS base point
            (* 180.0 mlt) ;; Submit the multiple of pi radians (i.e. multiple of 180 degrees)
        ) ;; end COMMAND
        ;; If we required an 'else' argument, it would go here
    ) ;; end IF
    (princ) ;; Suppress the return of the last evaluated expression
) ;; end DEFUN

 

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... When you run RTRAD, Enter, then you are asked to select objects to rotate. You select, Enter, and... And nothing,

You press Enter seconf time, and now you are asked for picking BasePoint.

My question is: Why is this in hat way? What causes it? And how can I repair it?


I don't see anything obvious to cause that.  Is command echoing turned on [CMDECHO System Variable]?  If it were not, it might explain the "nothing" if it's waiting without displaying the prompt, but I assume it is on, if it later asks for a base point, since that prompt must be coming from the command, not being in the code.  Do you see the Rotate command start?  What's at the Command: line when "nothing" is happening?  Is the Rotate command perhaps redefined in some way that might cause the problem?  If it might be, try it with the period/decimal-point prefix to force it to use the native command definition:

 

(command "_.rotate")

 

By the way, you can avoid the calculations at the end, and eliminate the variables used for them.  There's a handy (angtos) function that will turn an angle in radians directly into a string [in whatever angle settings are current] appropriate to answer the rotation prompt in a Rotate command:

 

(DEFUN C:RTRAD
   (/ zbior)
   (setq zbior (ssget))
   (COMMAND

     "_.ROTATE" zbior "" pause

     (angtos (getreal "\nSpecify number of PI: "))
   ); command

); defun

Kent Cooper, AIA
0 Likes
Message 4 of 5

Anonymous
Not applicable

Thank both of you.

 

Lee Mac, your lisp works well.

Kent1Cooper, I don't know why, but your lisp gives bad angle of rotation. What could be wrong?

0 Likes
Message 5 of 5

Lee_Mac
Advisor
Advisor

You're most welcome damian, happy to help Smiley Happy

0 Likes