ajithkumar.t Posted February 7 Posted February 7 (setq cdate_val (rtos (getvar "CDATE") 2 6)) (setq YYYY (substr cdate_val 1 4) M (substr cdate_val 5 2) D (substr cdate_val 7 2) ) (setq dateFolderName (strcat D "-" M "-" YYYY)) (setq subfolderName (strcat (rtos x 2 2) "-" modtext)) (setq nestedFolderPath (strcat (getvar "DWGPREFIX") "\\" dateFolderName "\\" subfolderName)) (princ (strcat "\nNested Folder Path: " nestedFolderPath)) (if (not (vl-file-directory-p nestedFolderPath)) ; Use vl-file-directory-p for checking directories (progn (if (vl-mkdir nestedFolderPath) (prompt (strcat "\nCreated folder: " nestedFolderPath)) (prompt (strcat "\nFailed to create folder: " nestedFolderPath)) ) ) (prompt (strcat "\nFolder already exists: " nestedFolderPath)) ) (setq saveFileName (strcat nestedFolderPath "\\" (vl-filename-base (getvar "DWGNAME")) ".dxf")) (princ (strcat "\nSave File Path: " saveFileName)) (if (not(vl-file-copy (getvar "DWGNAME") saveFileName)) (prompt (strcat "\nError: Unable to save the processed drawing as DXF.")) (prompt (strcat "\nProcessed drawing saved to: " saveFileName)) ) (princ) Why this code did not work..? Quote
Steven P Posted February 7 Posted February 7 OK help up out a little..... where does the code not work? Or where does the code work until? Perhaps to help you debug it, add in this: ) (princ "\n") ;;add this line (princ nestedFolderPath) ;; add this line (setq saveFileName (strcat nestedFolderPath "\\" (vl-filename-base (getvar "DWGNAME")) ".dxf")) These 2 parts should be about the middle of the code, if it displays them then it gets that far, if not then the error is before then Quote
Lee Mac Posted February 7 Posted February 7 A few points - This code: (setq cdate_val (rtos (getvar "CDATE") 2 6)) (setq YYYY (substr cdate_val 1 4) M (substr cdate_val 5 2) D (substr cdate_val 7 2) ) (setq dateFolderName (strcat D "-" M "-" YYYY)) Can be shortened to simply: (setq dateFolderName (menucmd "m=$(edtime,0,dd-mo-yyyy)")) In this code: (setq subfolderName (strcat (rtos x 2 2) "-" modtext)) The variables 'x' and 'modtext' are not defined in the code snippet. In this code: (setq nestedFolderPath (strcat (getvar "DWGPREFIX") "\\" dateFolderName "\\" subfolderName)) The DWGPREFIX system variable typically already has a trailing backslash path delimiter, and so this expression is doubling up the path delimiters. This code: (if (not(vl-file-copy (getvar "DWGNAME") saveFileName)) (prompt (strcat "\nError: Unable to save the processed drawing as DXF.")) (prompt (strcat "\nProcessed drawing saved to: " saveFileName)) ) Does not include a filepath for the source file and will only work if the source file is also a DXF file - you cannot save a DWG file as a DXF file by merely copying it to a new filename. Quote
ajithkumar.t Posted February 8 Author Posted February 8 Sorry for the confusion. Here is my modified code, this code work fine until creating folder after it does not save copy "Error: Unable to save the processed drawing as DXF." give solution for this(Note:my source file also DXF). (defun c:createandsave (/ FolderPath dateFolderName subfolderName FolderPath) (setq dateFolderName (menucmd "m=$(edtime,0,dd-mo-yyyy)")) (setq FolderPath (strcat(getvar "DWGPREFIX") dateFolderName)) (if (not (vl-file-directory-p FolderPath)) (vl-mkdir FolderPath) ) (setq subfolderName (strcat (rtos x 2 2) "-" modtext)) (vl-mkdir (strcat FolderPath "\\" subfolderName)) (setq saveFileNamepath (strcat FolderPath "\\" subfolderName)) (setq saveFileName (strcat (vl-filename-base (getvar "DWGNAME")) ".dxf")) (setq saveFile (strcat saveFileName)) (if (not (vl-file-copy (getvar "DWGNAME") saveFileName)) (prompt (strcat "\nError: Unable to save the processed drawing as DXF.")) (prompt (strcat "\nProcessed drawing saved to: " saveFileName)) ) (princ) ) Thanks in advance.. Quote
pkenewell Posted February 8 Posted February 8 (edited) @ajithkumar.t I recommend you try using the (vla-Saveas) method: ;; Use VlaSaveAs Method (setq saveFileName (strcat saveFileNamepath (vl-filename-base (getvar "DWGNAME")) ".dxf")) (vla-saveas (vla-get-activedocument (vlax-get-acad-object)) SaveFileName ac2018_dxf) (if (findfile SaveFileName) (prompt (strcat "\nProcessed drawing saved to: " saveFileName)) (prompt (strcat "\nError: Unable to save the processed drawing as DXF.")) ) Also note: you have some incomplete code in your post above: (setq subfolderName (strcat (rtos x 2 2) "-" modtext)) There is nothing in the function that defines "x" or "modtext" so it errors here. Edited February 8 by pkenewell 2 Quote
Recommended Posts
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.