[英]Solidworks C# can't extract item from feature that has TypeName equals "Reference"
i have opened solidworks assembly (swDocumentTypes_e.swDocASSEMBLY) using C# and i have iterated through all the features in order to get all the Sketchs called 'ISO/XXX' under each part of the assembly, here is the code我已经使用 C# 打开了solidworks组件(swDocumentTypes_e.swDocASSEMBLY),并且我已经迭代了所有功能,以便在组件的每个部分下获得所有名为“ISO/XXX”的草图,这是代码
public void openFile(string skeletonFilePath)
{
object[] Features = null;
int i = 0;
string FeatType = null;[1]
string FeatTypeName = null;
if (string.IsNullOrWhiteSpace(skeletonFilePath)) { return; }
ModelDoc2 model = _sldWorks.OpenDoc("C:PATH/fileName.SLDASM", (int)swDocumentTypes_e.swDocASSEMBLY);
Feature swFeat = default(Feature);
SelectionMgr swSelMgr = default(SelectionMgr);
swSelMgr = (SelectionMgr)model.SelectionManager;
swFeat = (Feature)model.FirstFeature();
while ((swFeat != null))
{
FeatType = swFeat.Name;
FeatTypeName = swFeat.GetTypeName2();
if ((FeatTypeName == "Reference")
{
Debug.Print(" Name of feature: " + swFeat.Name);
Debug.Print(" Type of feature: " + swFeat.GetTypeName2());
}
swFeat = (Feature)swFeat.GetNextFeature();
}
}
the problem : each time i try to extract the items under the feature (of one part) i got an exception, i have to tried these ways:问题:每次我尝试提取特征(一部分)下的项目时都会遇到异常,我必须尝试以下方法:
Your code is only iterating over top level features.您的代码仅迭代顶级功能。 You can use IFeature::GetFirstSubFeature() and IFeature::GetNextSubFeature to get sub feature.
您可以使用 IFeature::GetFirstSubFeature() 和 IFeature::GetNextSubFeature 来获取子功能。 Make this function recursive so it will iterate over all features, regardless of how many levels deep they are.
使这个 function 成为递归的,这样它就可以遍历所有的特征,不管它们有多深。 Another layer you need to consider is the components - you need to iterate over components in an assembly first if you need feature data in the context of individual parts.
您需要考虑的另一层是组件 - 如果您需要单个零件上下文中的特征数据,则需要首先迭代装配中的组件。
Here's an example from the Solidworks API documentation. 这是Solidworks API 文档中的示例。 Its poorly written (IMO) but it will guide you in the right direction.
它写得不好(IMO),但它会引导你朝着正确的方向前进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.