Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

hard return in lisp

8 REPLIES 8
Reply
Message 1 of 9
chrisdavis5201
798 Views, 8 Replies

hard return in lisp

OK, I have searched for this answer and tried various different options and none seem to work. I am trying to insert a hard return at the end of my code to end a command. I am creating very basic lisp routines that are 2 keystroke commands. This one is to lock all viewports

 

(defun c:V1 ()
 (command "-vports" "L" "ON" "ALL" "#\newline")
 (princ)
)

 

The problem I am having is finishing the command. If i were to type the steps out i would just hit enter at the end and be done. I cannot figure out what to put at the end of the code (shown above in red) to have autocad register a hard return and finish the command. I have tried the following:

 

""

" "

"\"

"\r"

"#\r"

"#\return"

 

I am sure this is a simple solution, but I have not run across it. I am very basic when it comes to programming, hence the simple lisp.

 

Thanks,

Chris M. Davis

 

Oh, also I would appreciate some feedback as to a good book to pick up to start learning Lisp and DCL.

 

 

8 REPLIES 8
Message 2 of 9
p_mcknight
in reply to: chrisdavis5201

(command "-vports" "L" "ON" "ALL" " ")

Remember, in autocad the space bar is a return.

 

Message 3 of 9
chrisdavis5201
in reply to: p_mcknight

Thank you!! see something simple...

Message 4 of 9


@chrisdavis5201 wrote:

.... I am trying to insert a hard return at the end of my code to end a command. I am creating very basic lisp routines that are 2 keystroke commands. This one is to lock all viewports

 

(defun c:V1 ()
 (command "-vports" "L" "ON" "ALL" "#\newline")
 (princ)
)

 

.... I cannot figure out what to put at the end of the code (shown above in red) to have autocad register a hard return and finish the command. I have tried the following:

 

""

....


A double double-quote is the standard for Enter in Lisp expressions, and using it in your line of code works for me:
(command "-vports" "L" "ON" "ALL" "")

 

If it doesn't work for you, what happens instead?  Is there any kind of message?

Kent Cooper, AIA
Message 5 of 9
bhull1985
in reply to: Kent1Cooper

Does this work for when autocad is giving a prompt that must be answered or cancelled out of?

The insert prompt, especially, was giving me some problems when trying to use it in a lisp routine.

Here, i'll share

(defun C:swapblock ( / oldos oldec oldattdia oldattreq cmdecho dxf en name doc)


(setq oldech (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq oldos (getvar "osmode"))
(setvar "osmode" 0)
(setq oldattdia (getvar "attdia"))
(setvar "attdia" 0)
(setq oldattreq (getvar "attreq"))
(setvar "attreq" 0)

(command "undo" "be")
(if 
(setq en (car (entsel "Select block to update:")))
(progn

(setq name (cdr (assoc 2 (setq dxf (entget en)))))
(setq objx 1)
(if (= NAME NIL)
 (progn
 (alert "Entity selected is not a block. ")
));progn
));progn if

(if (= objx 1)
(progn
(command "_.insert" (strcat name "="))

);progn
);if
(princ "\n")
(princ (strcat "L-Con PIP Block " name " Redefined."))
(princ)
(command "undo" "end")

);defun

 So what's happening is it's inserting/redefining the selected block, and leaving the newly redefined block on the crosshairs as shown, with a prompt to go along with it in autocad.

For scripting/batch processing dwgs this prompt kills any following lines of code and i'm hoping to find a reliable method to get past it.

Thanks for any assistance with this'n 🙂swapblock.jpg

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 6 of 9
bhull1985
in reply to: bhull1985

And you can see in the image where I tried using the "" to get past the prompt, but that just results in the prompt stating that a point or keyword is required

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 7 of 9
p_mcknight
in reply to: chrisdavis5201

The insert command must be given all of its needed components to complete the command prior to continuing with your routine.  That said, it must be given an insertion point, rotation, scale, etc.  If all you want is to redefine the block given, then using your method you must still complete the insert command and then, if wanted, delete the block you just inserted.  That said it would be something along the lines of

 

(command "_.insert" (strcat name "=") '(0 0 0)  1 1 0)

(command ".erase" (entlast) "")

Message 8 of 9
bhull1985
in reply to: p_mcknight

Thanks very much that indeed took care of the issue and has the routine working as intended.

Thanks alot !

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 9 of 9
Kent1Cooper
in reply to: p_mcknight


@p_mcknight wrote:

....  If all you want is to redefine the block given, then using your method you must still complete the insert command and then, if wanted, delete the block you just inserted.  .... 

(command "_.insert" (strcat name "=") '(0 0 0)  1 1 0)

(command ".erase" (entlast) "")


I have used this:

(command "_.insert" (strcat name "=") nil)

 

The nil simply cancels the command, but after the new definition has been brought in.  No need to finish the insertion and then remove the result.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost