diff --git a/ExportDXF.sln b/ExportDXF.sln
new file mode 100644
index 0000000..9a1043d
--- /dev/null
+++ b/ExportDXF.sln
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExportDXF", "ExportDXF\ExportDXF.csproj", "{05F21D73-FD31-4E77-8D9B-41C86D4D8305}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {05F21D73-FD31-4E77-8D9B-41C86D4D8305}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {05F21D73-FD31-4E77-8D9B-41C86D4D8305}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {05F21D73-FD31-4E77-8D9B-41C86D4D8305}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {05F21D73-FD31-4E77-8D9B-41C86D4D8305}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/ExportDXF/ExportDXF.csproj b/ExportDXF/ExportDXF.csproj
new file mode 100644
index 0000000..03b2606
--- /dev/null
+++ b/ExportDXF/ExportDXF.csproj
@@ -0,0 +1,101 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {05F21D73-FD31-4E77-8D9B-41C86D4D8305}
+ WinExe
+ Properties
+ ExportDXF
+ ExportDXF
+ v4.0
+ 512
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ False
+ False
+ C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\api\redist\SolidWorks.Interop.sldworks.dll
+
+
+ False
+ False
+ C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\api\redist\SolidWorks.Interop.swconst.dll
+
+
+
+
+
+
+
+ Form
+
+
+ MainForm.cs
+
+
+
+
+ MainForm.cs
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+ Designer
+
+
+ True
+ Resources.resx
+ True
+
+
+ SettingsSingleFileGenerator
+ Settings.Designer.cs
+
+
+ True
+ Settings.settings
+ True
+
+
+ PreserveNewest
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ExportDXF/Forms/MainForm.Designer.cs b/ExportDXF/Forms/MainForm.Designer.cs
new file mode 100644
index 0000000..664362c
--- /dev/null
+++ b/ExportDXF/Forms/MainForm.Designer.cs
@@ -0,0 +1,149 @@
+namespace ExportDXF.Forms
+{
+ partial class MainForm
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.textBox1 = new System.Windows.Forms.TextBox();
+ this.richTextBox1 = new System.Windows.Forms.RichTextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.textBox2 = new System.Windows.Forms.TextBox();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button1 = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // textBox1
+ //
+ this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.textBox1.BackColor = System.Drawing.Color.White;
+ this.textBox1.Location = new System.Drawing.Point(130, 17);
+ this.textBox1.Name = "textBox1";
+ this.textBox1.ReadOnly = true;
+ this.textBox1.Size = new System.Drawing.Size(348, 25);
+ this.textBox1.TabIndex = 2;
+ //
+ // richTextBox1
+ //
+ this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.richTextBox1.BackColor = System.Drawing.Color.White;
+ this.richTextBox1.Location = new System.Drawing.Point(12, 83);
+ this.richTextBox1.Name = "richTextBox1";
+ this.richTextBox1.ReadOnly = true;
+ this.richTextBox1.Size = new System.Drawing.Size(570, 181);
+ this.richTextBox1.TabIndex = 3;
+ this.richTextBox1.Text = "";
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(12, 20);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(112, 17);
+ this.label1.TabIndex = 4;
+ this.label1.Text = "Active Document :";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(23, 51);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(101, 17);
+ this.label2.TabIndex = 4;
+ this.label2.Text = "Prefix files with :";
+ //
+ // textBox2
+ //
+ this.textBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.textBox2.Location = new System.Drawing.Point(130, 48);
+ this.textBox2.Name = "textBox2";
+ this.textBox2.Size = new System.Drawing.Size(348, 25);
+ this.textBox2.TabIndex = 2;
+ //
+ // button2
+ //
+ this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button2.Image = global::ExportDXF.Properties.Resources.edit_alt;
+ this.button2.Location = new System.Drawing.Point(536, 13);
+ this.button2.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(46, 60);
+ this.button2.TabIndex = 0;
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Visible = false;
+ this.button2.Click += new System.EventHandler(this.button2_Click);
+ //
+ // button1
+ //
+ this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.button1.Image = global::ExportDXF.Properties.Resources.play;
+ this.button1.Location = new System.Drawing.Point(484, 13);
+ this.button1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(46, 60);
+ this.button1.TabIndex = 0;
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.button1_Click);
+ //
+ // Form1
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(594, 276);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.richTextBox1);
+ this.Controls.Add(this.textBox2);
+ this.Controls.Add(this.textBox1);
+ this.Controls.Add(this.button2);
+ this.Controls.Add(this.button1);
+ this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.MaximizeBox = false;
+ this.Name = "Form1";
+ this.Text = "ExportDXF";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.TextBox textBox1;
+ private System.Windows.Forms.RichTextBox richTextBox1;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.TextBox textBox2;
+ private System.Windows.Forms.Button button2;
+ }
+}
+
diff --git a/ExportDXF/Forms/MainForm.cs b/ExportDXF/Forms/MainForm.cs
new file mode 100644
index 0000000..95970fe
--- /dev/null
+++ b/ExportDXF/Forms/MainForm.cs
@@ -0,0 +1,688 @@
+using SolidWorks.Interop.sldworks;
+using SolidWorks.Interop.swconst;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace ExportDXF.Forms
+{
+ public partial class MainForm : Form
+ {
+ private SldWorks sldWorks;
+ private BackgroundWorker worker;
+ private DrawingDoc templateDrawing;
+ private DateTime timeStarted;
+
+ public MainForm()
+ {
+ InitializeComponent();
+
+ worker = new BackgroundWorker();
+ worker.WorkerSupportsCancellation = true;
+ worker.DoWork += Worker_DoWork;
+ worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
+ }
+
+ private void Worker_DoWork(object sender, DoWorkEventArgs e)
+ {
+ timeStarted = DateTime.Now;
+
+ Invoke(new MethodInvoker(() =>
+ {
+ sldWorks.ActiveModelDocChangeNotify -= SldWorks_ActiveModelDocChangeNotify;
+
+ button1.Image = Properties.Resources.stop_alt;
+
+ if (richTextBox1.TextLength != 0)
+ richTextBox1.AppendText("\n\n");
+ }));
+
+ var model = sldWorks.ActiveDoc as ModelDoc2;
+
+ Print("Started at " + DateTime.Now.ToShortTimeString());
+
+ CreateDXFTemplates(model);
+ }
+
+ private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
+ {
+ Invoke(new MethodInvoker(() =>
+ {
+ if (templateDrawing != null)
+ {
+ sldWorks.CloseDoc(((ModelDoc2)templateDrawing).GetTitle());
+ templateDrawing = null;
+ }
+
+ button1.Image = Properties.Resources.play;
+ }));
+
+ var duration = DateTime.Now - timeStarted;
+
+ Print("Run time: " + duration.ToReadableFormat());
+ Print("Done.", Color.Green);
+
+ sldWorks.ActiveModelDocChangeNotify += SldWorks_ActiveModelDocChangeNotify;
+ }
+
+ private int SldWorks_ActiveModelDocChangeNotify()
+ {
+ if (InvokeRequired)
+ {
+ Invoke(new MethodInvoker(() =>
+ {
+ SetCurrentDocName();
+ }));
+ }
+ else
+ {
+ SetCurrentDocName();
+ }
+
+ return 1;
+ }
+
+ protected override void OnLoad(EventArgs e)
+ {
+ base.OnLoad(e);
+
+ new Thread(new ThreadStart(() =>
+ {
+ Invoke(new MethodInvoker(() =>
+ {
+ Enabled = false;
+ sldWorks = Activator.CreateInstance(Type.GetTypeFromProgID("SldWorks.Application")) as SldWorks;
+
+ if (sldWorks == null)
+ {
+ MessageBox.Show("Failed to connect to SolidWorks.");
+ Application.Exit();
+ return;
+ }
+
+ sldWorks.Visible = true;
+ sldWorks.ActiveModelDocChangeNotify += SldWorks_ActiveModelDocChangeNotify;
+ SetCurrentDocName();
+ Enabled = true;
+ }));
+ }))
+ .Start();
+ }
+
+ private void Print(string s)
+ {
+ Invoke(new MethodInvoker(() =>
+ {
+ richTextBox1.AppendText(s + System.Environment.NewLine);
+ richTextBox1.ScrollToCaret();
+ }));
+ }
+
+ private void Print(string s, Color color)
+ {
+ Invoke(new MethodInvoker(() =>
+ {
+ richTextBox1.AppendText(s + System.Environment.NewLine, color);
+ richTextBox1.ScrollToCaret();
+ }));
+ }
+
+ private void SetCurrentDocName()
+ {
+ var model = sldWorks.ActiveDoc as ModelDoc2;
+
+ textBox1.Text = model != null ? model.GetTitle() : "";
+ }
+
+ private void button1_Click(object sender, EventArgs e)
+ {
+ if (worker.IsBusy)
+ {
+ worker.CancelAsync();
+ return;
+ }
+
+ worker.RunWorkerAsync();
+ }
+
+ private void CreateDXFTemplates(ModelDoc2 model)
+ {
+ if (model is PartDoc)
+ {
+ Print("Active document is a Part");
+ ExportToDXF(model as PartDoc);
+ }
+ else if (model is DrawingDoc)
+ {
+ Print("Active document is a Drawing");
+ ExportToDXF(model as DrawingDoc);
+ }
+ else if (model is AssemblyDoc)
+ {
+ Print("Active document is a Assembly");
+ ExportToDXF(model as AssemblyDoc);
+ }
+ }
+
+ private void ExportToDXF(DrawingDoc drawing)
+ {
+ Print("Finding BOM tables...");
+ var bomTables = GetBomTables(drawing);
+
+ if (bomTables.Count == 0)
+ {
+ Print("Error: Bill of materials not found.", Color.Red);
+ return;
+ }
+
+ Print("Found " + bomTables.Count);
+ Print("");
+
+ foreach (var bom in bomTables)
+ {
+ if (worker.CancellationPending)
+ return;
+
+ Print(bom.BomFeature.Name);
+
+ Print("Fetching components...");
+
+ var items = GetItems(bom);
+
+ Print("Found " + items.Count);
+ Print("");
+
+ ExportToDXF(items);
+ }
+ }
+
+ private void ExportToDXF(PartDoc part)
+ {
+ var prefix = textBox2.Text;
+ var model = part as ModelDoc2;
+ var dir = GetSaveDir();
+
+ if (dir == null)
+ {
+ Print("Cancelled\n", Color.Red);
+ return;
+ }
+
+ if (dir == null)
+ return;
+
+ var name = model.ConfigurationManager.ActiveConfiguration.Name.ToLower() == "default" ?
+ model.GetTitle() :
+ string.Format("{0} [{1}]", model.GetTitle(), model.ConfigurationManager.ActiveConfiguration.Name);
+
+ var savePath = Path.Combine(dir, prefix + name + ".dxf");
+
+ SavePartToDXF(part, savePath);
+ }
+
+ private void ExportToDXF(AssemblyDoc assembly)
+ {
+ Print("Fetching components...");
+
+ var items = GetItems(assembly, false);
+
+ Print("Found " + items.Count);
+ Print("");
+
+ ExportToDXF(items);
+ }
+
+ private void ExportToDXF(IEnumerable- items)
+ {
+ var savePath = GetSaveDir();
+ var prefix = textBox2.Text;
+
+ if (savePath == null)
+ {
+ Print("Cancelled\n", Color.Red);
+ return;
+ }
+
+ templateDrawing = CreateDrawing();
+
+ Print("");
+
+ foreach (var item in items)
+ {
+ if (worker.CancellationPending)
+ break;
+
+ var fileName = prefix + item.Name + ".dxf";
+ var savepath = Path.Combine(savePath, fileName);
+ var part = item.Component.GetModelDoc2() as PartDoc;
+
+ if (part == null)
+ continue;
+
+ SavePartToDXF(part, item.Component.ReferencedConfiguration, savepath);
+ Application.DoEvents();
+ }
+ }
+
+ private static int? FindItemNumberColumn(TableAnnotation table)
+ {
+ try
+ {
+ if (table.RowCount == 0 || table.ColumnCount == 0)
+ return null;
+
+ var consecutiveNumberCountPerColumn = new int[table.ColumnCount];
+
+ for (int columnIndex = 0; columnIndex < table.ColumnCount; ++columnIndex)
+ {
+ for (int rowIndex = 0; rowIndex < table.RowCount - 1; ++rowIndex)
+ {
+ var currentRowValue = table.Text[rowIndex, columnIndex];
+ var nextRowValue = table.Text[rowIndex + 1, columnIndex];
+
+ int currentRowNum;
+ int nextRowNum;
+
+ if (currentRowValue == null || !int.TryParse(currentRowValue, out currentRowNum))
+ continue; // because currentRowValue is not a number
+
+ if (nextRowValue == null || !int.TryParse(nextRowValue, out nextRowNum))
+ continue; // because nextRowValue is not a number
+
+ if (currentRowNum == (nextRowNum - 1))
+ consecutiveNumberCountPerColumn[columnIndex]++;
+ }
+ }
+
+ int index = 0;
+ int max = consecutiveNumberCountPerColumn[0];
+
+ for (int i = 1; i < consecutiveNumberCountPerColumn.Length; ++i)
+ {
+ if (consecutiveNumberCountPerColumn[i] > max)
+ {
+ index = i;
+ max = consecutiveNumberCountPerColumn[i];
+ }
+ }
+
+ return index;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ private bool SavePartToDXF(PartDoc part, string savePath)
+ {
+ var partModel = part as ModelDoc2;
+ var config = partModel.ConfigurationManager.ActiveConfiguration.Name;
+
+ return SavePartToDXF(part, config, savePath);
+ }
+
+ private bool SavePartToDXF(PartDoc part, string partConfiguration, string savePath)
+ {
+ try
+ {
+ var partModel = part as ModelDoc2;
+
+ if (partModel.IsSheetMetal() == false)
+ {
+ Print(partModel.GetTitle() + " - skipped, not sheet metal");
+ return false;
+ }
+
+ if (templateDrawing == null)
+ templateDrawing = CreateDrawing();
+
+ var sheet = templateDrawing.IGetCurrentSheet();
+ var modelName = Path.GetFileNameWithoutExtension(partModel.GetPathName());
+ sheet.SetName(modelName);
+
+
+ Print(partModel.GetTitle() + " - Creating flat pattern.");
+ SolidWorks.Interop.sldworks.View view;
+ view = templateDrawing.CreateFlatPatternViewFromModelView3(partModel.GetPathName(), partConfiguration, 0, 0, 0, false, false);
+ view.ShowSheetMetalBendNotes = true;
+
+ var drawingModel = templateDrawing as ModelDoc2;
+ drawingModel.ViewZoomtofit2();
+
+ if (ShouldFlipView(view))
+ {
+ Print(partModel.GetTitle() + " - Flipped view", Color.Blue);
+ view.FlipView = true;
+ }
+
+ drawingModel.SaveAs(savePath);
+
+ Print(partModel.GetTitle() + " - Saved to \"" + savePath + "\"", Color.Green);
+ Print("");
+
+ drawingModel.SelectByName(0, view.Name);
+ drawingModel.DeleteSelection(false);
+
+ return true;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message);
+ return false;
+ }
+ }
+
+ private string GetSaveDir()
+ {
+ string path = null;
+
+ Invoke(new MethodInvoker(() =>
+ {
+ var dlg = new FolderBrowserDialog();
+ dlg.Description = "Where do you want to save the DXF files?";
+
+ path = dlg.ShowDialog() == DialogResult.OK ? dlg.SelectedPath : null;
+ }));
+
+ return path;
+ }
+
+ private bool ShouldFlipView(SolidWorks.Interop.sldworks.View view)
+ {
+ var notes = (view.GetNotes() as Array)?.Cast();
+
+ var upCount = 0;
+ var dnCount = 0;
+
+ Note leftMost = null;
+ double leftMostValue = double.MaxValue;
+
+ foreach (var note in notes)
+ {
+ var pt = (note.GetTextPoint() as double[]);
+
+ if (pt[0] < leftMostValue)
+ {
+ leftMostValue = pt[0];
+ leftMost = note;
+ }
+
+ var txt = note.GetText();
+
+ if (txt.ToUpper().Contains("UP"))
+ upCount++;
+ else
+ dnCount++;
+ }
+
+ Print(string.Format("Found {0} bends, {1} UP, {2} DOWN", notes.Count(), upCount, dnCount), Color.Blue);
+
+ if (dnCount == upCount && leftMost != null)
+ return !leftMost.GetText().Contains("UP");
+
+ return dnCount > upCount;
+ }
+
+ private string DrawingTemplatePath
+ {
+ get { return Path.Combine(Application.StartupPath, "Templates", "Blank.drwdot"); }
+ }
+
+ private DrawingDoc CreateDrawing()
+ {
+ return sldWorks.NewDocument(
+ DrawingTemplatePath,
+ (int)swDwgPaperSizes_e.swDwgPaperDsize,
+ 1,
+ 1) as DrawingDoc;
+ }
+
+ private List GetBomTables(DrawingDoc drawing)
+ {
+ var model = drawing as ModelDoc2;
+
+ return model.GetAllFeaturesByTypeName("BomFeat")
+ .Select(f => f.GetSpecificFeature2() as BomFeature)
+ .Select(f => (f.GetTableAnnotations() as Array)?.Cast().FirstOrDefault())
+ .ToList();
+ }
+
+ private List
- GetItems(BomTableAnnotation bom)
+ {
+ var items = new List
- ();
+
+ var table = bom as TableAnnotation;
+
+ var itemNumColumnFound = FindItemNumberColumn(bom as TableAnnotation);
+
+ if (itemNumColumnFound == null)
+ {
+ Print("Error: Item number column not found.");
+ return null;
+ }
+ else
+ {
+ Print("Item numbers are in the " + Helper.GetNumWithSuffix(itemNumColumnFound.Value + 1) + " column.");
+ }
+
+ var isBOMPartsOnly = bom.BomFeature.TableType == (int)swBomType_e.swBomType_PartsOnly;
+
+ for (int rowIndex = 0; rowIndex < table.RowCount; rowIndex++)
+ {
+ if (table.RowHidden[rowIndex] == true)
+ continue;
+
+ var bomComponents = isBOMPartsOnly ?
+ ((Array)bom.GetComponents2(rowIndex, bom.BomFeature.Configuration))?.Cast() :
+ ((Array)bom.GetComponents(rowIndex))?.Cast();
+
+ if (bomComponents == null)
+ continue;
+
+ var distinctComponents = bomComponents
+ .GroupBy(c => c.ReferencedConfiguration)
+ .Select(group => group.First());
+
+ var itemNumber = table.Text[rowIndex, itemNumColumnFound.Value].PadLeft(2, '0');
+ var rev = 'A';
+
+ if (distinctComponents.Count() > 1)
+ {
+ foreach (var comp in distinctComponents)
+ {
+ items.Add(new Item
+ {
+ Name = itemNumber + rev++,
+ Component = comp
+ });
+ }
+ }
+ else
+ {
+ items.Add(new Item
+ {
+ Name = itemNumber,
+ Component = distinctComponents.First()
+ });
+ }
+ }
+
+ return items;
+ }
+
+ private List
- GetItems(AssemblyDoc assembly, bool topLevel)
+ {
+ var list = new List
- ();
+
+ assembly.ResolveAllLightWeightComponents(false);
+
+ var assemblyComponents = ((Array)assembly.GetComponents(topLevel))
+ .Cast()
+ .Where(c => !c.IsHidden(true));
+
+ var componentGroups = assemblyComponents
+ .GroupBy(c => c.GetTitle() + c.ReferencedConfiguration);
+
+ foreach (var group in componentGroups)
+ {
+ var component = group.First();
+
+ var name = component.ReferencedConfiguration.ToLower() == "default" ?
+ component.GetTitle() :
+ string.Format("{0} [{1}]", component.GetTitle(), component.ReferencedConfiguration);
+
+ list.Add(new Item
+ {
+ Name = name,
+ Quantity = group.Count(),
+ Component = component
+ });
+ }
+
+ return list;
+ }
+
+ private void button2_Click(object sender, EventArgs e)
+ {
+
+ }
+ }
+
+ public static class Helper
+ {
+ public static Feature GetFeatureByTypeName(this ModelDoc2 model, string featureName)
+ {
+ var feature = model.FirstFeature() as Feature;
+
+ while (feature != null)
+ {
+ if (feature.GetTypeName() == featureName)
+ return feature;
+
+ feature = feature.GetNextFeature() as Feature;
+ }
+
+ return feature;
+ }
+
+ public static List GetAllFeaturesByTypeName(this ModelDoc2 model, string featureName)
+ {
+ var feature = model.FirstFeature() as Feature;
+ var list = new List();
+
+ while (feature != null)
+ {
+ if (feature.GetTypeName() == featureName)
+ list.Add(feature);
+
+ feature = feature.GetNextFeature() as Feature;
+ }
+
+ return list;
+ }
+
+ public static bool HasFlatPattern(this ModelDoc2 model)
+ {
+ return model.GetBendState() != (int)swSMBendState_e.swSMBendStateNone;
+ }
+
+ public static bool IsSheetMetal(this ModelDoc2 model)
+ {
+ if (model is PartDoc == false)
+ return false;
+
+ if (model.HasFlatPattern() == false)
+ return false;
+
+ return true;
+ }
+
+ public static bool IsPart(this ModelDoc2 model)
+ {
+ return model is PartDoc;
+ }
+
+ public static bool IsDrawing(this ModelDoc2 model)
+ {
+ return model is DrawingDoc;
+ }
+
+ public static bool IsAssembly(this ModelDoc2 model)
+ {
+ return model is AssemblyDoc;
+ }
+
+ public static string GetTitle(this Component2 component)
+ {
+ var model = component.GetModelDoc2() as ModelDoc2;
+ return model.GetTitle();
+ }
+
+ public static void AppendText(this RichTextBox box, string text, Color color)
+ {
+ box.SelectionStart = box.TextLength;
+ box.SelectionLength = 0;
+
+ box.SelectionColor = color;
+ box.AppendText(text);
+ box.SelectionColor = box.ForeColor;
+ }
+
+ public static string ToReadableFormat(this TimeSpan ts)
+ {
+ var s = new StringBuilder();
+
+ if (ts.TotalHours >= 1)
+ {
+ var hrs = ts.Hours + ts.Days * 24.0;
+
+ s.Append(string.Format("{0}hrs ", hrs));
+ s.Append(string.Format("{0}min ", ts.Minutes));
+ s.Append(string.Format("{0}sec", ts.Seconds));
+ }
+ else if (ts.TotalMinutes >= 1)
+ {
+ s.Append(string.Format("{0}min ", ts.Minutes));
+ s.Append(string.Format("{0}sec", ts.Seconds));
+ }
+ else
+ {
+ s.Append(string.Format("{0} seconds", ts.Seconds));
+ }
+
+ return s.ToString();
+ }
+
+ public static string GetNumWithSuffix(int i)
+ {
+ if (i >= 11 && i <= 13)
+ return i.ToString() + "th";
+
+ var j = i % 10;
+
+ switch (j)
+ {
+ case 1: return i.ToString() + "st";
+ case 2: return i.ToString() + "nd";
+ case 3: return i.ToString() + "rd";
+ default: return i.ToString() + "th";
+ }
+ }
+ }
+
+ public class Item
+ {
+ public string Name { get; set; }
+
+ public int Quantity { get; set; }
+
+ public Component2 Component { get; set; }
+ }
+}
diff --git a/ExportDXF/Forms/MainForm.resx b/ExportDXF/Forms/MainForm.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/ExportDXF/Forms/MainForm.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ExportDXF/Program.cs b/ExportDXF/Program.cs
new file mode 100644
index 0000000..12da93b
--- /dev/null
+++ b/ExportDXF/Program.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+
+namespace ExportDXF
+{
+ static class Program
+ {
+ ///
+ /// The main entry point for the application.
+ ///
+ [STAThread]
+ static void Main()
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Application.Run(new Forms.MainForm());
+ }
+ }
+}
diff --git a/ExportDXF/Properties/AssemblyInfo.cs b/ExportDXF/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..c56f72e
--- /dev/null
+++ b/ExportDXF/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ExportDXF")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ExportDXF")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("05f21d73-fd31-4e77-8d9b-41c86d4d8305")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/ExportDXF/Properties/Resources.Designer.cs b/ExportDXF/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..431c9de
--- /dev/null
+++ b/ExportDXF/Properties/Resources.Designer.cs
@@ -0,0 +1,93 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace ExportDXF.Properties {
+ using System;
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ExportDXF.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap edit_alt {
+ get {
+ object obj = ResourceManager.GetObject("edit_alt", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap play {
+ get {
+ object obj = ResourceManager.GetObject("play", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap stop_alt {
+ get {
+ object obj = ResourceManager.GetObject("stop_alt", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+ }
+}
diff --git a/ExportDXF/Properties/Resources.resx b/ExportDXF/Properties/Resources.resx
new file mode 100644
index 0000000..1eae97b
--- /dev/null
+++ b/ExportDXF/Properties/Resources.resx
@@ -0,0 +1,130 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+
+ ..\Resources\edit_alt.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\play.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\stop_alt.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
\ No newline at end of file
diff --git a/ExportDXF/Properties/Settings.Designer.cs b/ExportDXF/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..b72cffc
--- /dev/null
+++ b/ExportDXF/Properties/Settings.Designer.cs
@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace ExportDXF.Properties
+{
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
+ {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default
+ {
+ get
+ {
+ return defaultInstance;
+ }
+ }
+ }
+}
diff --git a/ExportDXF/Properties/Settings.settings b/ExportDXF/Properties/Settings.settings
new file mode 100644
index 0000000..3964565
--- /dev/null
+++ b/ExportDXF/Properties/Settings.settings
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/ExportDXF/Resources/edit_alt.png b/ExportDXF/Resources/edit_alt.png
new file mode 100644
index 0000000..6117f96
Binary files /dev/null and b/ExportDXF/Resources/edit_alt.png differ
diff --git a/ExportDXF/Resources/play.png b/ExportDXF/Resources/play.png
new file mode 100644
index 0000000..991db6f
Binary files /dev/null and b/ExportDXF/Resources/play.png differ
diff --git a/ExportDXF/Resources/stop_alt.png b/ExportDXF/Resources/stop_alt.png
new file mode 100644
index 0000000..a48c240
Binary files /dev/null and b/ExportDXF/Resources/stop_alt.png differ
diff --git a/ExportDXF/Templates/Blank.drwdot b/ExportDXF/Templates/Blank.drwdot
new file mode 100644
index 0000000..56fc40d
Binary files /dev/null and b/ExportDXF/Templates/Blank.drwdot differ