2013-06-28 13 views
0

我是Inventor api編程中的新手。我想獲取活動文檔的屬性。我使用vb.net進行編碼。我嘗試了一些代碼,但沒有幫助。 這裏我用開放的發明者文檔一些代碼,它工作正常如何使用api獲取某個對象在Inventoer中的屬性

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

任何一個知道如何讓part1.ipt文檔的屬性?

回答

2

先了解對象模型

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 
+0

謝謝先生..在這裏打印文檔的文件名稱。我需要打印對象使用的平均長度,寬度等的屬性.... – Arun

+0

檢查教程:http://download.autodesk.com/us/community/mfg/Part_1.pdf http://download.autodesk.com/us/community/mfg/Part_2.pdf http://download.autodesk.com/us/community/mfg/Part_3.pdf http://download.autodesk.com /us/community/mfg/Part_4.pdf – rags

0

既然你已經拿到了文件,你可以通過迭代PropertySets和其中的屬性有兩個For-Each-Loop,例如:

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