属性
Name | Description | 备注 |
ActiveConfiguration | Gets the active configuration. | 获取活动配置。 |
Document | Gets the related model document. | 获取相关模型文档。 |
EnableConfigurationTree | Gets or sets whether to update the ConfigurationManager tree. | 获取或设置是否更新 ConfigurationManager 树。 |
LinkDisplayStatesToConfigurations | Gets or sets whether to link or unlink display states to or from the active configuration. | 获取或设置是将显示状态链接到活动配置还是从活动配置取消链接。 |
ShowConfigurationDescriptions | Gets or sets whether to display configuration descriptions in ConfigurationManager. | 获取或设置是否在 ConfigurationManager 中显示配置描述。 |
ShowConfigurationNames | Gets or sets whether to display configuration names in ConfigurationManager. | 获取或设置是否在 ConfigurationManager 中显示配置名称。 |
ShowPreview | Gets or sets whether to display the preview of a selected configuration. | 获取或设置是否显示选定配置的预览。 |
//This example shows how to traverse an assembly at the component and feature levels //using recursion.
//--------------------------------------------------------------------------
// Preconditions:
// 1. Open an assembly document containing nested subassemblies.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Traverses the assembly.
// 2. Examine the Immediate Window.
//---------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
namespace RecursiveTraverseAssemblyCSharp.csproj
{
public partial class SolidWorksMacro
{
public void TraverseFeatureFeatures(Feature swFeat, long nLevel)
{
Feature swSubFeat;
Feature swSubSubFeat;
Feature swSubSubSubFeat;
string sPadStr = " ";
long i = 0;
for (i = 0; i <= nLevel; i++)
{
sPadStr = sPadStr + " ";
}
while ((swFeat != null))
{
Debug.Print(sPadStr + swFeat.Name + " [" + swFeat.GetTypeName2() + "]");
swSubFeat = (Feature)swFeat.GetFirstSubFeature();
while ((swSubFeat != null))
{
Debug.Print(sPadStr + " " + swSubFeat.Name + " [" + swSubFeat.GetTypeName() + "]");
swSubSubFeat = (Feature)swSubFeat.GetFirstSubFeature();
while ((swSubSubFeat != null))
{
Debug.Print(sPadStr + " " + swSubSubFeat.Name + " [" + swSubSubFeat.GetTypeName() + "]");
swSubSubSubFeat = (Feature)swSubSubFeat.GetFirstSubFeature();
while ((swSubSubSubFeat != null))
{
Debug.Print(sPadStr + " " + swSubSubSubFeat.Name + " [" + swSubSubSubFeat.GetTypeName() + "]");
swSubSubSubFeat = (Feature)swSubSubSubFeat.GetNextSubFeature();
}
swSubSubFeat = (Feature)swSubSubFeat.GetNextSubFeature();
}
swSubFeat = (Feature)swSubFeat.GetNextSubFeature();
}
swFeat = (Feature)swFeat.GetNextFeature();
}
}
public void TraverseComponentFeatures(Component2 swComp, long nLevel)
{
Feature swFeat;
swFeat = (Feature)swComp.FirstFeature();
TraverseFeatureFeatures(swFeat, nLevel);
}
public void TraverseComponent(Component2 swComp, long nLevel)
{
object[] vChildComp;
Component2 swChildComp;
string sPadStr = " ";
long i = 0;
for (i = 0; i <= nLevel - 1; i++)
{
sPadStr = sPadStr + " ";
}
vChildComp = (object[])swComp.GetChildren();
for (i = 0; i < vChildComp.Length; i++)
{
swChildComp = (Component2)vChildComp[i];
Debug.Print(sPadStr + "+" + swChildComp.Name2 + " <" + swChildComp.ReferencedConfiguration + ">");
TraverseComponentFeatures(swChildComp, nLevel);
TraverseComponent(swChildComp, nLevel + 1);
}
}
public void TraverseModelFeatures(ModelDoc2 swModel, long nLevel)
{
Feature swFeat;
swFeat = (Feature)swModel.FirstFeature();
TraverseFeatureFeatures(swFeat, nLevel);
}
public void Main()
{
ModelDoc2 swModel;
ConfigurationManager swConfMgr;
Configuration swConf;
Component2 swRootComp;
swModel = (ModelDoc2)swApp.ActiveDoc;
swConfMgr = (ConfigurationManager)swModel.ConfigurationManager;
swConf = (Configuration)swConfMgr.ActiveConfiguration;
swRootComp = (Component2)swConf.GetRootComponent();
System.Diagnostics.Stopwatch myStopwatch = new Stopwatch();
myStopwatch.Start();
Debug.Print("File = " + swModel.GetPathName());
TraverseModelFeatures(swModel, 1);
if (swModel.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
{
TraverseComponent(swRootComp, 1);
}
myStopwatch.Stop();
TimeSpan myTimespan = myStopwatch.Elapsed;
Debug.Print("Time = " + myTimespan.TotalSeconds + " sec");
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
This example shows how to link and unlink display states to and from configurations.
// ---------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\pdmworks\speaker.sldasm
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Gets and sets whether display states are linked to the
// active configuration.
// 2. Closes the assembly document without saving
// any changes.
//-----------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace LinkDisplayStatesToConfigurationCSharp.csproj
{
partial class SolidWorksMacro
{
public void Main()
{
ModelDoc2 swModel = default(ModelDoc2);
ConfigurationManager swConfigMgr = default(ConfigurationManager);
string assemblyName = null;
swModel = (ModelDoc2)swApp.ActiveDoc;
Debug.Print("");
swConfigMgr = (ConfigurationManager)swModel.ConfigurationManager;
swConfigMgr.LinkDisplayStatesToConfigurations = false;
Debug.Print("Are display states linked to configurations? " + swConfigMgr.LinkDisplayStatesToConfigurations);
if (!swConfigMgr.LinkDisplayStatesToConfigurations)
{
Debug.Print("All display states are available to the active configuration.");
}
swConfigMgr.LinkDisplayStatesToConfigurations = true;
Debug.Print("Are display states linked configurations? " + swConfigMgr.LinkDisplayStatesToConfigurations);
if (swConfigMgr.LinkDisplayStatesToConfigurations)
{
Debug.Print("All display states are not available to the active configuration.");
}
assemblyName = swModel.GetTitle();
swApp.QuitDoc(assemblyName);
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
方法
Name | Description | 备注 |
AddConfiguration2 | Creates a new configuration. | 创建新配置。 |
AddRebuildSaveMark | Adds marks indicating whether the specified configurations need to be rebuilt and their configuration data saved every time the model document is saved. | 添加标记,指示每次保存模型文档时是否需要重新构建指定的配置及其配置数据。 |
AddSpeedPak2 | Creates a SpeedPak configuration that includes all faces and the specified threshold of parts or bodies for the active assembly configuration. | 创建 SpeedPak 配置,其中包括活动装配配置的所有面和零件或实体的指定阈值。 |
GetConfigurationParams | Gets the parameters for this configuration. | 获取此配置的参数。 |
GetConfigurationParamsCount | Gets the number of parameters for this configuration. | 获取此配置的参数数量。 |
IGetConfigurationParams | Gets the parameters for this configuration. | 获取此配置的参数。 |
ISetConfigurationParams | Sets the parameters for this configuration. | 设置此配置的参数。 |
RemoveMarkForAllConfigurations | Remove all marks indicating whether configurations need to be rebuilt and their configuration data saved every time the model document is saved. | 每次保存模型文档时,删除所有指示是否需要重建配置和保存配置数据的标记。 |
SetConfigurationParams | Sets the parameters for this configuration. | 设置此配置的参数。 |
SetExpanded | Sets whether to display and expand all of the configuration nodes in the specified pane of the ConfigurationManager. | 设置是否在 ConfigurationManager 的指定窗格中显示和展开所有配置节点。 |
SortConfigurationTree | Specifies the order in which to list configurations in the ConfigurationManager. | 指定在 ConfigurationManager 中列出配置的顺序。 |
This example shows how to link and unlink display states to and from configurations.
// ---------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\pdmworks\speaker.sldasm
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Gets and sets whether display states are linked to the
// active configuration.
// 2. Closes the assembly document without saving
// any changes.
//-----------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
namespace LinkDisplayStatesToConfigurationCSharp.csproj
{
partial class SolidWorksMacro
{
public void Main()
{
ModelDoc2 swModel = default(ModelDoc2);
ConfigurationManager swConfigMgr = default(ConfigurationManager);
string assemblyName = null;
swModel = (ModelDoc2)swApp.ActiveDoc;
Debug.Print("");
swConfigMgr = (ConfigurationManager)swModel.ConfigurationManager;
swConfigMgr.LinkDisplayStatesToConfigurations = false;
Debug.Print("Are display states linked to configurations? " + swConfigMgr.LinkDisplayStatesToConfigurations);
if (!swConfigMgr.LinkDisplayStatesToConfigurations)
{
Debug.Print("All display states are available to the active configuration.");
}
swConfigMgr.LinkDisplayStatesToConfigurations = true;
Debug.Print("Are display states linked configurations? " + swConfigMgr.LinkDisplayStatesToConfigurations);
if (swConfigMgr.LinkDisplayStatesToConfigurations)
{
Debug.Print("All display states are not available to the active configuration.");
}
assemblyName = swModel.GetTitle();
swApp.QuitDoc(assemblyName);
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
This example shows how to specify the order in which to list configurations in the ConfigurationManager.
//-------------------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\driveworksxpress\mobile gantry.sldasm.
// 2. Click the ConfigurationManager tab and examine the order in which the
// configurations are listed.
//
// Preconditions:
// 1. Lists the configurations in the specified order.
// 2. Examine the ConfigurationManager tab.
//
// NOTE: Because the assembly is used elsewhere, do not save changes.
//-------------------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
namespace Macro1CSharp.csproj
{
public partial class SolidWorksMacro
{
public void Main()
{
ModelDoc2 swModel = default(ModelDoc2);
ConfigurationManager swConfigMgr = default(ConfigurationManager);
swModel = (ModelDoc2)swApp.ActiveDoc;
swConfigMgr = (ConfigurationManager)swModel.ConfigurationManager;
swConfigMgr.SortConfigurationTree((int)swConfigTreeSortType_e.swSortType_Literal);
swModel.EditRebuild3();
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}