简体   繁体   English

如何使用api获取inventoer中对象的属性

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

I am new in Inventor api programming.I want to get the properties of a active document.I am using vb.net for coding.I tried some code but no help. 我是Inventor api编程的新手。我想获取活动文档的属性。我正在使用vb.net进行编码。我尝试了一些代码但没有帮助。 here I use some code for open an inventor document ,it is working fine 在这里我使用一些代码打开一个发明人文档,它工作正常

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

any one know how to get the part1.ipt document's properties.? 任何人都知道如何获取part1.ipt文档的属性。

First try to understand the object model 首先尝试了解对象模型

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

Now, you can access the info you require ... 现在,您可以访问所需的信息......

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

Since you already got the document, you can just iterate through the PropertySets and the Properties therein with two For-Each-Loops like this for example: 既然您已经获得了文档,那么您可以通过这样的两个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.

相关问题 如何使用反射和递归从嵌套对象获取属性? - How to get properties from nested object using reflection and recursion? 当不在参数中时如何获取函数中对象的属性 - how to get properties of an object in a function when it's not in the parameter 如果我遍历对象以获取所有属性,性能将如何? - How is performance going to be if I iterate through an object to get all the properties? 如何使用OLEDB或ADO连接获取Access DB的“扩展属性” - How to get “extended properties” of Access DB Using OLEDB or ADO connection 如何在 pdf 中获取字体属性……我正在使用 .net - How to get font properties in pdf… i'm using .net 如何使用 Object 类型变量访问 class 的属性? - How to access properties of a class using Object type variable? 使用反射获取属性 - Using reflection to get a properties property 使用GetProperties获取类的属性列表后,如何获取父属性的类类型? - How to I get the parent property's class type after using GetProperties to get a list of properties on a class? 如何对对象的属性进行排序并填充到ArrayList中 - How to sort properties of object and populate into an ArrayList 从LogicalBinaryExpression中获取属性; 怎么样? - Get Properties out of LogicalBinaryExpression ; How?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM