Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Routine that will open dxf file and save it as dwg

  1. #1
    100 Club
    Join Date
    2005-05
    Posts
    102
    Login to Give a bone
    0

    Unhappy Routine that will open dxf file and save it as dwg

    I have a lots of dxf file that i will like to open each one of them, purge everything, and then save them as a dwg file with its current name and location. I would appreciate if someone could assist me with this routine. I wasn't sure if lisp is the only solutions.
    I appreciate your input.

    Thanks

    --vboyaji

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Routine that will open dxf file and save it as dwg

    Maybe go the script route. Or have a lisp routine that will write the script for you.

  3. #3
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Routine that will open dxf file and save it as dwg

    This routine requires that a purge lisp already be written and saved to the ACAD support directory. Then this script will load it and run it in every drawing it opens and will save it as a .dwg. ALso it is best if all of the DXF's are in one folder or this code will not work.

    Code:
    (defun c:GenScr (/ dwgPath dwgList dwgName numDwgs count scrFile)
    ;;; Path should be like "c:\\projects\plots\\" or "c:/projects/plots/"
    ;;; Substitute your path here.
    (setq dwgPath "C:\\Documents and Settings"; sets the path
    		dwgList (vl-directory-files dwgPath "*.Dxf") ; get the list of all the dxf's
    )
    	 (if dwgList	 ; if dwg files exists there
    (progn
    (setq numDwgs (length dwgList) ; number of drawings
    		 count 0	 ; initiate counter
    scrFile (open (strcat dwgPath "Runme.scr") "w") ; open a script file in the same folder
    )
    (repeat numDwgs	 ; for all the drawings
    (setq dwgName (strcat "\"" dwgPath (nth count dwgList) "\""))   
    (write-line ".Open" scrFile)	; write to script file
    (write-line dwgName scrFile)
     
    ;;;If you need to load a lisp routine in each dwg
    ;Make sure the lisp files are in the Support search path
    (write-line "(load \"Purging.LSP\")" scrFile) ; load any required lisp routine
    
    ;;;
    ;;; Enter your Lisp routine names here.
    (write-line "(c:PurgeAll)" scrFile)
    
       
    
    ;;;
    ;;; Preset the dxf file format before you proceed.
    ;;; May require minor modification depending on you
    ;;; AutoCAD version Notice the two spaces after dxfout
    ;;; in the following line acts like <enter>.This will 
    ;;; accept the default file name and default format
    (write-line ".dwgout  " scrFile)
    ;;; Better to save the drawing for uninterrupted scripting
    (write-line ".Qsave" scrFile)
      (write-line ".close" scrFile)
    (setq count (1+ count)); next dwg
    )
    (close scrFile); close when done
    ;;; Make sure that the current dwg won't prompt for
    ;;; save changes!
    (command ".script" (strcat dwgPath "Runme.scr")); run the script
    ); progn
    	 ); if
    	 (princ)
    ); defun
    Here is a purge all lisp that you can use.

    Code:
    (defun C:PurgeAll()
        (command "-purge" "A" "" "n")
    );; end of program
    This needs to be saved into the ACAD support directory. IF saved as Purging.lsp the only thing you will need to change in the script above is the directory where the files are located

  4. #4
    100 Club
    Join Date
    2005-05
    Posts
    102
    Login to Give a bone
    0

    Default Re: Routine that will open dxf file and save it as dwg

    Thank you for response.

    How would i execute this lisp routine.
    I have saved my dxf files in the server. Location is O:\Dxf
    I also saved the lisp routine and referenced it in my acad.lsp

    Thanks

    vboyaji

  5. #5
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Routine that will open dxf file and save it as dwg

    Just load this like you would any other lisp routine and from the command prompt type GENSCR and this will run and go to the directory pull out all dxf files and run the lisp routine then save it as a drawing.

    Or to load this from the command prompt if it is saved in the ACAD support directory type

    (load "Purging.lsp") this will load the routine then to run it type GENSCR

    Code:
    (defun c:GenScr (/ dwgPath dwgList dwgName numDwgs count scrFile)
    ;;; Path should be like "c:\\projects\plots\\" or "c:/projects/plots/"
    ;;; Substitute your path here.
    (setq dwgPath "O:\\DXF\\"; sets the path
    		dwgList (vl-directory-files dwgPath "*.Dxf") ; get the list of all the dxf's
    )
    	 (if dwgList	 ; if dwg files exists there
    (progn
    (setq numDwgs (length dwgList) ; number of drawings
    		 count 0	 ; initiate counter
    scrFile (open (strcat dwgPath "Runme.scr") "w") ; open a script file in the same folder
    )
    (repeat numDwgs	 ; for all the drawings
    (setq dwgName (strcat "\"" dwgPath (nth count dwgList) "\""))   
    (write-line ".Open" scrFile)	; write to script file
    (write-line dwgName scrFile)
     
    ;;;If you need to load a lisp routine in each dwg
    ;Make sure the lisp files are in the Support search path
    (write-line "(load \"Purging.LSP\")" scrFile) ; load any required lisp routine
    
    ;;;
    ;;; Enter your Lisp routine names here.
    (write-line "(c:PurgeAll)" scrFile)
    
       
    
    ;;;
    ;;; Preset the dxf file format before you proceed.
    ;;; May require minor modification depending on you
    ;;; AutoCAD version Notice the two spaces after dxfout
    ;;; in the following line acts like <enter>.This will 
    ;;; accept the default file name and default format
    (write-line ".dwgout  " scrFile)
    ;;; Better to save the drawing for uninterrupted scripting
    (write-line ".Qsave" scrFile)
      (write-line ".close" scrFile)
    (setq count (1+ count)); next dwg
    )
    (close scrFile); close when done
    ;;; Make sure that the current dwg won't prompt for
    ;;; save changes!
    (command ".script" (strcat dwgPath "Runme.scr")); run the script
    ); progn
    	 ); if
    	 (princ)
    ); defun

  6. #6
    100 Club
    Join Date
    2005-05
    Posts
    102
    Login to Give a bone
    0

    Default Re: Routine that will open dxf file and save it as dwg

    Well, it started it to work, it opened the dxf file and went on with purgeall routine, but i got an error. It did not save it as a dwg. This is the error i got.


    Enter name of drawing to open <.>: "O:\DXF\231b153.dxf"

    Opening a Release 12 DXF file.
    Regenerating model.

    AutoCAD Express Tools Copyright © 2002-2004 Autodesk, Inc.

    Type BLCX to run.
    AutoCAD menu utilities loaded.
    Command: (load "Purging.LSP")
    ; error: LOAD failed: "Purging.LSP"

    Command: (c:PurgeAll)

    No unreferenced blocks found.

    No unreferenced layers found.

    No unreferenced linetypes found.

    No unreferenced text styles found.

    No unreferenced shape files found.

    No unreferenced dimension styles found.

    No unreferenced mlinestyles found.

    No unreferenced plotstyles found.

    No unreferenced table styles found.

    No unreferenced materials found.

    No unreferenced visual styles found.
    nil

    Command: .dwgout Unknown command "DWGOUT". Press F1 for help.

  7. #7
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Routine that will open dxf file and save it as dwg

    replace this
    (write-line ".dwgout " scrFile)
    with this
    (write-line ".saveas " scrFile)

    and replace
    (write-line ".qsave" scrFile)
    with
    ;;;(write-line ".qsave" scrFile)

    see if that works.
    Last edited by Lions60; 2006-10-12 at 05:10 PM.

  8. #8
    100 Club
    Join Date
    2005-05
    Posts
    102
    Login to Give a bone
    0

    Default Re: Routine that will open dxf file and save it as dwg

    Well it worked. But its only doing the same file, over, over.

    I type genscr and open one dxf file and went through the routine and saved it. But it did not open the next dxf file.

  9. #9
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Routine that will open dxf file and save it as dwg

    I am sorry I told you wrong earlier i have been running it and it seems to work fine this way


    replace this
    (write-line ".dwgout " scrFile)
    with this
    (write-line ".saveas " scrFile)
    ;;;;;;;;;;;There needs to be two spaces in between saveas and "
    and replace
    (write-line ".qsave" scrFile)
    with
    ;;;(write-line ".qsave" scrFile)
    Last edited by Lions60; 2006-10-12 at 05:15 PM.

  10. #10
    100 Club
    Join Date
    2005-05
    Posts
    102
    Login to Give a bone
    0

    Default Re: Routine that will open dxf file and save it as dwg

    Can you please rewrite the code again with the proper changes. I am still getting problems. Its only opening one dxf file at a time.

    No sweat, go it working.

    thanks
    Last edited by VBOYAJI; 2006-10-12 at 11:54 PM. Reason: THANK HIM

Page 1 of 2 12 LastLast

Similar Threads

  1. VBA routine to save and close some open drawings
    By GreyHippo in forum VBA/COM Interop
    Replies: 1
    Last Post: 2010-03-24, 11:59 AM
  2. Add folder in file open/save
    By Andrew Dobson in forum Revit Architecture - General
    Replies: 3
    Last Post: 2006-08-07, 01:27 PM
  3. Lost File/Open File/Save Dialog Box on Autocad 2000i
    By thegoffs.89856 in forum AutoCAD General
    Replies: 3
    Last Post: 2005-06-30, 09:05 PM
  4. Strange behavior on File Open and File Save
    By allen.73799 in forum AutoCAD General
    Replies: 3
    Last Post: 2004-08-27, 07:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •