Jump to content

Output text with spaces?


Nickvnlr

Recommended Posts

I created a LISP to output data to a text file.  It works well except how do I put spaces in the data?  It uses the space as an enter.

 

(defun c:WriteProjectInfo ()
  (setq OutputFile (getfiled "Save Project Info" "" "txt" 1)) ; Prompt user for output file path

  (if OutputFile
    (progn
      (setq Client (getstring "Enter client name: "))
      (setq Location (getstring "Enter location: "))
      (setq Crop (getstring "Enter crop: "))
      (setq DateCode (getstring "Enter date code: "))
      (setq Acres (getstring "Enter acres: "))
      (setq PlantCount (getstring "Enter plant count: "))
      (setq AppRate (getstring "Enter application rate: "))

      (setq FileHandle (open OutputFile "w"))
      (write-line (strcat Client) FileHandle)
      (write-line (strcat Location) FileHandle)
      (write-line (strcat Crop) FileHandle)
      (write-line (strcat DateCode) FileHandle)
      (write-line (strcat Acres) FileHandle)
      (write-line (strcat PlantCount) FileHandle)
      (write-line (strcat AppRate) FileHandle)
      (close FileHandle)

      (prompt (strcat "Project information saved to " OutputFile))
    )
    (prompt "File selection canceled.")
  )
  (princ)
)

 

Link to comment
Share on other sites

AutoDesk has this lookup for functions that usually gives more context for commands.

 

Quote


Type: T or nil

If supplied and not nil, this argument indicates that users can include blanks in their input string (and must terminate the string by pressing Enter). Otherwise, the input string is terminated by entering a space or pressing Enter.

 

 

  • Like 1
Link to comment
Share on other sites

Your welcome to use multi getvals it will make a dcl on the fly for your input of values.  If make mistake can correct before hit Ok.Multi GETVALS.lsp

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

(setq lst (list "Please enter values " "Enter client name: " 20 19 " " "Enter location: " 20 19 " " "Enter crop: " 20 19 " " "Enter date code: " 20 19 " "
"Enter acres: " 20 19 " " "Enter plant count: " 20 19 " "  "Enter application rate: " 20 19 " "))

(setq ans (AH:getvalsm lst))

; ans is a list of the values you can set to a vataible or use (nth x ans) in your write line ps start at x=0

 

image.png.0e285f74b4b478dd45d91b8306de40be.png

 

 

  • Thanks 1
Link to comment
Share on other sites

On 3/13/2024 at 5:33 PM, BIGAL said:

Your welcome to use multi getvals it will make a dcl on the fly for your input of values.  If make mistake can correct before hit Ok.Multi GETVALS.lsp

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

(setq lst (list "Please enter values " "Enter client name: " 20 19 " " "Enter location: " 20 19 " " "Enter crop: " 20 19 " " "Enter date code: " 20 19 " "
"Enter acres: " 20 19 " " "Enter plant count: " 20 19 " "  "Enter application rate: " 20 19 " "))

(setq ans (AH:getvalsm lst))

; ans is a list of the values you can set to a vataible or use (nth x ans) in your write line ps start at x=0

 

image.png.0e285f74b4b478dd45d91b8306de40be.png

 

 

 

That's a great upgrade.  Works well.

I am feeling really dense, but where do I change the input box size?

I read this:

; the input box size can be bigger just change the two values tested with 145 145 and worked ok.

and cannot figure it out.

Link to comment
Share on other sites

20 19 is what your looking for, I dont know why 2 values, a min max thing, as suggested in code tested with 145 144, its number of characters in the edit box.

 

You can make each edit box a different size like 4 3 for say 1-10 then 30 29 for a big string.

 

A further hint if you set a variable to say a number you can use that variable in the lst 

 

(setq lst (list "Please enter values " "Enter client name: " 20 19 " " "Enter location: " 20 19 " " "Enter crop: " 20 19 "10" "Enter date code: " 20 19 " "
"Enter acres: " 20 19 " " "Enter plant count: " 20 19 " "  "Enter application rate: " 20 19 "20"))


(if (= apprate nil)(setq apprate 20))
(setq lst (list "Please enter values " "Enter client name: " 20 19 " " "Enter location: " 20 19 " " "Enter crop: " 20 19 " " "Enter date code: " 20 19 " "
"Enter acres: " 20 19 " " "Enter plant count: " 20 19 " "  "Enter application rate: " 20 19 (rtos apprate 2 0)))

 

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...