Jump to content

Recommended Posts

Posted

Is there any way to have it go back two folders to save the folder bound or e-mail?

 

Example: M:\1234\dwgs\electrical and I want it to save the folders in the 1234 folder that would be two folders. You can also think of it as the folder before the dwgs folder to. Thanks in advance for everything.

 

(defun c:BindIt ( / )
(setq vDia (getvar "filedia")
      vEcho (getvar "cmdecho")
      vPrefix (getvar "dwgprefix")
      vName (getvar "dwgname")
      vDate (rtos (getvar "cdate") 2 6)
      vYear (substr vDate 1 4)
      vMonth (substr vDate 5 2)
      vDay (substr vDate 7 2)
      vDateStr (strcat vYear "-" vMonth "-" vDay)
)
(setvar "filedia" 0)
(setvar "cmdecho" 0)
(initget 1 "Bind Email")
(setq vAns (getkword "\nSave file to [Email / Bound] <Bound>: "))
(cond
 ((= "Bind" vAns)
  (setq vDir (strcat vPrefix "Bound"))
 )
 ((= "Email" vAns)
  (setq vDir (strcat vPrefix "Email"))
 )
)
(if (= (vl-file-directory-p vDir) nil)
 (progn
  (vl-mkdir vDir)
  (vl-mkdir (strcat vDir "\\" vDateStr))
 )
 (if (= (vl-file-directory-p (strcat vDir "\\" vDateStr)) nil)
  (vl-mkdir (strcat vDir "\\" vDateStr))
 )
)
(command ".saveas" "" (strcat vDir "\\" vDateStr "\\" vName))
(setvar "filedia" vDia)
(setvar "cmdecho" vEcho)
(princ)
)

 

Thanks for any help!!!

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • neekcotrack

    12

  • CAB

    10

  • borgunit

    1

Posted

This would trim up the path by two folders

;;;------------------------------------------------------------------------------
;;;
;;;Finds the folder name by how many folders up supplied in argument
;;;No error checking for too many folders argument
;;;Example:    (pp_GetFolderNameUp 2)
;;;------------------------------------------------------------------------------
(defun pp_GetFolderNameUp(sNo /)
 (vl-load-com)
 (setq sPath (pp_StrRev (getvar "dwgprefix")))
 ;Get to folder above
 (repeat sNo
   (setq sPath (substr sPath (+ (vl-string-search "\\" sPath)  3)))
   ) ;repeat
 ;Trim leftover folder name
 (setq sPath (pp_StrRev (substr sPath (+ (vl-string-search "\\" sPath)  1))))
 spath
 ) ;defun
;------------------------------------------------------------------------------
;pp_StrRev: String reverse
;------------------------------------------------------------------------------
(defun pp_StrRev (STR)
 (vl-list->string(reverse(vl-string->list STR)))
)

Posted

Another way to go:

;;  CAB 10/07/08
;; (splitdirs "c:\\123\\456\\789") returns ("c:" "123" "456" "789")
(defun splitdirs (str / lst pos)
 (while (or (setq pos (vl-string-search "\\" str))
            (setq pos (vl-string-search "/" str)))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
 (if (> (strlen str) 0) (setq lst (cons str lst)))
 (reverse lst)
)

Posted

Is there any way to go back to there folder before dwgs no matter how many folders are after it. Where would I put what you guess did above in my lisp already given?

 

Thanks again

Posted
Is there any way to go back to there folder before dwgs no matter how many folders are after it. Where would I put what you guess did above in my lisp already given?

 

Thanks again

 

Any Help!!

Posted
(defun c:test(/ dir lst NewDir idx)
 (setq dir "M:\\1234\\Target Dir\\dwgs\\electrical")
 (setq lst (splitdirs dir))
 (setq NewDir (car lst))
 (setq idx 0)
 (while (/= "DWGS" (strcase (nth (setq idx (1+ idx)) lst)))
   (setq NewDir (strcat NewDir "\\" (nth idx lst)))
 )
 (print NewDir)
 (princ)
)


;;  CAB 10/07/08
;; (splitdirs "c:\\123\\456\\789") returns ("c:" "123" "456" "789")
(defun splitdirs (str / lst pos)
 (while (or (setq pos (vl-string-search "\\" str))
            (setq pos (vl-string-search "/" str)))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
 (if (> (strlen str) 0) (setq lst (cons str lst)))
 (reverse lst)
)

Posted
(defun c:test(/ dir lst NewDir idx)
 (setq dir "M:\\1234\\Target Dir\\dwgs\\electrical")
 (setq lst (splitdirs dir))
 (setq NewDir (car lst))
 (setq idx 0)
 (while (/= "DWGS" (strcase (nth (setq idx (1+ idx)) lst)))
   (setq NewDir (strcat NewDir "\\" (nth idx lst)))
 )
 (print NewDir)
 (princ)
)


;;  CAB 10/07/08
;; (splitdirs "c:\\123\\456\\789") returns ("c:" "123" "456" "789")
(defun splitdirs (str / lst pos)
 (while (or (setq pos (vl-string-search "\\" str))
            (setq pos (vl-string-search "/" str)))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
 (if (> (strlen str) 0) (setq lst (cons str lst)))
 (reverse lst)
)

 

When I do your is does not do anything? How come?

Posted

The test lisp starts with this:

"M:\\1234\\Target Dir\\dwgs\\electrical"

and returns this:

Command: test

"M:\\1234\\Target Dir"

 

 

This is a tool, a subroutine.

Do you need help integrating it into your lisp?

Posted
The test lisp starts with this:

"M:\\1234\\Target Dir\\dwgs\\electrical"

and returns this:

Command: test

"M:\\1234\\Target Dir"

 

 

This is a tool, a subroutine.

Do you need help integrating it into your lisp?

 

Yes please I'm lost!!!!

Posted

Here, you debug it.:wink: :wink:

(defun c:BindIt (/)

;;  CAB 10/07/08
;; (splitdirs "c:\\123\\456\\789") returns ("c:" "123" "456" "789")
(defun splitdirs (str / lst pos)
 (while (or (setq pos (vl-string-search "\\" str))
            (setq pos (vl-string-search "/" str)))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
 (if (> (strlen str) 0) (setq lst (cons str lst)))
 (reverse lst)
)


 (setq vDia     (getvar "filedia")
       vEcho    (getvar "cmdecho")
       vPrefix  (getvar "dwgprefix")
       vName    (getvar "dwgname")
       vDate    (rtos (getvar "cdate") 2 6)
       vYear    (substr vDate 1 4)
       vMonth   (substr vDate 5 2)
       vDay     (substr vDate 7 2)
       vDateStr (strcat vYear "-" vMonth "-" vDay)
 )

 ;;  remove the last 2 dirs
 (setq lst (reverse (cddr (reverse (splitdirs vPrefix)))))
 (setq vPrefix "")
 (mapcar '(lambda(x) (setq vPrefix (strcat vPrefix x "\\"))) lst)
 
 (setvar "filedia" 0)
 (setvar "cmdecho" 0)
 (initget "Bound Email")
 (setq vDir (getkword "\nSave file to [Email/Bound] <Bound>: "))
 (cond
   ((or (null vDir)(= "Bound" vAns))
    (setq vDir (strcat vPrefix "Bound"))
   )
   (t
    (setq vDir (strcat vPrefix "Email"))
   )
 )
 (cond
   ((and (null (vl-file-directory-p vDir))
         (null (vl-mkdir vDir))
     )
    (prompt "\nError - Could not create Folder.")
    )
   (t ; folder exist
     (command ".saveas" "" (strcat vDir "\\" vDateStr "-" vName))
   )
 )
    

 (setvar "filedia" vDia)
 (setvar "cmdecho" vEcho)
 (princ)
)

Posted
Here, you debug it.:wink: :wink:

(defun c:BindIt (/)

;;  CAB 10/07/08
;; (splitdirs "c:\\123\\456\\789") returns ("c:" "123" "456" "789")
(defun splitdirs (str / lst pos)
 (while (or (setq pos (vl-string-search "\\" str))
            (setq pos (vl-string-search "/" str)))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
 (if (> (strlen str) 0) (setq lst (cons str lst)))
 (reverse lst)
)


 (setq vDia     (getvar "filedia")
       vEcho    (getvar "cmdecho")
       vPrefix  (getvar "dwgprefix")
       vName    (getvar "dwgname")
       vDate    (rtos (getvar "cdate") 2 6)
       vYear    (substr vDate 1 4)
       vMonth   (substr vDate 5 2)
       vDay     (substr vDate 7 2)
       vDateStr (strcat vYear "-" vMonth "-" vDay)
 )

 ;;  remove the last 2 dirs
 (setq lst (reverse (cddr (reverse (splitdirs vPrefix)))))
 (setq vPrefix "")
 (mapcar '(lambda(x) (setq vPrefix (strcat vPrefix x "\\"))) lst)

 (setvar "filedia" 0)
 (setvar "cmdecho" 0)
 (initget "Bound Email")
 (setq vDir (getkword "\nSave file to [Email/Bound] <Bound>: "))
 (cond
   ((or (null vDir)(= "Bound" vAns))
    (setq vDir (strcat vPrefix "Bound"))
   )
   (t
    (setq vDir (strcat vPrefix "Email"))
   )
 )
 (cond
   ((and (null (vl-file-directory-p vDir))
         (null (vl-mkdir vDir))
     )
    (prompt "\nError - Could not create Folder.")
    )
   (t ; folder exist
     (command ".saveas" "" (strcat vDir "\\" vDateStr "-" vName))
   )
 )


 (setvar "filedia" vDia)
 (setvar "cmdecho" vEcho)
 (princ)
)

 

I got it to work, but instead of it taking the file and putting it in the bound/E-mail folder, then a folder created with the date like 2008-10-22. If puts it in the bound/e-mail folder and just puts the date at the beginning of the file name. How come it does this.

Posted
I got it to work

Did you change anything to get it to work?

instead of it taking the file and putting it in the bound/E-mail folder, then a folder created with the date like 2008-10-22. If puts it in the bound/e-mail folder and just puts the date at the beginning of the file name. How come it does this.
I changed the code to do that thinking you would not want to create folders for every date

but to just create unique file names instead.

 

Silly me.:)

If you want I can revise it.

Posted

no you had everything working.

Posted

Revised code:

(defun c:BindIt (/)

;;  CAB 10/07/08
;; (splitdirs "c:\\123\\456\\789") returns ("c:" "123" "456" "789")
(defun splitdirs (str / lst pos)
 (while (or (setq pos (vl-string-search "\\" str))
            (setq pos (vl-string-search "/" str)))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
 (if (> (strlen str) 0) (setq lst (cons str lst)))
 (reverse lst)
)


 (setq vDia     (getvar "filedia")
       vEcho    (getvar "cmdecho")
       vPrefix  (getvar "dwgprefix")
       vName    (getvar "dwgname")
       vDate    (rtos (getvar "cdate") 2 6)
       vYear    (substr vDate 1 4)
       vMonth   (substr vDate 5 2)
       vDay     (substr vDate 7 2)
       vDateStr (strcat vYear "-" vMonth "-" vDay)
 )

 ;;  remove the last 2 dirs
 (setq lst (reverse (cddr (reverse (splitdirs vPrefix)))))
 (setq vPrefix "")
 (mapcar '(lambda(x) (setq vPrefix (strcat vPrefix x "\\"))) lst)
 
 (setvar "filedia" 0)
 (setvar "cmdecho" 0)
 (initget "Bound Email")
 (setq vDir (getkword "\nSave file to [Email/Bound] <Bound>: "))
 (cond
   ((or (null vDir)(= "Bound" vAns))
    (setq vDir (strcat vPrefix "Bound"))
   )
   (t
    (setq vDir (strcat vPrefix "Email"))
   )
 )

 ;;  The following is to create a seperate directory for each date
 (setq vDir (strcat vDir "\\" vDateStr))

 
 (cond
   ((and (null (vl-file-directory-p vDir))
         (null (vl-mkdir vDir))
     )
    (prompt "\nError - Could not create Folder.")
    )
   (t ; folder exist
     ;;(command ".saveas" "" (strcat vDir "\\" vDateStr "-" vName))
     (command ".saveas" "" (strcat vDir "\\" vName))
   )
 )
 
 (setvar "filedia" vDia)
 (setvar "cmdecho" vEcho)
 (princ)
)

Posted
Revised code:

(defun c:BindIt (/)

;;  CAB 10/07/08
;; (splitdirs "c:\\123\\456\\789") returns ("c:" "123" "456" "789")
(defun splitdirs (str / lst pos)
 (while (or (setq pos (vl-string-search "\\" str))
            (setq pos (vl-string-search "/" str)))
   (setq lst (cons (substr str 1 pos) lst)
         str (substr str (+ pos 2))))
 (if (> (strlen str) 0) (setq lst (cons str lst)))
 (reverse lst)
)


 (setq vDia     (getvar "filedia")
       vEcho    (getvar "cmdecho")
       vPrefix  (getvar "dwgprefix")
       vName    (getvar "dwgname")
       vDate    (rtos (getvar "cdate") 2 6)
       vYear    (substr vDate 1 4)
       vMonth   (substr vDate 5 2)
       vDay     (substr vDate 7 2)
       vDateStr (strcat vYear "-" vMonth "-" vDay)
 )

 ;;  remove the last 2 dirs
 (setq lst (reverse (cddr (reverse (splitdirs vPrefix)))))
 (setq vPrefix "")
 (mapcar '(lambda(x) (setq vPrefix (strcat vPrefix x "\\"))) lst)

 (setvar "filedia" 0)
 (setvar "cmdecho" 0)
 (initget "Bound Email")
 (setq vDir (getkword "\nSave file to [Email/Bound] <Bound>: "))
 (cond
   ((or (null vDir)(= "Bound" vAns))
    (setq vDir (strcat vPrefix "Bound"))
   )
   (t
    (setq vDir (strcat vPrefix "Email"))
   )
 )

 ;;  The following is to create a seperate directory for each date
 (setq vDir (strcat vDir "\\" vDateStr))


 (cond
   ((and (null (vl-file-directory-p vDir))
         (null (vl-mkdir vDir))
     )
    (prompt "\nError - Could not create Folder.")
    )
   (t ; folder exist
     ;;(command ".saveas" "" (strcat vDir "\\" vDateStr "-" vName))
     (command ".saveas" "" (strcat vDir "\\" vName))
   )
 )

 (setvar "filedia" vDia)
 (setvar "cmdecho" vEcho)
 (princ)
)

 

Ok this works good. If I have a drawing on my C drive, but if I have something on my m drive it keeps on saying could not create folder how come. I even tried changing the c:\\ to m:\\ but still the samething how come?

Posted

The problem is if the Bind or Email folders are not already created.

This should fix it.

(defun c:BindIt (/ LST VANS VDATE VDATESTR VDAY VDIA VDIR VECHO VMONTH VNAME VPREFIX VYEAR X)

 ;;  CAB 10/07/08
 ;; (splitdirs "c:\\123\\456\\789") returns ("c:" "123" "456" "789")
 (defun splitdirs (str / lst pos)
   (while (or (setq pos (vl-string-search "\\" str))
              (setq pos (vl-string-search "/" str))
          )
     (setq lst (cons (substr str 1 pos) lst)
           str (substr str (+ pos 2))
     )
   )
   (if (> (strlen str) 0)
     (setq lst (cons str lst))
   )
   (reverse lst)
 )


 (setq vDia     (getvar "filedia")
       vEcho    (getvar "cmdecho")
       vPrefix  (getvar "dwgprefix")
       vName    (getvar "dwgname")
       vDate    (rtos (getvar "cdate") 2 6)
       vYear    (substr vDate 1 4)
       vMonth   (substr vDate 5 2)
       vDay     (substr vDate 7 2)
       vDateStr (strcat vYear "-" vMonth "-" vDay)
 )

 ;;  remove the last 2 dirs
 (setq lst (reverse (cddr (reverse (splitdirs vPrefix)))))
 (setq vPrefix "")
 (mapcar '(lambda (x) (setq vPrefix (strcat vPrefix x "\\"))) lst)

 (setvar "filedia" 0)
 (setvar "cmdecho" 0)
 (initget "Bound Email")
 (setq vDir (getkword "\nSave file to [Email/Bound] <Bound>: "))
 (cond
   ((or (null vDir) (= "Bound" vAns))
    (setq vDir (strcat vPrefix "Bound"))
    (vl-mkdir vDir)
   )
   (t
    (setq vDir (strcat vPrefix "Email"))
    (vl-mkdir vDir)
   )
 )

 (if (vl-file-directory-p vDir)
   (progn
     ;;  The following is to create a seperate directory for each date
     (setq vDir (strcat vDir "\\" vDateStr))


     (cond
       ((and (null (vl-file-directory-p vDir))
             (null (vl-mkdir vDir))
        )
        (prompt (strcat "\nError - Could not create Folder: " vDir))
       )
       (t ; folder exist
        ;;(command ".saveas" "" (strcat vDir "\\" vDateStr "-" vName))
        (command ".saveas" "" (strcat vDir "\\" vName))
       )
     )
   )
   (prompt (strcat "\nError - Could not create Folder: " vDir))
 )
 (setvar "filedia" vDia)
 (setvar "cmdecho" vEcho)
 (princ)
)

Posted
The problem is if the Bind or Email folders are not already created.

This should fix it.

(defun c:BindIt (/ LST VANS VDATE VDATESTR VDAY VDIA VDIR VECHO VMONTH VNAME VPREFIX VYEAR X)

 ;;  CAB 10/07/08
 ;; (splitdirs "c:\\123\\456\\789") returns ("c:" "123" "456" "789")
 (defun splitdirs (str / lst pos)
   (while (or (setq pos (vl-string-search "\\" str))
              (setq pos (vl-string-search "/" str))
          )
     (setq lst (cons (substr str 1 pos) lst)
           str (substr str (+ pos 2))
     )
   )
   (if (> (strlen str) 0)
     (setq lst (cons str lst))
   )
   (reverse lst)
 )


 (setq vDia     (getvar "filedia")
       vEcho    (getvar "cmdecho")
       vPrefix  (getvar "dwgprefix")
       vName    (getvar "dwgname")
       vDate    (rtos (getvar "cdate") 2 6)
       vYear    (substr vDate 1 4)
       vMonth   (substr vDate 5 2)
       vDay     (substr vDate 7 2)
       vDateStr (strcat vYear "-" vMonth "-" vDay)
 )

 ;;  remove the last 2 dirs
 (setq lst (reverse (cddr (reverse (splitdirs vPrefix)))))
 (setq vPrefix "")
 (mapcar '(lambda (x) (setq vPrefix (strcat vPrefix x "\\"))) lst)

 (setvar "filedia" 0)
 (setvar "cmdecho" 0)
 (initget "Bound Email")
 (setq vDir (getkword "\nSave file to [Email/Bound] <Bound>: "))
 (cond
   ((or (null vDir) (= "Bound" vAns))
    (setq vDir (strcat vPrefix "Bound"))
    (vl-mkdir vDir)
   )
   (t
    (setq vDir (strcat vPrefix "Email"))
    (vl-mkdir vDir)
   )
 )

 (if (vl-file-directory-p vDir)
   (progn
     ;;  The following is to create a seperate directory for each date
     (setq vDir (strcat vDir "\\" vDateStr))


     (cond
       ((and (null (vl-file-directory-p vDir))
             (null (vl-mkdir vDir))
        )
        (prompt (strcat "\nError - Could not create Folder: " vDir))
       )
       (t ; folder exist
        ;;(command ".saveas" "" (strcat vDir "\\" vDateStr "-" vName))
        (command ".saveas" "" (strcat vDir "\\" vName))
       )
     )
   )
   (prompt (strcat "\nError - Could not create Folder: " vDir))
 )
 (setvar "filedia" vDia)
 (setvar "cmdecho" vEcho)
 (princ)
)

 

thanks works perfect. I just added one thing at the end so it will bind and purge, then resave it

 

At the end I added this.

 

(command "_.xref" "bind" "*")
(command "_.purge" "" "all" "n" "" "_.purge" "all" "" "n" "" "_.purge" "all" "" "n")
(command ".save")
)

 

Thanks for all your help I hope this helps someone else.

Posted

Put your code in this section so it will only be executed if no errors.

        (t ; folder exist
        ;;(command ".saveas" "" (strcat vDir "\\" vDateStr "-" vName))
        (command ".saveas" "" (strcat vDir "\\" vName))
        ;;  Add your code here
       )

Posted
Put your code in this section so it will only be executed if no errors.

        (t ; folder exist
        ;;(command ".saveas" "" (strcat vDir "\\" vDateStr "-" vName))
        (command ".saveas" "" (strcat vDir "\\" vName))
        ;;  Add your code here
       )

 

Is there a way to put the purge and bind at the beginning, then instead of savas is it possible to do a aectoacad. Not changing anything but the bind and purge will be done before aectoacad to the folder location.

Posted

Oops, use this:

        (t ; folder exist
        (command "_.xref" "bind" "*")
        (command "_.purge" "" "all" "n" "" "_.purge" "all" "" "n" "" "_.purge" "all" "" "n")
        ;;(command ".saveas" "" (strcat vDir "\\" vDateStr "-" vName))
        (command ".saveas" "" (strcat vDir "\\" vName))
       )

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...