solidworks模型自定义属性的批量处理的宏代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Attribute VB_Name = "利用子件处理属性1"

'利用子件进行自定义属性的批量处理的VBA代码

'比较完善的第一版完成时间2012.11.05,作者:张中锋

'适用于深圳东风有限公司solidworks老模型属性更改满足金蝶公司PLM系统要求实例'测试通过环境:2012.11.05 windows XP SP3 ;solidworks 2010 SP02(32bit)

'''''''''''''''' '''''''''''''''' '''''''''''''''' '

'版本更新日志

'1.0 2012.10.29 ①对属性中,存在空白情况处理时数据异常进行修复;②对于已经存在的自定义属性值,保护其值不被处理

'已知的bug记录

Public swModel2 As SldWorks.ModelDoc2

Public PARTNAME_Value_temp As String

Public MATERIAL_Value2_temp As String

Public swApp As SldWorks.SldWorks

Sub main()

Dim swModel As SldWorks.ModelDoc2

Dim swModelDocExt As SldWorks.ModelDocExtension

Dim swSelMgr As SldWorks.SelectionMgr

Dim swBOMAnnotation As SldWorks.BomTableAnnotation

Dim swBOMFeature As SldWorks.BomFeature

Dim swBomTable As Variant

Dim boolstatus As Boolean

Dim BomType As Long

Dim Configuration As String

Dim TemplateName As String

Dim i, j, n, k As Integer

Dim swBOM_name As String

Dim component As Component2

Dim value_temp As Integer

Dim time_start As String

Dim txt_path As String

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

txt_path = swModel.GetPathName() & " .csv"

Open txt_path For Output Shared As #400

Print #400, "图样代号"; ","; "零件名称"; ","; "零件材料"; Chr(10);

Configuration = swModel.GetActiveConfiguration().Name

If swModel.GetType = 1 Then

Set swModel2 = swApp.ActiveDoc

Call Custominfo_change(Configuration)

ElseIf swModel.GetType = 2 Then

value_temp = swModel.ResolveAllLightWeightComponents(False) '轻化取消到还原状态

Dim Components As Variant

Dim SingleComponent As Variant

Dim swComponent As ponent2

Components = swModel.GetComponents(False) '获取整个装配体的组成部件(零件或者装配体)

For Each SingleComponent In Components '遍历

Set swComponent = SingleComponent

If Not swComponent Is Nothing Then

If swComponent.GetModelDoc() Is Nothing Then '判断子件对象模型是否存在;轻化状态下

获取不到,为空

Debug.Print "没有通过"

Else

Dim x As Integer

Do '此循环实现处理当前模型和子件属

If Not swComponent Is Nothing And x < 99 Then '一个很原始的方法强制使用

当前的模型

Set swModel2 = swModel

x = 100

Else

Set swModel2 = swComponent.GetModelDoc() '取得子件对象模型

x = 101

End If

Call Custominfo_change(swModel2.GetActiveConfiguration().Name)

Loop Until x = 101

End If

Else

Debug.Print " 不能获取到子件"

End If

Next

Else

MsgBox "不是零件或者装配体模型"

End If

swModel.Save '保存文件

Close #400

MsgBox "属性转换完毕"

End Sub

Private Function Custominfo_change(ByVal vConfigName As String)

相关文档
最新文档