![](/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.