Moved ItemExtractors to separate namespace.
This commit is contained in:
@@ -94,7 +94,10 @@
|
||||
<Compile Include="DrawingInfo.cs" />
|
||||
<Compile Include="BomToExcel.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="ItemExtractor.cs" />
|
||||
<Compile Include="ItemExtractors\AssemblyItemExtractor.cs" />
|
||||
<Compile Include="ItemExtractors\BomColumnIndices.cs" />
|
||||
<Compile Include="ItemExtractors\BomItemExtractor.cs" />
|
||||
<Compile Include="ItemExtractors\ItemExtractor.cs" />
|
||||
<Compile Include="Forms\ViewFlipDeciderComboboxItem.cs" />
|
||||
<Compile Include="Item.cs" />
|
||||
<Compile Include="IViewFlipDecider.cs" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using OfficeOpenXml;
|
||||
using ExportDXF.ItemExtractors;
|
||||
using OfficeOpenXml;
|
||||
using SolidWorks.Interop.sldworks;
|
||||
using SolidWorks.Interop.swconst;
|
||||
using System;
|
||||
|
||||
64
ExportDXF/ItemExtractors/AssemblyItemExtractor.cs
Normal file
64
ExportDXF/ItemExtractors/AssemblyItemExtractor.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using SolidWorks.Interop.sldworks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace ExportDXF.ItemExtractors
|
||||
{
|
||||
public class AssemblyItemExtractor : ItemExtractor
|
||||
{
|
||||
private AssemblyDoc assembly;
|
||||
|
||||
public AssemblyItemExtractor(AssemblyDoc assembly)
|
||||
{
|
||||
this.assembly = assembly;
|
||||
}
|
||||
|
||||
public bool TopLevelOnly { get; set; }
|
||||
|
||||
private string GetComponentName(Component2 component)
|
||||
{
|
||||
var filepath = component.GetTitle();
|
||||
var filename = Path.GetFileNameWithoutExtension(filepath);
|
||||
var isDefaultConfig = component.ReferencedConfiguration.ToLower() == "default";
|
||||
|
||||
return isDefaultConfig ? filename : $"{filename} [{component.ReferencedConfiguration}]";
|
||||
}
|
||||
|
||||
public List<Item> GetItems()
|
||||
{
|
||||
var list = new List<Item>();
|
||||
|
||||
assembly.ResolveAllLightWeightComponents(false);
|
||||
|
||||
var assemblyComponents = ((Array)assembly.GetComponents(TopLevelOnly))
|
||||
.Cast<Component2>()
|
||||
.Where(c => !c.IsHidden(true));
|
||||
|
||||
var componentGroups = assemblyComponents
|
||||
.GroupBy(c => c.GetTitle() + c.ReferencedConfiguration);
|
||||
|
||||
foreach (var group in componentGroups)
|
||||
{
|
||||
var component = group.First();
|
||||
var model = component.GetModelDoc2() as ModelDoc2;
|
||||
|
||||
if (model == null)
|
||||
continue;
|
||||
|
||||
var name = GetComponentName(component);
|
||||
|
||||
list.Add(new Item
|
||||
{
|
||||
PartName = name,
|
||||
Quantity = group.Count(),
|
||||
Component = component,
|
||||
Configuration = component.ReferencedConfiguration
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
ExportDXF/ItemExtractors/BomColumnIndices.cs
Normal file
13
ExportDXF/ItemExtractors/BomColumnIndices.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace ExportDXF.ItemExtractors
|
||||
{
|
||||
public class BomColumnIndices
|
||||
{
|
||||
public int ItemNumber { get; set; } = -1;
|
||||
|
||||
public int Quantity { get; set; } = -1;
|
||||
|
||||
public int Description { get; set; } = -1;
|
||||
|
||||
public int PartNumber { get; set; } = -1;
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,10 @@
|
||||
using SolidWorks.Interop.swconst;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace ExportDXF
|
||||
namespace ExportDXF.ItemExtractors
|
||||
{
|
||||
public interface ItemExtractor
|
||||
{
|
||||
List<Item> GetItems();
|
||||
}
|
||||
|
||||
public class BomItemExtractor : ItemExtractor
|
||||
{
|
||||
private BomTableAnnotation bom;
|
||||
@@ -142,71 +136,4 @@ namespace ExportDXF
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
||||
public class AssemblyItemExtractor : ItemExtractor
|
||||
{
|
||||
private AssemblyDoc assembly;
|
||||
|
||||
public AssemblyItemExtractor(AssemblyDoc assembly)
|
||||
{
|
||||
this.assembly = assembly;
|
||||
}
|
||||
|
||||
public bool TopLevelOnly { get; set; }
|
||||
|
||||
private string GetComponentName(Component2 component)
|
||||
{
|
||||
var filepath = component.GetTitle();
|
||||
var filename = Path.GetFileNameWithoutExtension(filepath);
|
||||
var isDefaultConfig = component.ReferencedConfiguration.ToLower() == "default";
|
||||
|
||||
return isDefaultConfig ? filename : $"{filename} [{component.ReferencedConfiguration}]";
|
||||
}
|
||||
|
||||
public List<Item> GetItems()
|
||||
{
|
||||
var list = new List<Item>();
|
||||
|
||||
assembly.ResolveAllLightWeightComponents(false);
|
||||
|
||||
var assemblyComponents = ((Array)assembly.GetComponents(TopLevelOnly))
|
||||
.Cast<Component2>()
|
||||
.Where(c => !c.IsHidden(true));
|
||||
|
||||
var componentGroups = assemblyComponents
|
||||
.GroupBy(c => c.GetTitle() + c.ReferencedConfiguration);
|
||||
|
||||
foreach (var group in componentGroups)
|
||||
{
|
||||
var component = group.First();
|
||||
var model = component.GetModelDoc2() as ModelDoc2;
|
||||
|
||||
if (model == null)
|
||||
continue;
|
||||
|
||||
var name = GetComponentName(component);
|
||||
|
||||
list.Add(new Item
|
||||
{
|
||||
PartName = name,
|
||||
Quantity = group.Count(),
|
||||
Component = component,
|
||||
Configuration = component.ReferencedConfiguration
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public class BomColumnIndices
|
||||
{
|
||||
public int ItemNumber { get; set; } = -1;
|
||||
|
||||
public int Quantity { get; set; } = -1;
|
||||
|
||||
public int Description { get; set; } = -1;
|
||||
|
||||
public int PartNumber { get; set; } = -1;
|
||||
}
|
||||
}
|
||||
9
ExportDXF/ItemExtractors/ItemExtractor.cs
Normal file
9
ExportDXF/ItemExtractors/ItemExtractor.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ExportDXF.ItemExtractors
|
||||
{
|
||||
public interface ItemExtractor
|
||||
{
|
||||
List<Item> GetItems();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user