Set lightweight components to resolved

This commit is contained in:
AJ
2019-11-27 13:07:33 -05:00
parent 3f24020576
commit a2474fca3b
4 changed files with 40 additions and 47 deletions

View File

@@ -22,8 +22,8 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>21</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.1.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>

View File

@@ -257,7 +257,6 @@ namespace ExportDXF.Forms
var itemExtractor = new BomItemExtractor(bom);
itemExtractor.SkipHiddenRows = true;
Print(bom.BomFeature.Name);
Print($"Fetching components from {bom.BomFeature.Name}");
var bomItems = itemExtractor.GetItems();
@@ -332,7 +331,7 @@ namespace ExportDXF.Forms
var fileName = GetFileName(item);
var savepath = Path.Combine(savePath, fileName + ".dxf");
SetLightweightToResolved(item.Component);
item.Component.SetLightweightToResolved();
var model = item.Component.GetModelDoc2() as ModelDoc2;
var part = model as PartDoc;
@@ -406,37 +405,6 @@ namespace ExportDXF.Forms
}
}
private void SetLightweightToResolved(Component2 component)
{
var isSuppressed = component.IsSuppressed();
if (isSuppressed)
return;
var suppressionState = (swComponentSuppressionState_e)component.GetSuppression();
switch (suppressionState)
{
case swComponentSuppressionState_e.swComponentFullyResolved:
case swComponentSuppressionState_e.swComponentResolved:
return;
case swComponentSuppressionState_e.swComponentFullyLightweight:
case swComponentSuppressionState_e.swComponentLightweight:
var error = (swSuppressionError_e)component.SetSuppression2((int)swComponentSuppressionState_e.swComponentResolved);
if (error == swSuppressionError_e.swSuppressionChangeOk)
{
var model = component.GetModelDoc2() as ModelDoc2;
if (model != null)
{
model.ForceRebuild3(false);
}
}
break;
}
}
private string RemoveFontXml(string s)
{
if (s == null)

View File

@@ -80,32 +80,40 @@ namespace ExportDXF
item.Quantity = qty;
}
item.Component = GetComponent(rowIndex);
return item;
}
private Component2 GetComponent(int rowIndex)
{
var isBOMPartsOnly = bom.BomFeature.TableType == (int)swBomType_e.swBomType_PartsOnly;
List<Component2> components;
IEnumerable<Component2> components;
if (isBOMPartsOnly)
{
components = ((Array)bom.GetComponents2(rowIndex, bom.BomFeature.Configuration))?.Cast<Component2>().ToList();
components = ((Array)bom.GetComponents2(rowIndex, bom.BomFeature.Configuration))?.Cast<Component2>();
}
else
{
components = ((Array)bom.GetComponents(rowIndex))?.Cast<Component2>().ToList();
components = ((Array)bom.GetComponents(rowIndex))?.Cast<Component2>();
}
if (components != null)
if (components == null)
return null;
foreach (var component in components)
{
foreach (var component in components)
{
if (component.IsSuppressed())
continue;
component.SetLightweightToResolved();
item.Component = component;
break;
}
if (component.IsSuppressed())
continue;
return component;
}
return item;
return null;
}
public List<Item> GetItems()

View File

@@ -1,5 +1,6 @@
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -138,5 +139,21 @@ namespace ExportDXF
.ToList();
}
public static void SetLightweightToResolved(this Component2 component)
{
var suppressionState = (swComponentSuppressionState_e)component.GetSuppression();
switch (suppressionState)
{
case swComponentSuppressionState_e.swComponentFullyResolved:
case swComponentSuppressionState_e.swComponentResolved:
return;
case swComponentSuppressionState_e.swComponentFullyLightweight:
case swComponentSuppressionState_e.swComponentLightweight:
var error = (swSuppressionError_e)component.SetSuppression2((int)swComponentSuppressionState_e.swComponentResolved);
break;
}
}
}
}