Lisp auto wblock to separate drawings with number increments to the file name in autocad

Lisp auto wblock to separate drawings with number increments to the file name in autocad

thientuinfo
Explorer Explorer
360 Views
5 Replies
Message 1 of 6

Lisp auto wblock to separate drawings with number increments to the file name in autocad

thientuinfo
Explorer
Explorer

 I found a lisp, but can only save 1 file with the name 001. Can someone help me how to save more files with increasing names from 000-999. Thanks everyone

(defun c:fwb ()
(setq pickset (ssget))
(setq file_name "D:\\file new\\001.dwg")

(command "_.WBLOCK" file_name "" (list 0.0 0.0 0.0) pickset "")
(command "_.OOPS")
)

0 Likes
Accepted solutions (1)
361 Views
5 Replies
Replies (5)
Message 2 of 6

paullimapa
Mentor
Mentor
Accepted solution

*code updated*

try this:

 

 

; fwb wblocks files with increasing names from 000-999
; fwbres resets name sequence back to 1
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-auto-wblock-to-separate-drawings-with-number-increments-to/m-p/12427730#M458720
(defun c:fwb 
 (/ file_name folder pickset) ; local variables
 (vl-load-com)
 (setq folder "D:\\file new") ; change folder name as needed
 (if (not **fwb_count**)(setq **fwb_count** 1)) ; initiate **fwb_count** as a global variable
 (if (not (vl-file-directory-p folder))  
  (progn
   (princ (strcat"\nFolder Name [" folder "] Does Not Exist attempting to Create it..."))
   (vl-mkdir folder) 
  )
 )
 (if (vl-file-directory-p folder)
  (progn
   (princ (strcat"\nFound Folder Name [" folder "]... Continuing with Wblock function."))
   (setq pickset T)
  )
  (princ (strcat"\nFailed to Create Folder Name [" folder "]... Exiting Wblock function."))
 )
 (while pickset
  (princ "\nSelect Objects to Wblock...")
  (if (setq pickset (ssget))
   (progn
    (cond
     ((< **fwb_count** 9)
      (setq file_name (strcat folder "\\00" (itoa **fwb_count**) ".dwg"))
     )
     ((< **fwb_count** 100)
      (setq file_name (strcat folder "\\0" (itoa **fwb_count**) ".dwg"))
     )
     (t
      (setq file_name (strcat folder "\\" (itoa **fwb_count**) ".dwg"))
     )     
    ) ; cond
    (if (findfile file_name)(vl-file-delete file_name)) ; delete any existing files matching name
    (command "_.WBLOCK" file_name "" (list 0.0 0.0 0.0) pickset "")
    (command "_.OOPS")
    (setq **fwb_count** (1+ **fwb_count**)) ; increment # 
    (princ (strcat "\nWblock successfully written to [" file_name "]."))
   ) ; progn
   (princ"\nNothing Selected.")
  ) ; if
 ) ; while loop
 (princ) ; clean exit
) ; defun
(defun c:fwbres ()(setq **fwb_count** nil)(princ)) ; defun
(princ"\nType [FWB] to execute Wblock sequence or [FWBRes] to Change Sequence back to 1.")(princ)

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 6

ВeekeeCZ
Consultant
Consultant

If you were a newbie, I'd say learn how cond works. That applies to red.

But seeing all the blue ones.. got a headache.

 

It could be so simple 

(cond

  ((< n 10) ...)

  ((< n 100) ...)

 


@paullimapa wrote:

try this:

 

(cond
     ((= (< **fwb_count** 9))
      (setq file_name (strcat folder "\\00" (itoa **fwb_count**) ".dwg"))
     )
     ((and (= (< **fwb_count** 100)(> **fwb_count** 9)))
      (setq file_name (strcat folder "\\0" (itoa **fwb_count**) ".dwg"))
     )
     (t
      (setq file_name (strcat folder "\\" (itoa **fwb_count**) ".dwg"))
     )     
    ) ; cond

 

0 Likes
Message 4 of 6

thientuinfo
Explorer
Explorer
tks u so much !!!
0 Likes
Message 5 of 6

paullimapa
Mentor
Mentor

You’re welcome. .cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 6 of 6

paullimapa
Mentor
Mentor

Yes, temp insanity on my part. Thanks for the reminder. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes