![](/img/trans.png)
[英]C# / inherit methods and properties from COM Reference (SolidWorks API)
[英]Solidworks C# can't extract item from feature that has TypeName equals "Reference"
我已经使用 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();
}
}
问题:每次我尝试提取特征(一部分)下的项目时都会遇到异常,我必须尝试以下方法:
您的代码仅迭代顶级功能。 您可以使用 IFeature::GetFirstSubFeature() 和 IFeature::GetNextSubFeature 来获取子功能。 使这个 function 成为递归的,这样它就可以遍历所有的特征,不管它们有多深。 您需要考虑的另一层是组件 - 如果您需要单个零件上下文中的特征数据,则需要首先迭代装配中的组件。
这是Solidworks API 文档中的示例。 它写得不好(IMO),但它会引导你朝着正确的方向前进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.