获取特征的轮廓草图实体

基本上任何种类型的特征都基于一定的草图轮廓。如果已知一个特征,可通过Feature.Profile获得所有的轮廓,每一轮廓是一个ProfilePath对象,ProfilePath.TextBoxPath告知是否来自TextBox,ProfilePath.TextBox将返回该TextBox对象。而其余则是普通草图实体图元。

我在全球博客上些了一个小代码:

http://adndevblog.typepad.com/manufacturing/2013/12/get-profile-path-of-feature.html

``` Dim swApp As SldWorks.SldWorks = CreateObject("SldWorks.Application") swApp.Visible = True Dim swModel As ModelDoc2 = swApp.OpenDoc6("D:\Sldworks模型\拉伸(测试).SLDPRT", swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0) ' 确保模型已完全重建 swModel.ForceRebuild3(True) '通过将其转换为PartDoc类型,可以调用零件特有的方法和属性(例如操作特征草图实体等) Dim swPart As SldWorks.PartDoc = swModel Dim swFeature As SldWorks.Feature = swPart.FirstFeature() While swFeature IsNot Nothing Dim featureType As String = swFeature.GetTypeName2() Dim featureName As String = swFeature.Name() '判断是否是需要忽略的特征类型 If Not ShouldIgnoreFeature(featureType) Then Console.WriteLine("特征类型: " & featureType & ", 特征名字 " & featureName) '根据特征类型调用对应处理函数 Select Case featureType Case "Extrusion" '拉伸函数 Dim swExtrusionData As ExtrudeFeatureData2 = CType(swFeature.GetDefinition(), ExtrudeFeatureData2) '获取当前特征swFeature的定义数据,并将其转换为ExtrudeFeatureData2类型 '访问特征选择集(必要步骤) swModel.Extension.SelectByID2(featureName, "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0) '选中对象 swExtrusionData.AccessSelections(swModel, Nothing) '激活特征数据访问权限 '获取关联草图(子特征) Dim swSubFeature As Feature = swFeature.GetFirstSubFeature() While swSubFeature IsNot Nothing Dim subFeatureName As String = swSubFeature.Name() Dim subFeatureType As String = swSubFeature.GetTypeName2() If subFeatureType = "ProfileFeature" Then```通过上述代码,我是不是可以查找到拉伸特征下的子特征,即草图?那么接下来,我如何访问获得草图中的信息
03-29
``` Imports System.Xml Imports SolidWorks.Interop.sldworks Imports SolidWorks.Interop.swconst Imports System.Runtime.InteropServices Imports System Imports System.Diagnostics Module Module1 Sub Main() Dim swApp As SldWorks.SldWorks = CreateObject("SldWorks.Application") swApp.Visible = True Dim swModel As ModelDoc2 = swApp.OpenDoc6("D:\Sldworks模型\拉伸(测试).SLDPRT", swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0) ' 确保模型已完全重建 swModel.ForceRebuild3(True) '通过将其转换为PartDoc类型,可以调用零件特有的方法和属性(例如操作特征草图实体等) Dim swPart As SldWorks.PartDoc = swModel Dim swFeature As SldWorks.Feature = swPart.FirstFeature() While swFeature IsNot Nothing Dim featureType As String = swFeature.GetTypeName2() Dim featureName As String = swFeature.Name() '判断是否是需要忽略的特征类型 If Not ShouldIgnoreFeature(featureType) Then Console.WriteLine("特征类型: " & featureType & ", 特征名字 " & featureName) '根据特征类型调用对应处理函数 Select Case featureType Case "Extrusion" '拉伸函数 Dim swExtrusionData As ExtrudeFeatureData2 = CType(swFeature.GetDefinition(), ExtrudeFeatureData2) '获取当前特征swFeature的定义数据,并将其转换为ExtrudeFeatureData2类型 '访问特征选择集(必要步骤) swModel.Extension.SelectByID2(featureName, "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0) '选中对象 swExtrusionData.AccessSelections(swModel, Nothing) '激活特征数据访问权限 '获取关联草图(子特征) Dim swSubFeature As Feature = swFeature.GetFirstSubFeature() While swSubFeature IsNot Nothing Dim subFeatureName As String = swSubFeature.Name() Dim subFeatureType As String = swSubFeature.GetTypeName2() If subFeatureType = "ProfileFeature" Then Dim swSketch As SldWorks.Sketch = CType(swSubFeature, SldWorks.Sketch) '将swSubFeature对象转换为Sketch类型,获取轮廓特征对应的草图对象 ...... End Select End If swFeature = swFeature.GetNextFeature() End While Console.ReadLine() End Sub End Module```分析上述代码并判断是否有误,并结合上文分析 Dim swSketch As SldWorks.Sketch = CType(swSubFeature, SldWorks.Sketch) 这行代码是否有误,是在干嘛。如果接下里想要进一步获取草图数据,是不是需要使用AccessSelections函数
03-29
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值