diff --git a/ExportDXF/ExportDXF.csproj b/ExportDXF/ExportDXF.csproj index 34864e5..d4e26b7 100644 --- a/ExportDXF/ExportDXF.csproj +++ b/ExportDXF/ExportDXF.csproj @@ -85,6 +85,7 @@ + @@ -97,6 +98,8 @@ + + MainForm.cs diff --git a/ExportDXF/Extensions.cs b/ExportDXF/Extensions.cs new file mode 100644 index 0000000..47dcaa3 --- /dev/null +++ b/ExportDXF/Extensions.cs @@ -0,0 +1,45 @@ +using System; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace ExportDXF +{ + public static class Extensions + { + 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(); + } + } +} \ No newline at end of file diff --git a/ExportDXF/Helper.cs b/ExportDXF/Helper.cs index 608143b..3fefd7f 100644 --- a/ExportDXF/Helper.cs +++ b/ExportDXF/Helper.cs @@ -1,14 +1,4 @@ -using SolidWorks.Interop.sldworks; -using SolidWorks.Interop.swconst; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; - -namespace ExportDXF +namespace ExportDXF { public static class Helper { @@ -28,211 +18,4 @@ namespace ExportDXF } } } - - public static class SolidWorksExtensions - { - 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) - { - var name = feature.GetTypeName(); - - if (name == featureName) - list.Add(feature); - - feature = feature.GetNextFeature() as Feature; - } - - return list; - } - - public static List GetAllSubFeaturesByTypeName(this Feature feature, string subFeatureName) - { - var subFeature = feature.GetFirstSubFeature() as Feature; - var list = new List(); - - while (subFeature != null) - { - Debug.WriteLine(subFeature.GetTypeName2()); - if (subFeature.GetTypeName() == subFeatureName) - list.Add(subFeature); - - subFeature = subFeature.GetNextSubFeature() 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 int IndexOfColumnType(this TableAnnotation table, swTableColumnTypes_e columnType) - { - for (int columnIndex = 0; columnIndex < table.ColumnCount; ++columnIndex) - { - var currentColumnType = (swTableColumnTypes_e)table.GetColumnType(columnIndex); - - if (currentColumnType == columnType) - return columnIndex; - } - - return -1; - } - - public static int IndexOfColumnTitle(this TableAnnotation table, string columnTitle) - { - var lowercaseColumnTitle = columnTitle.ToLower(); - - for (int columnIndex = 0; columnIndex < table.ColumnCount; ++columnIndex) - { - var currentColumnType = table.GetColumnTitle(columnIndex); - - if (currentColumnType.ToLower() == lowercaseColumnTitle) - return columnIndex; - } - - return -1; - } - - public static Dimension GetDimension(this Feature feature, string dimName) - { - return feature?.Parameter(dimName) as Dimension; - } - - public static string PunctuateList(this IEnumerable stringList) - { - var list = stringList.ToList(); - - switch (list.Count) - { - case 0: - return string.Empty; - - case 1: - return list[0]; - - case 2: - return string.Format("{0} and {1}", list[0], list[1]); - - default: - var s = string.Empty; - - for (int i = 0; i < list.Count - 1; i++) - s += list[i] + ", "; - - s += "and " + list.Last(); - - return s; - } - } - } - - public static class Extensions - { - 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 class Units - { - /// - /// Multiply factor needed to convert the desired units to meters. - /// - public static double ScaleFactor = 0.0254; // inches to meters - - public static double ToSldWorks(this double d) - { - return Math.Round(d * ScaleFactor, 8); - } - - public static double FromSldWorks(this double d) - { - return Math.Round(d / ScaleFactor, 8); - } - } } \ No newline at end of file diff --git a/ExportDXF/SolidWorksExtensions.cs b/ExportDXF/SolidWorksExtensions.cs new file mode 100644 index 0000000..7d7fbee --- /dev/null +++ b/ExportDXF/SolidWorksExtensions.cs @@ -0,0 +1,158 @@ +using SolidWorks.Interop.sldworks; +using SolidWorks.Interop.swconst; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; + +namespace ExportDXF +{ + public static class SolidWorksExtensions + { + 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) + { + var name = feature.GetTypeName(); + + if (name == featureName) + list.Add(feature); + + feature = feature.GetNextFeature() as Feature; + } + + return list; + } + + public static List GetAllSubFeaturesByTypeName(this Feature feature, string subFeatureName) + { + var subFeature = feature.GetFirstSubFeature() as Feature; + var list = new List(); + + while (subFeature != null) + { + Debug.WriteLine(subFeature.GetTypeName2()); + if (subFeature.GetTypeName() == subFeatureName) + list.Add(subFeature); + + subFeature = subFeature.GetNextSubFeature() 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 int IndexOfColumnType(this TableAnnotation table, swTableColumnTypes_e columnType) + { + for (int columnIndex = 0; columnIndex < table.ColumnCount; ++columnIndex) + { + var currentColumnType = (swTableColumnTypes_e)table.GetColumnType(columnIndex); + + if (currentColumnType == columnType) + return columnIndex; + } + + return -1; + } + + public static int IndexOfColumnTitle(this TableAnnotation table, string columnTitle) + { + var lowercaseColumnTitle = columnTitle.ToLower(); + + for (int columnIndex = 0; columnIndex < table.ColumnCount; ++columnIndex) + { + var currentColumnType = table.GetColumnTitle(columnIndex); + + if (currentColumnType.ToLower() == lowercaseColumnTitle) + return columnIndex; + } + + return -1; + } + + public static Dimension GetDimension(this Feature feature, string dimName) + { + return feature?.Parameter(dimName) as Dimension; + } + + public static string PunctuateList(this IEnumerable stringList) + { + var list = stringList.ToList(); + + switch (list.Count) + { + case 0: + return string.Empty; + + case 1: + return list[0]; + + case 2: + return string.Format("{0} and {1}", list[0], list[1]); + + default: + var s = string.Empty; + + for (int i = 0; i < list.Count - 1; i++) + s += list[i] + ", "; + + s += "and " + list.Last(); + + return s; + } + } + } +} \ No newline at end of file diff --git a/ExportDXF/Units.cs b/ExportDXF/Units.cs new file mode 100644 index 0000000..81f0e8a --- /dev/null +++ b/ExportDXF/Units.cs @@ -0,0 +1,22 @@ +using System; + +namespace ExportDXF +{ + public static class Units + { + /// + /// Multiply factor needed to convert the desired units to meters. + /// + public static double ScaleFactor = 0.0254; // inches to meters + + public static double ToSldWorks(this double d) + { + return Math.Round(d * ScaleFactor, 8); + } + + public static double FromSldWorks(this double d) + { + return Math.Round(d / ScaleFactor, 8); + } + } +} \ No newline at end of file