Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

AutoCAD Script to open a .dxf file and save it as a .dwg

Zesty46
Explorer

AutoCAD Script to open a .dxf file and save it as a .dwg

Zesty46
Explorer
Explorer

Hello,

I am new to Autodesk scripts, and could use some help.  I've received a few hundred dxf files from a vendor that i need to convert to dwgs.  If someone could assist with writing a script to open a dxf file and save as a dwg, that would be very helpful.  I am running the scripts using proscript if that helps at all.  Thank you in advance!

 

0 Me gusta
Responder
Soluciones aceptadas (2)
1.070 Vistas
7 Respuestas
Respuestas (7)

Valentin-WSP
Mentor
Mentor
Solución aceptada

@Zesty46 ,

 

Take a look at the Dxf2Dwg from the Autodesk App Store:

 

 

ValentinWSP_0-1694013425240.png

 

 

 

 



Please select the "Accept as Solution" button if my post solves your issue or answers your question.


Emilio Valentin

Zesty46
Explorer
Explorer

Thank you very much, i didnt know this existed!

TheCADnoob
Mentor
Mentor
Solución aceptada

Edit: I started this before the question got answered haha, figured id share anyway. 

 

Scripts are easy generally. Dont get me wrong, there are lots of ways they go sideways but basically you just write each command on a new line in a text file. 

 

TheCADnoob_0-1694013834630.png

 

TheCADnoob_1-1694013950699.png

 

next rename your .txt file to a .scr file. Be sure that you are changing the file extension and not just adding a .scr to the file name. if you cant see the file extensions, turn those on

 

One way you can tell if you have created a script file is if the icon has changed. 

TheCADnoob_2-1694013981243.png

 

What goes into your script file is basically just the command you would send to the command line. So if you wanted to start a line command you would put line in your script file. The other key aspect is that to simulate pressing the enter key is done by going to the next line. 

 

Now specific to your task you will likely need to toggle off the save file dialog. That can be done by changing the FILEDIA system variable to 0. This will allow your save commands to be run from the command line. 

 

Once that is set then use the save as command and then select the DWG version you would like. When it prompts for the file name just do an enter (go to the next line). 

 

Once you are don remember to reset your filedia back to 1. 

 

Here is the contect of a script fil that will save the current file to dwg:

 

FILEDIA
0
SAVEAS
LT2018

FILEDIA
1

 

 

One thing that is always a little tricky is the next line/ enter thing. Some time you may have too many enters which cause command to run again, or some times you forget to do a new line which doesn't finish the command like you though it would. 

 

Hope all that helps!

CADnoob

EESignature

Zesty46
Explorer
Explorer

No worries haha, i really appreciate the well written response.  I didnt realize is was as easy as just writing out the command sequence.  Is the sequence you wrote something i should be able to copy into a script file and use in ProScript?

TheCADnoob
Mentor
Mentor

Yes, you should be able to copy the script. This is with the caveat that in the process of copying sometimes carriage returns/line breaks aren't always preserved. It's best to test the script file on one drawing first to ensure it does what you think it should. Once you verify that it did what you needed and didn't stop unexpectedly in the wrong place, you can run it through script pro. 

CADnoob

EESignature

Zesty46
Explorer
Explorer

Yeah, i had to add an extra return line and it worked fantastic.  Thank you for not only solving my issue but teaching me how to avoid it in the future!

TheCADnoob
Mentor
Mentor

Glad it worked!

 

Scripts are an excellent tool for handling batch operations. 

 

If you start playing with it more, remember that some commands have dialogs much like the save as dialog, but some of those can be surpressed using a dash command "-" version of the command. 

CADnoob

EESignature