Making a lisp to create a folder and save drawing in that folder on network

Making a lisp to create a folder and save drawing in that folder on network

Anonymous
Not applicable
3,677 Views
7 Replies
Message 1 of 8

Making a lisp to create a folder and save drawing in that folder on network

Anonymous
Not applicable

Hello everyone,

 

I have been working on this lisp but i hit a road block any help is appreciated!

 

(setq path "M:\CNC DXF FILES\\") ; This is the location I want to make the folder in.
      (setq file (vl-string-translate "" "" (getstring T "NAME FILE"))) ; prompts user to enter desired name of the drawing.

          (setq 1F (vl-string-translate "" "" (getstring T "NAME FOLDER"))); prompts user to enter desired name of the new folder
(acet-file-mkdir (strcat path 1F )) ; creates the new folder
(setq filepath (strcat path 1F) "\\" (strcat file ))) ; Combines everything to make the file path  

(command "saveas" "dxf" "" filepath)

 

Something towards the end of this is not working properly and i need some help troubleshooting 

 Also everything i wrote was inspired by something else i read on the forums.

 

thanks guys

 

0 Likes
Accepted solutions (2)
3,678 Views
7 Replies
Replies (7)
Message 2 of 8

dbhunia
Advisor
Advisor
Accepted solution

Hi

 

Like this ....

 

(defun C:fs (/)
(setq path "M:\\CNC DXF FILES\\")
(setq file (vl-string-translate "" "" (getstring T "NAME FILE")))
(setq 1F (vl-string-translate "" "" (getstring T "NAME FOLDER")))
(acet-file-mkdir (strcat path 1F ))
(setq filepath (strcat path 1F "\\" file ))
(command "saveas" "dxf" "" filepath)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 8

Anonymous
Not applicable

Thanks so much! Works like a charm!

0 Likes
Message 4 of 8

ronjonp
Mentor
Mentor

Food for thought:

(defun c:foo (/ dwg file filepath fldr path);< - localize variables!
  (setq path "G:\\CNC DXF FILES\\")
  ;; Create a predefined filename
  (setq	dwg (strcat (vl-filename-base (getvar 'dwgname))
		    "_"
		    (menucmd "M=$(edtime,$(getvar,date),MO-DD-YYYY_HH-MM)")
	    )
  )
  ;; Get user input
  (setq file (getstring (strcat "\nEnter name for file or [" dwg "]: ")))
  ;; If the string is empty use the predefined option else use input
  (setq	file (cond ((= "" file) dwg)
		   (file)
	     )
  )
  ;; Get user input
  (setq fldr (getstring "\nEnter name for file or [None]: "))
  ;; If the string is empty keep it empty else use input and append "\\"
  (setq	fldr (cond ((= "" fldr) "")
		   ((strcat fldr "\\"))
	     )
  )
  ;; Make directory
  (vl-mkdir path)
  ;; Make subfolder ( if any )
  (vl-mkdir (strcat path fldr))
  ;; Save the file
  ;; Could also use DXFOUT then the current drawing would not be in your save directory
  (command "_.saveas" "dxf" "" (strcat path fldr file ".dxf"))
  ;; Shhhhh
  (princ)
)
(vl-load-com)
0 Likes
Message 5 of 8

Anonymous
Not applicable

THANKS FOR THAT

0 Likes
Message 6 of 8

Anonymous
Not applicable

How would I go about integrating a yes or no and if into this 

(defun C:fs (/)

(initget "yes no")

(setq x (getkword "IS THIS A SAMPLE")
(setq path "M:\\CNC DXF FILES\\") ;if x equals no

(setq path "M:\\CNC DXF FILES\SAMPLES\\") ;if x equals yes
(setq file (vl-string-translate "" "" (getstring T "NAME FILE")))
(setq 1F (vl-string-translate "" "" (getstring T "NAME FOLDER")))
(acet-file-mkdir (strcat path 1F ))
(setq filepath (strcat path 1F "\\" file ))
(command "saveas" "dxf" "" filepath)
)

0 Likes
Message 7 of 8

dbhunia
Advisor
Advisor

Try this..............

 

(defun C:fs (/)

(initget 1 "Y N")
(setq x (getkword "\nIS THIS A SAMPLE [Yes/No]: "))
(cond ((= x "N")
	(setq path "M:\\CNC DXF FILES\\") ;if x equals no
      )
      ((= x "Y")
	(setq path "M:\\CNC DXF FILES\\SAMPLES\\") ;if x equals yes
      )
)
(setq file (vl-string-translate "" "" (getstring T "NAME FILE")))
(setq 1F (vl-string-translate "" "" (getstring T "NAME FOLDER")))
(acet-file-mkdir (strcat path 1F ))
(setq filepath (strcat path 1F "\\" file ))
(command "saveas" "dxf" "" filepath)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 8 of 8

ronjonp
Mentor
Mentor
Accepted solution

FWIW ...

(defun c:fs (/ 1f file filepath path x); <-Localize variables!
  (initget 1 "Y N")
  (setq x (getkword "\nIS THIS A SAMPLE [Yes/No]: "))
  ;; If statement works well for two options
  (setq	path (if (= x "N")
	       "M:\\CNC DXF FILES\\"
	       "M:\\CNC DXF FILES\\SAMPLES\\"
	     )
  )
;;;  (cond	((= x "N")
;;;	 (setq path "M:\\CNC DXF FILES\\") ;if x equals no
;;;	)
;;;	((= x "Y")
;;;	 (setq path "M:\\CNC DXF FILES\\SAMPLES\\") ;if x equals yes
;;;	)
;;;  )
  ;; FWIW (vl-string-translate "" "" string) will do nothing
  (setq file (vl-string-translate "" "" (getstring t "NAME FILE")))
  (setq 1f (vl-string-translate "" "" (getstring t "NAME FOLDER")))
  (acet-file-mkdir (strcat path 1f))
  (setq filepath (strcat path 1f "\\" file))
  (command "saveas" "dxf" "" filepath)
)
0 Likes