Author Topic: Problem to create folder and file name  (Read 2866 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Problem to create folder and file name
« on: February 05, 2009, 01:48:33 AM »
My idea got from creator by JefferyPSanders
Here my code
Code: [Select]
; Create program in program
(defun c:test (/ tex file f)
  (prompt "(C)ircle,(L)ine,(R)ectangular,(E)llipse")
  (setq tex (getstring "\nSelect a program[C/L/R/E]<C>: "))
  (if
    (= tex "")
    (setq tex "c")
    ) ; if
  (cond
    ((= tex "c")(cir))
    ((= tex "l")(lin))
    ((= tex "r")(rec))
    ((= tex "e")(ell))
    ) ; cond
  (startapp "notepad" file) 
  (princ)
  ) ; defun
 

(defun cir ()
  (vl-filename-mktemp "cir" "c:\\Autolisp" ".lsp")
  (setq file "c:/Autolisp/cir.lsp")
  (setq f (open file "w"))
  (princ  "\n(defun c:cir (/ loc rad)" f)
  (princ "\n(setq loc '(0 0 0))" f)
  (princ "\n(setq rad 5)" f)
  (princ "\n(command \"_circle\" loc rad \"\")" f)
  (princ "\n(princ)" f)
  (princ "\n)" f) 
  (close f)
  ) ; defun

(defun lin ()
  (vl-filename-mktemp "lin" "c:\\Autolisp" ".lsp") 
  (setq file "c/Autolisp/lin.lsp")
  (setq f (open file "w"))
  (princ "\n(defun c:lin (/ pt1 pt2)" f)
  (princ "\n(setq pt1 '(0 0 0))" f)
  (princ "\n(setq pt2 '(10 5 0)" f)
  (princ "\n(command \"_line\" pt1 pt2 \"\")" f)
  (princ "\n(princ)" f)
  (princ "\n)" f)
  (close f)
  ) ; defun

(defun rec ()
  (vl-filename-mktemp "rec" "c:\\Autolisp" ".lsp")
  (setq file "c/Autolisp/rec.lsp")
  (setq f (open file "w"))
  (princ "\n(defun c:rec (/ pt1 pt2)" f)
  (princ "\n(setq pt1 '(0 0 0))" f)
  (princ "\n(setq pt2 '(10 5 0)" f)
  (princ "\n(command \"_rectang\" pt1 pt2 \"\")" f)
  (princ "\n(princ)" f)
  (princ "\n)" f)
  (close f)
  ) ; defun

(defun ell ()
  (vl-filename-mktemp "ell" "c:\\Autolisp" ".lsp")
  (setq file "c/Autolisp/ell.lsp")
  (setq f (open file "w"))
  (princ "\n(defun c:ell (/ pt1 pt2)" f)
  (princ "\n(setq pt1 '(0 0 0))" f)
  (princ "\n(setq pt2 '(10 5 0))" f)
  (princ "\n(command \"_ellipse\" pt1 pt2 \"\")" f)
  (princ "\n(princ)" f)
  (princ "\n)" f)
  (close f)
  ) ; defun     

FengK

  • Guest
Re: Problem to create folder and file name
« Reply #1 on: February 05, 2009, 02:27:04 AM »
what is your question?

Adesu

  • Guest
Re: Problem to create folder and file name
« Reply #2 on: February 05, 2009, 02:39:29 AM »
I can not create folder and file name at drive C, any wrong in my code?

what is your question?

fixo

  • Guest
Re: Problem to create folder and file name
« Reply #3 on: February 05, 2009, 04:17:25 AM »
I can not create folder and file name at drive C, any wrong in my code?

what is your question?

Use VL-MKDIR for that

~'J'~

dustinthiesse

  • Guest
Re: Problem to create folder and file name
« Reply #4 on: February 05, 2009, 08:30:54 AM »
......
  (prompt "(C)ircle,(L)ine,(R)ectangular,(E)llipse")
  (setq tex (getstring "\nSelect a program[C/L/R/E]<C>: "))
  (if
    (= tex "")
    (setq tex "c")
    ) ; if
  (cond
    ((= tex "c")(cir))
    ((= tex "l")(lin))
    ((= tex "r")(rec))
    ((= tex "e")(ell))
......

May I suggest using (initget) before your call to getstring?
Code: [Select]
(initget "C L R E")
(setq tex(getkword "\nSelect a program[C/L/R/E]<C>"))
(if(not tex)(setq tex "C"))

This restricts the user input to only those values that you have defined.

Adesu

  • Guest
Re: Problem to create folder and file name
« Reply #5 on: February 05, 2009, 10:47:48 PM »
Thanks fixo it's great information.
here new code
Code: [Select]
(vl-mkdir "c:\\Autolisp")
(setq file "c:/Autolisp/cir.lsp")


I can not create folder and file name at drive C, any wrong in my code?

what is your question?

Use VL-MKDIR for that

~'J'~

fixo

  • Guest
Re: Problem to create folder and file name
« Reply #6 on: February 06, 2009, 04:46:43 AM »
Glad to refresh your memory
Cheers :)

~'J'~