使用 iLogic 代码将文件名填充到 Autodesk Inventor 零件的'零件代号'属性中

本教程演示如何使用 iLogic 代码将文件名中的信息自动填充到 Autodesk Inventor 零件的'零件代号'属性中。

以下是一个示例 iLogic 代码,可以将文件名赋值给零件的属性'零件代号':

Sub Main
    ' 获取活动文档
    Dim doc As Document = ThisApplication.ActiveDocument
    
    ' 获取文件名
    Dim fileName As String = doc.FullFileName
    
    ' 提取文件名中的零件代号
    Dim partNumber As String = GetPartNumberFromFileName(fileName)
    
    ' 将零件代号赋值给零件属性
    doc.PropertySets.Item("Inventor Summary Information").Item("Part Number").Value = partNumber
End Sub

' 从文件名中提取零件代号的函数
Function GetPartNumberFromFileName(fileName As String) As String
    ' 获取文件名的最后一个斜杠的位置
    Dim lastSlashIndex As Integer = fileName.LastIndexOf("/")
    
    ' 获取文件名的最后一个点的位置
    Dim lastDotIndex As Integer = fileName.LastIndexOf(".")
    
    ' 提取零件代号
    Dim partNumber As String = fileName.Substring(lastSlashIndex + 1, lastDotIndex - lastSlashIndex - 1)
    
    Return partNumber
End Function

请将以上代码复制到 iLogic 编辑器中,并将其保存为一个 iLogic 规则。在需要将文件名赋值给'零件代号'属性的时候,可以运行这个 iLogic 规则。


原文地址: http://www.cveoy.top/t/topic/phcU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录