簡體   English   中英

如何使用api獲取inventoer中對象的屬性

[英]how to get the properties of an object in inventoer using api

我是Inventor api編程的新手。我想獲取活動文檔的屬性。我正在使用vb.net進行編碼。我嘗試了一些代碼但沒有幫助。 在這里我使用一些代碼打開一個發明人文檔,它工作正常

Public Sub OpenDoc()
    Dim oDoc As Document
    oDoc = _InvApplication.Documents.Open _
                             ("C:\Temp\Part1.ipt")
End Sub

任何人都知道如何獲取part1.ipt文檔的屬性。

首先嘗試了解對象模型

Application
   |
   -------- Documents
               |
               ---------- Document
                              |
                              ------------- PropertySet
                                                |
                                                ------------ Property

現在,您可以訪問所需的信息......

Public Sub ShowDocuments()
     ' Get the Documents collection object.
     Dim invDocs As Documents
     Set invDocs = ThisApplication.Documents
     ' Iterate through the contents of the Documents collection.
     Dim i As Integer
     For i = 1 To invDocs.Count
         ' Get a specific item from the Documents collection.
         Dim invDocument As Document
         Set invDocument = invDocs.Item(i)
         ' Display the full filename of the document in the Immediate window.
         Debug.Print invDocument.FullFileName
     Next
End Sub

既然您已經獲得了文檔,那么您可以通過這樣的兩個For-Each-Loops迭代PropertySets和其中的屬性,例如:

    Dim oPropSets As PropertySets
    oPropSets = oDoc.PropertySets
    Dim oPropSet As PropertySet
    For Each oPropSet In oPropSets
        Dim oPartProp As Inventor.Property
        For Each oPartProp In oPropSet
            Dim oPropertyValue As Object
            If oPartProp.Value Is Nothing Then
                'NullValue-Properties are ignored
            ElseIf oPartProp Is Nothing Then
                   'Null-Properties are ignored too
            ElseIf System.String.Equals(oPartProp.Value.ToString.Trim, "") Then
            'Properties with empty values are also ignored
            Else
                'And here you have your Property:
                Debug.Print(oPartProp.Name & "=" & oPartProp.Value.ToS5tring & vbLf)
            End If
        Next
    Next

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM