设计背景:把多实体零件的实体名称修改为文件名和两位数的序号。
文件名:GT.ipt
实体1:GT01
实体2:GT02
......
实体99:GT99
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Exit Sub
Dim oPDoc As PartDocument = ThisDoc.Document
Dim oBodies As SurfaceBodies = oPDoc.ComponentDefinition.SurfaceBodies
fileName=ThisDoc.Document.DisplayName.Replace(".ipt","")
i=1
For Each oBody As SurfaceBody In oBodies
oBody.Name=fileName+Format(i, "00")
i=i+1
Next
If oPDoc.RequiresUpdate Then oPDoc.Update2(True)
End Sub
网友评论