iCAx开思网
标题:
按设计树顺序遍历装配体
[打印本页]
作者:
wenmk
时间:
2020-4-10 11:15
标题:
按设计树顺序遍历装配体
本帖最后由 wenmk 于 2020-4-11 10:14 编辑
分享一段完整按设计树顺序遍历装配体代码,此代码是VB.NET编写。可以在此代码中添加功能代码后可实现特定功能。
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Dim swApp As SldWorks
Dim swModel As ModelDoc2
Dim swPropMgrs As CustomPropertyManager
Dim swConMgrs As ConfigurationManager
Dim swConfigs As Configuration
Dim swGetType As String
Dim swFeat As Feature
Dim swChild As String
RichTextBox1.Text = ""
swApp = GetObject(, "SldWorks.Application")
If swApp Is Nothing Then
MsgBox("请您在运行本程序前先运行Solidworks!")
Exit Sub
End If
swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox("请您打开模型后再运行!")
Exit Sub
End If
If swModel.GetType <> 2 Then
MsgBox("请您打开装配模型后再运行!")
Exit Sub
End If
swConMgrs = swModel.ConfigurationManager '获取配置管理器
swConfigs = swConMgrs.ActiveConfiguration '获取活动配置
swChild = swConfigs.Name '获取活动配置名
swPropMgrs = swModel.Extension.CustomPropertyManager("") '获得自定义属性
'swPropMgrs = swModel.Extension.CustomPropertyManager(swChild) '获得配置特定属性
swGetType = swModel.GetPathName '获取此文档的完整路径名,包括文件名
RichTextBox1.Text &= swGetType & vbNewLine
swFeat = swModel.FirstFeature
While IsNothing(swFeat) = False
Select Case swFeat.GetTypeName2
Case "Reference", "ReferencePattern" '排除镜像及阵列模型
Throughs(swModel, swFeat.Name)
End Select
swFeat = swFeat.GetNextFeature
End While
End Sub
Private Sub Throughs(ByVal swModels As ModelDoc2, ByVal swPartName As String)
Dim swComponent As Component2
Dim swildMode As ModelDoc2
Dim swPropMgr As CustomPropertyManager
Dim swGetTypes As String
Dim swFeature As Feature
Dim swChild As String
swComponent = swModels.GetComponentByName(swPartName) '获取指定的顶级程序集组件
swChild = swComponent.ReferencedConfiguration
If swComponent.IsSuppressed = False AndAlso swComponent.ExcludeFromBOM = False AndAlso swComponent.IsEnvelope = False Then '排除否被压缩、不包括在材料明细表中或是一个封套
swildMode = swComponent.GetModelDoc2 '获取此组件的模型文档
swGetTypes = swildMode.GetPathName '获取此文档的完整路径名,包括文件名
RichTextBox1.Text &= swGetTypes & vbNewLine
swPropMgr = swildMode.Extension.CustomPropertyManager("") '获得自定义属性
'swPropMgr = swildMode.Extension.CustomPropertyManager(swChild) '获得配置特定属性
'..............
'..............
'..............
'..............添加你要处理的代码
If swildMode.GetType = 2 Then '获取文档类型,是否是装配文件
swFeature = swildMode.FirstFeature '获取此组件中的第一个模型
Do While Not swFeature Is Nothing '如果模型存在, 模型循环此模型
Select Case swFeature.GetTypeName2
Case "Reference", "ReferencePattern"
Throughs(swildMode, swFeature.Name)
End Select
swFeature = swFeature.GetNextFeature
Loop
End If
End If
End Sub
复制代码
作者:
qxzch
时间:
2020-5-2 14:20
可以转换成VB代码吗
作者:
xiaocake
时间:
2020-6-5 19:59
qxzch 发表于 2020-5-2 14:20
可以转换成VB代码吗
自己去查查VB和VB.net的区别就知道了
作者:
1066236582
时间:
2021-4-15 13:31
感谢分享
欢迎光临 iCAx开思网 (https://www.icax.org/)
Powered by Discuz! X3.3