cleaning
This commit is contained in:
BIN
scripts/SolidWorks.Interop.sldworks.dll
Normal file
BIN
scripts/SolidWorks.Interop.sldworks.dll
Normal file
Binary file not shown.
12
scripts/export-file.cmd
Normal file
12
scripts/export-file.cmd
Normal file
@@ -0,0 +1,12 @@
|
||||
ECHO OFF
|
||||
SET inputFilePath=%~dp0%1".SLDPRT"
|
||||
|
||||
SET outFilePath=%~dp0%1".step"
|
||||
|
||||
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%~dp0export-file.ps1" %inputFilePath% %outFilePath%
|
||||
|
||||
SET inputFilePath=%~dp0%1".SLDDRW"
|
||||
SET outFilePath=%~dp0%1".pdf"
|
||||
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%~dp0export-file.ps1" %inputFilePath% %outFilePath%
|
||||
SET outFilePath=%~dp0%1".dxf"
|
||||
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%~dp0export-file.ps1" %inputFilePath% %outFilePath%
|
||||
102
scripts/export-file.ps1
Normal file
102
scripts/export-file.ps1
Normal file
@@ -0,0 +1,102 @@
|
||||
$inputFilePath=$args[0]
|
||||
$outFilePath=$args[1]
|
||||
|
||||
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||
|
||||
$Assem = (
|
||||
$ScriptDir + "\SolidWorks.Interop.sldworks.dll"
|
||||
)
|
||||
|
||||
$Source = @"
|
||||
using SolidWorks.Interop.sldworks;
|
||||
using System;
|
||||
|
||||
namespace CodeStack
|
||||
{
|
||||
public static class Exporter
|
||||
{
|
||||
#region Libraries
|
||||
|
||||
static Exporter()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
|
||||
}
|
||||
|
||||
public static void LoadLibrary(params object[] libs)
|
||||
{
|
||||
foreach(string lib in libs)
|
||||
{
|
||||
Console.WriteLine(string.Format("Loading library: {0}", lib));
|
||||
System.Reflection.Assembly assm = System.Reflection.Assembly.LoadFrom(lib);
|
||||
Console.WriteLine(assm.GetName().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static System.Reflection.Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
foreach (System.Reflection.Assembly assm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if(assm.GetName().ToString() == args.Name)
|
||||
{
|
||||
return assm;
|
||||
}
|
||||
};
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static void ExportFile(string filePath, string outFilePath)
|
||||
{
|
||||
Console.WriteLine("Connecting to SOLIDWORKS...");
|
||||
|
||||
ISldWorks app = Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")) as ISldWorks;
|
||||
|
||||
if (app != null)
|
||||
{
|
||||
Console.WriteLine(string.Format("Opening file '{0}'...", filePath));
|
||||
|
||||
IDocumentSpecification docSpec = app.GetOpenDocSpec(filePath) as IDocumentSpecification;
|
||||
docSpec.ReadOnly = true;
|
||||
docSpec.Silent = true;
|
||||
IModelDoc2 model = app.OpenDoc7(docSpec);
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
const int swSaveAsCurrentVersion = 0;
|
||||
const int swSaveAsOptions_Silent = 1;
|
||||
int err = -1;
|
||||
int warn = -1;
|
||||
|
||||
Console.WriteLine(string.Format("Exporting file '{0}' to '{1}'...", filePath, outFilePath));
|
||||
|
||||
if (!model.Extension.SaveAs(outFilePath, swSaveAsCurrentVersion,
|
||||
swSaveAsOptions_Silent, null, ref err, ref warn))
|
||||
{
|
||||
Console.WriteLine(string.Format("Failed to export '{0}' to '{1}'. Error code: {2}", filePath, outFilePath, err));
|
||||
}
|
||||
|
||||
Console.WriteLine(string.Format("Closing file '{0}'...", filePath));
|
||||
|
||||
app.CloseDoc(model.GetTitle());
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(string.Format("Failed to open document: '{0}'. Error code: {1}",
|
||||
filePath, docSpec.Error));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Failed to connect to SOLIDWORKS instance");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
Add-Type -TypeDefinition $Source -ReferencedAssemblies $Assem -Language CSharp
|
||||
|
||||
[CodeStack.Exporter]::LoadLibrary($Assem)
|
||||
[CodeStack.Exporter]::ExportFile($inputFilePath, $outFilePath)
|
||||
110
scripts/export-pdf-dxf.ps1
Normal file
110
scripts/export-pdf-dxf.ps1
Normal file
@@ -0,0 +1,110 @@
|
||||
$inputFilePath=$args[0]+".SLDDRW"
|
||||
$outFilePath=$args[1]
|
||||
|
||||
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||
|
||||
$Assem = (
|
||||
$ScriptDir + "\SolidWorks.Interop.sldworks.dll"
|
||||
)
|
||||
|
||||
$Source = @"
|
||||
using SolidWorks.Interop.sldworks;
|
||||
using System;
|
||||
|
||||
namespace CodeStack
|
||||
{
|
||||
public static class Exporter
|
||||
{
|
||||
#region Libraries
|
||||
|
||||
static Exporter()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
|
||||
}
|
||||
|
||||
public static void LoadLibrary(params object[] libs)
|
||||
{
|
||||
foreach(string lib in libs)
|
||||
{
|
||||
Console.WriteLine(string.Format("Loading library: {0}", lib));
|
||||
System.Reflection.Assembly assm = System.Reflection.Assembly.LoadFrom(lib);
|
||||
Console.WriteLine(assm.GetName().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static System.Reflection.Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
foreach (System.Reflection.Assembly assm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if(assm.GetName().ToString() == args.Name)
|
||||
{
|
||||
return assm;
|
||||
}
|
||||
};
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static void ExportFile(string filePath, string outFilePath)
|
||||
{
|
||||
Console.WriteLine("Connecting to SOLIDWORKS...");
|
||||
|
||||
ISldWorks app = Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")) as ISldWorks;
|
||||
|
||||
if (app != null)
|
||||
{
|
||||
Console.WriteLine(string.Format("Opening file '{0}'...", filePath));
|
||||
|
||||
IDocumentSpecification docSpec = app.GetOpenDocSpec(filePath) as IDocumentSpecification;
|
||||
docSpec.ReadOnly = true;
|
||||
docSpec.Silent = true;
|
||||
IModelDoc2 model = app.OpenDoc7(docSpec);
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
const int swSaveAsCurrentVersion = 0;
|
||||
const int swSaveAsOptions_Silent = 1;
|
||||
int err = -1;
|
||||
int warn = -1;
|
||||
|
||||
Console.WriteLine(string.Format("Exporting file '{0}' to '{1}'...", filePath, outFilePath+".pdf"));
|
||||
|
||||
if (!model.Extension.SaveAs(outFilePath+".pdf", swSaveAsCurrentVersion,
|
||||
swSaveAsOptions_Silent, null, ref err, ref warn))
|
||||
{
|
||||
Console.WriteLine(string.Format("Failed to export '{0}' to '{1}'. Error code: {2}", filePath, outFilePath+".pdf", err));
|
||||
}
|
||||
|
||||
Console.WriteLine(string.Format("Exporting file '{0}' to '{1}'...", filePath, outFilePath+".dxf"));
|
||||
|
||||
if (!model.Extension.SaveAs(outFilePath+".dxf", swSaveAsCurrentVersion,
|
||||
swSaveAsOptions_Silent, null, ref err, ref warn))
|
||||
{
|
||||
Console.WriteLine(string.Format("Failed to export '{0}' to '{1}'. Error code: {2}", filePath, outFilePath+".dfx", err));
|
||||
}
|
||||
|
||||
Console.WriteLine(string.Format("Closing file '{0}'...", filePath));
|
||||
|
||||
app.CloseDoc(model.GetTitle());
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(string.Format("Failed to open document: '{0}'. Error code: {1}",
|
||||
filePath, docSpec.Error));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Failed to connect to SOLIDWORKS instance");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
Add-Type -TypeDefinition $Source -ReferencedAssemblies $Assem -Language CSharp
|
||||
|
||||
[CodeStack.Exporter]::LoadLibrary($Assem)
|
||||
[CodeStack.Exporter]::ExportFile($inputFilePath, $outFilePath)
|
||||
102
scripts/export-step.ps1
Normal file
102
scripts/export-step.ps1
Normal file
@@ -0,0 +1,102 @@
|
||||
$inputFilePath=$args[0]+".SLDPRT"
|
||||
$outFilePath=$args[1]
|
||||
|
||||
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||
|
||||
$Assem = (
|
||||
$ScriptDir + "\SolidWorks.Interop.sldworks.dll"
|
||||
)
|
||||
|
||||
$Source = @"
|
||||
using SolidWorks.Interop.sldworks;
|
||||
using System;
|
||||
|
||||
namespace CodeStack
|
||||
{
|
||||
public static class Exporter
|
||||
{
|
||||
#region Libraries
|
||||
|
||||
static Exporter()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
|
||||
}
|
||||
|
||||
public static void LoadLibrary(params object[] libs)
|
||||
{
|
||||
foreach(string lib in libs)
|
||||
{
|
||||
Console.WriteLine(string.Format("Loading library: {0}", lib));
|
||||
System.Reflection.Assembly assm = System.Reflection.Assembly.LoadFrom(lib);
|
||||
Console.WriteLine(assm.GetName().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static System.Reflection.Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
foreach (System.Reflection.Assembly assm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if(assm.GetName().ToString() == args.Name)
|
||||
{
|
||||
return assm;
|
||||
}
|
||||
};
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static void ExportFile(string filePath, string outFilePath)
|
||||
{
|
||||
Console.WriteLine("Connecting to SOLIDWORKS...");
|
||||
|
||||
ISldWorks app = Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")) as ISldWorks;
|
||||
|
||||
if (app != null)
|
||||
{
|
||||
Console.WriteLine(string.Format("Opening file '{0}'...", filePath));
|
||||
|
||||
IDocumentSpecification docSpec = app.GetOpenDocSpec(filePath) as IDocumentSpecification;
|
||||
docSpec.ReadOnly = true;
|
||||
docSpec.Silent = true;
|
||||
IModelDoc2 model = app.OpenDoc7(docSpec);
|
||||
|
||||
if (model != null)
|
||||
{
|
||||
const int swSaveAsCurrentVersion = 0;
|
||||
const int swSaveAsOptions_Silent = 1;
|
||||
int err = -1;
|
||||
int warn = -1;
|
||||
|
||||
Console.WriteLine(string.Format("Exporting file '{0}' to '{1}'...", filePath, outFilePath+".step"));
|
||||
|
||||
if (!model.Extension.SaveAs(outFilePath+".step", swSaveAsCurrentVersion,
|
||||
swSaveAsOptions_Silent, null, ref err, ref warn))
|
||||
{
|
||||
Console.WriteLine(string.Format("Failed to export '{0}' to '{1}'. Error code: {2}", filePath, outFilePath+".step", err));
|
||||
}
|
||||
|
||||
Console.WriteLine(string.Format("Closing file '{0}'...", filePath));
|
||||
|
||||
app.CloseDoc(model.GetTitle());
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(string.Format("Failed to open document: '{0}'. Error code: {1}",
|
||||
filePath, docSpec.Error));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Failed to connect to SOLIDWORKS instance");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
Add-Type -TypeDefinition $Source -ReferencedAssemblies $Assem -Language CSharp
|
||||
|
||||
[CodeStack.Exporter]::LoadLibrary($Assem)
|
||||
[CodeStack.Exporter]::ExportFile($inputFilePath, $outFilePath)
|
||||
57
scripts/run.py
Normal file
57
scripts/run.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# example: .\run.py path_to_folder\
|
||||
|
||||
import os
|
||||
import sys
|
||||
import pathlib
|
||||
import subprocess
|
||||
from rich.progress import track
|
||||
|
||||
# folder input
|
||||
input = next(os.walk(sys.argv[1]))
|
||||
files = input[2]
|
||||
path = input[0]
|
||||
|
||||
currentPath = str(pathlib.Path().resolve())
|
||||
|
||||
# print("files: ", files)
|
||||
# print("currentPath :", currentPath)
|
||||
# print("path: ", path)
|
||||
|
||||
partFiles = [s for s in files if ".SLDPRT" in s] # get only parts files
|
||||
drwgFiles = [s for s in files if ".SLDDRW" in s] # get only drawings files
|
||||
|
||||
# print("Parts: ", partFiles)
|
||||
# print("Drawings: ", drwgFiles)
|
||||
|
||||
partWithoutExention = [os.path.splitext(x)[0] for x in partFiles] # remove extension
|
||||
drwgWithoutExtension = [os.path.splitext(x)[0] for x in drwgFiles] # remove extension
|
||||
# print("Parts without extension: ", partWithoutExention)
|
||||
|
||||
# Check if each part has drawings and print
|
||||
for p in partWithoutExention:
|
||||
if str(p) not in str(drwgFiles):
|
||||
print(p, " doesn't have drawing file")
|
||||
|
||||
|
||||
|
||||
outputFolder = str(path) + "\\export\\"
|
||||
# print("Out folder: ", outputFolder)
|
||||
|
||||
# create export directory
|
||||
if not os.path.exists(outputFolder):
|
||||
os.makedirs(outputFolder)
|
||||
print("Export folder created")
|
||||
|
||||
# part files
|
||||
for i in track(partWithoutExention, description="Exporting step files..."):
|
||||
input = str(i)
|
||||
commandstep = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\scripts\export-step.ps1 "' + path + "\\" + input + '" "' + outputFolder + input + '"'
|
||||
# print(commandstep)
|
||||
subprocess.run(commandstep, capture_output=True)
|
||||
|
||||
# drawings files
|
||||
for i in track(drwgWithoutExtension, description="Exporting PDF and DXF..."):
|
||||
input = str(i)
|
||||
commandPdfDxf = "PowerShell -NoProfile -ExecutionPolicy Bypass -File " + currentPath + '\scripts\export-pdf-dxf.ps1 "' + path + "\\" + input + '" "' + outputFolder + input + '"'
|
||||
# print(commandPdfDxf)
|
||||
subprocess.run(commandPdfDxf, capture_output=True)
|
||||
Reference in New Issue
Block a user