I would like to be able to process all files in a folder and have them converted to dwg
i recorded this macro but was not sure how to get it to automatically process all the files
any help would be appricated
I would like to be able to process all files in a folder and have them converted to dwg
i recorded this macro but was not sure how to get it to automatically process all the files
any help would be appricated
dim ext as SwConst.swDocumentTypes_e
dim mydir as System.IO.DirectoryInfo
mydir =new System.IO.DirectoryInfo(Path)
for each System.IO.FileInfo myFile in myDir.GetFiles("*.Sld*",IO.SearchOption.[TopDirectoryOnly]/[All]Directory)
if(myfile.Extension.toUppder()=".SLDPRT) then
ext=SwConst.swDocumentTypes_e.swDocPART
else
ext=SwConst.swDocumentTypes_e.swDocASSEMBLY
end if
part.openDoc(myFile.FullName,ext)
part.saveAs(NewFilename.dwg)
part.close()
next
''Wote off the top of my head but that is about it
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.IO;
using System.Windows.Forms;
namespace ToDWG.csproj
{
public partial class SolidWorksMacro
{
public SldWorks swApp;
public IModelDoc2 swModel;
public string folder;
public string[] files;
public string result;
public void Main()
{
FolderBrowserDialog fb = new FolderBrowserDialog();
if (fb.ShowDialog() == DialogResult.OK)
{
folder = fb.SelectedPath;
files = Directory.GetFiles(folder);
int errors = 0, warnings = 0;
foreach (string file in files)
{
FileInfo fi = new FileInfo(file);
if (fi.Extension.ToLower() == ".sldasm")
{
//Do Nothing
}
if (fi.Extension.ToLower() == ".sldprt")
{
//Do Nothing
}
if (fi.Extension.ToLower() == ".slddrw")
{
swModel = swApp.OpenDoc6(file, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
swModel.Extension.SaveAs(fi.Name.Remove(fi.Name.LastIndexOf(".")) + ".DWG", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
result += file + "\n";
swApp.QuitDoc(file);
}
}
swApp.SendMsgToUser2("Files saved to DWG: \n" + result, (int)swMessageBoxIcon_e.swMbInformation, 0);
}
}
}
}
---
Above code will open every drawing in a folder and save it to DWG..
This should Work I tested it
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
dim path as String
Dim file As String
Sub main()
path ="C:\Documents and Settings\BakerRob.PTT_LAN\My Documents\MGQ\"
Set swApp = Application.SldWorks
file = dir(path, vbNormal)
While file <> ""
If (Right(UCase(file), 7) = ".SLDDRW") Then
Set Part = swApp.OpenDoc6(path + file, 3, 0, "", longstatus, longwarnings)
Part.ViewZoomtofit2
longstatus = Part.SaveAs(path + Replace(file, "SLDDRW", "DRW"))
End If
file = dir
Wend
End Sub
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
dim path as String
Dim file As String
Sub main()
path =InputBox("Message","Title", "C:\Documents and Settings\BakerRob.PTT_LAN\My Documents\MGQ\")
Set swApp = Application.SldWorks
file = dir(path, vbNormal)
While file <> ""
If (Right(UCase(file), 7) = ".SLDDRW") Then
Set Part = swApp.OpenDoc6(path + file, 3, 0, "", longstatus, longwarnings)
Part.ViewZoomtofit2
longstatus = Part.SaveAs(path + Replace(file, "SLDDRW", "DRW"))
End If
Part.Close
file = dir
Wend
End Sub
Message was edited by: Jacob Cordingley remove extra space in part .close
The form cut off the code
here it is
swApp.SetUserPreferenceIntegerValue swDxfOutputNoScale, 1
swApp.SetUserPreferenceDoubleValue swDxfOutputScaleFactor, 1
swApp.SetUserPreferenceIntegerValue swDxfVersion,swDxfFormat_e.*
*
swDxfFormat_R12
swDxfFormat_R13
swDxfFormat_R14
swDxfFormat_R2000
swDxfFormat_R2004
swDxfFormat_R2007
If you want to avoid driving your users mad, I would remember to toggle system/user preferences back to their original states at the end of your code. Below is an example in C# (go here if you want VB... http://www.developerfusion.com/tools/convert/csharp-to-vb/). This doesn't refer to your settings in particular but I would probably handle it in a somewhat similar fashion. The main point is to make a decent effort to restore original settings (good practice).
private void EditUserPreferencesExample()
{
bool bInputDimValOnCreate = _swApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate);
try
{
_swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, false);
//....
}
finally
{
_swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, bInputDimValOnCreate);
}
}
If you want to avoid driving your users mad, I would remember to toggle system/user preferences back to their original states at the end of your code. Below is an example in C# (go here if you want VB... http://www.developerfusion.com/tools/convert/csharp-to-vb/). This doesn't refer to your settings in particular but I would probably handle it in a somewhat similar fashion. The main point is to make a decent effort to restore original settings (good practice).
private void EditUserPreferencesExample()
{
bool bInputDimValOnCreate = _swApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate);
try
{
_swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, false);
//....
}
finally
{
_swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, bInputDimValOnCreate);
}
}