Moved classes to their own file.
This commit is contained in:
@@ -85,6 +85,7 @@
|
|||||||
<Compile Include="BendOrientation.cs" />
|
<Compile Include="BendOrientation.cs" />
|
||||||
<Compile Include="Bounds.cs" />
|
<Compile Include="Bounds.cs" />
|
||||||
<Compile Include="DrawingInfo.cs" />
|
<Compile Include="DrawingInfo.cs" />
|
||||||
|
<Compile Include="Extensions.cs" />
|
||||||
<Compile Include="Forms\ViewFlipDeciderComboboxItem.cs" />
|
<Compile Include="Forms\ViewFlipDeciderComboboxItem.cs" />
|
||||||
<Compile Include="Item.cs" />
|
<Compile Include="Item.cs" />
|
||||||
<Compile Include="IViewFlipDecider.cs" />
|
<Compile Include="IViewFlipDecider.cs" />
|
||||||
@@ -97,6 +98,8 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="SolidWorksExtensions.cs" />
|
||||||
|
<Compile Include="Units.cs" />
|
||||||
<Compile Include="ViewHelper.cs" />
|
<Compile Include="ViewHelper.cs" />
|
||||||
<EmbeddedResource Include="Forms\MainForm.resx">
|
<EmbeddedResource Include="Forms\MainForm.resx">
|
||||||
<DependentUpon>MainForm.cs</DependentUpon>
|
<DependentUpon>MainForm.cs</DependentUpon>
|
||||||
|
|||||||
45
ExportDXF/Extensions.cs
Normal file
45
ExportDXF/Extensions.cs
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,4 @@
|
|||||||
using SolidWorks.Interop.sldworks;
|
namespace ExportDXF
|
||||||
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
|
|
||||||
{
|
{
|
||||||
public static class Helper
|
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<Feature> GetAllFeaturesByTypeName(this ModelDoc2 model, string featureName)
|
|
||||||
{
|
|
||||||
var feature = model.FirstFeature() as Feature;
|
|
||||||
var list = new List<Feature>();
|
|
||||||
|
|
||||||
while (feature != null)
|
|
||||||
{
|
|
||||||
var name = feature.GetTypeName();
|
|
||||||
|
|
||||||
if (name == featureName)
|
|
||||||
list.Add(feature);
|
|
||||||
|
|
||||||
feature = feature.GetNextFeature() as Feature;
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Feature> GetAllSubFeaturesByTypeName(this Feature feature, string subFeatureName)
|
|
||||||
{
|
|
||||||
var subFeature = feature.GetFirstSubFeature() as Feature;
|
|
||||||
var list = new List<Feature>();
|
|
||||||
|
|
||||||
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<string> 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
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Multiply factor needed to convert the desired units to meters.
|
|
||||||
/// </summary>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
158
ExportDXF/SolidWorksExtensions.cs
Normal file
158
ExportDXF/SolidWorksExtensions.cs
Normal file
@@ -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<Feature> GetAllFeaturesByTypeName(this ModelDoc2 model, string featureName)
|
||||||
|
{
|
||||||
|
var feature = model.FirstFeature() as Feature;
|
||||||
|
var list = new List<Feature>();
|
||||||
|
|
||||||
|
while (feature != null)
|
||||||
|
{
|
||||||
|
var name = feature.GetTypeName();
|
||||||
|
|
||||||
|
if (name == featureName)
|
||||||
|
list.Add(feature);
|
||||||
|
|
||||||
|
feature = feature.GetNextFeature() as Feature;
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Feature> GetAllSubFeaturesByTypeName(this Feature feature, string subFeatureName)
|
||||||
|
{
|
||||||
|
var subFeature = feature.GetFirstSubFeature() as Feature;
|
||||||
|
var list = new List<Feature>();
|
||||||
|
|
||||||
|
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<string> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
ExportDXF/Units.cs
Normal file
22
ExportDXF/Units.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ExportDXF
|
||||||
|
{
|
||||||
|
public static class Units
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Multiply factor needed to convert the desired units to meters.
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user