酷居科技

每个人都有属于自己的世界

工程图及模型文件iproperty相互映射案例

作者:ikuju 发布:2017/10/29 分类:科技 阅读: 次 1条评论

VBA级别,可参考,具体如下

Sub Main()
        Dim doc As Document
        Dim DrawingName As String = Nothing
        If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Or ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            doc = ThisApplication.ActiveDocument
            DrawingName = GetDrawingType(doc.FullDocumentName)
            If DrawingName Is Nothing Then
                MsgBox("No drawing name could be found with this name in this path!", MsgBoxStyle.Exclamation, "Drawing not found")
                Exit Sub
            End If
        Else
            MsgBox("This application will only run from a part or assembly document!", MsgBoxStyle.Exclamation, "Document Type Error")
            Exit Sub
        End If

        Dim dwg As DrawingDocument
        dwg = ThisApplication.Documents.Open(DrawingName, False)

        Dim propSetPart As PropertySet
        propSetPart = doc.PropertySets.Item("D5CDD505-2E9C-101B-9397-08002B2CF9AE")

        Dim propSetDwg As PropertySet
        propSetDwg = dwg.PropertySets.Item("D5CDD505-2E9C-101B-9397-08002B2CF9AE")

        Dim prop As Inventor.Property
        For Each prop In propSetDwg
            Try
                propSetPart.Item(prop.Name).Value = prop.Value
            Catch ex As Exception
                propSetPart.Add(prop.Value, prop.Name)
            End Try
        Next

    End Sub

    Private Function GetDrawingType(ByVal FileName As String) As String
        Dim FoundFile As String = Nothing
        Dim Dir As String = GetDirFromPath(FileName)
        Dim _FileName As String = GetFileNameWithoutExtFromPath(FileName)
        If My.Computer.FileSystem.FileExists(Dir & _FileName & ".idw") Then
            FoundFile = Dir & _FileName & ".idw"
        End If
        If My.Computer.FileSystem.FileExists(Dir & _FileName & ".dwg") Then
            FoundFile = Dir & _FileName & ".dwg"
        End If
        Return FoundFile
    End Function
   
    Private Function GetFileNameWithoutExtFromPath(ByVal path _
           As String) As String

        Try
            Dim filename As String = _
               path.Substring(path.LastIndexOf("\") + 1)
            Dim pos As Integer = filename.LastIndexOf(".")

            If pos <> -1 Then
                Return filename.Substring(0, pos)
            Else
                Return filename
            End If

        Catch ex As Exception
            ' error
            Return ""
        End Try

    End Function
   
    Private Function GetDirFromPath(ByVal path As String) _
      As String

        Try
            Return path.Substring(0, path.LastIndexOf("\") + 1)

        Catch ex As Exception
            ' error
            Return ""
        End Try

    End Function

除非注明,本站所有文章均为 ikuju 原创,转载请注明出处! 标签:iproperty  Inventor  
« 上一篇下一篇 »

工程图及模型文件iproperty相互映射案例:目前有1条评论

发表留言:

快捷回复: Ctrl+Enter