蒹葭苍苍,白露为霜。
所谓伊人,在水一方。

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

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

赞(1) 打赏
未经允许不得转载:酷居科技 » 工程图及模型文件iproperty相互映射案例

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    言简意赅,赞一个!

    跨境电商之家6年前 (2018-01-27)回复

锦瑟无端五十弦,一弦一柱思华年

酷居科技联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏