Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VB.net get iProperties from selected part/assembly in drawing

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
MR-Keller2014
2500 Views, 3 Replies

VB.net get iProperties from selected part/assembly in drawing

Hi there,

 

I'm trying to access some User definied iProperties of a selected part/assembly within a drawing view. I just get part as a kGenericObject therefore I can't access the properties.

Anyone there who can help me??

 

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Test
        If _invApp.Documents.Count = 0 Then
            MsgBox("Need to open an Assembly document")
            Return
        End If

        If _invApp.ActiveDocument.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
            MsgBox("Es muss eine Z-Ableitung aktiv sein.")
            Return
        End If

        Dim drawDoc As DrawingDocument
        drawDoc = _invApp.ActiveDocument

        If drawDoc.SelectSet.Count = 0 Then
            MsgBox("Wähle eine Linie, Baugruppe oder Bauteil")
            Return
        End If

        Dim selSet As SelectSet
        selSet = drawDoc.SelectSet

        Dim oSelectName As String

        If TypeOf selSet.Item(1) Is ComponentOccurrence Then

            MsgBox("Test")

            Dim oOcc As ComponentOccurrence
            oOcc = selSet.Item(1)
            Dim oDoc As Document
            oDoc = oOcc.Definition.Document

            Dim oProp As [Property]
            oProp = oDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}").Item("BENENNUNG2")

            MsgBox(oProp.Value)
        End If

        MsgBox("Test2")

  End Sub

3 REPLIES 3
Message 2 of 4
prakasht66
in reply to: MR-Keller2014

 

Hi,

 

I hope this will help you .But i done this using VB.net ,So you need to modify this code according to your requirement.

Here you need to select a drawingcurve & that will get the component properties .So that you will get the value of that property.

 

 

'Open a assembly drawing before run this & Change properties in custom tab as per your requirement

If inventordoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then

 Dim odoc As Inventor.Document
   odoc = inventorApp.ActiveDocument

  Dim oSelectSet As Inventor.SelectSet
   oSelectSet = odoc.SelectSet

   Dim oDrCurveseg As Inventor.DrawingCurveSegment
  oDrCurveseg = inventorApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a drawingCurve")

             oSelectSet.Select(oDrCurveseg)
  Dim oCurve As Inventor.DrawingCurve
             oCurve = oDrCurveseg.Parent
            If TypeOf oCurve.ModelGeometry Is Inventor.EdgeProxy Then

    Dim oEdge As Inventor.Edge
                oEdge = oCurve.ModelGeometry

  Dim oBody As Inventor.SurfaceBody
                oBody = oEdge.Parent

  Dim oOC As Inventor.ComponentOccurrence
                oOC = oBody.Parent

                If oOC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
                                        odoc = oOC.Definition.Document

                    Dim oProp As Inventor.Property
                    oProp = odoc.PropertySets.Item("Inventor User Defined Properties").Item("Height")
                    Console.WriteLine(oPropSet.Value)
                End If

            End If

 End If

Message 3 of 4
MR-Keller2014
in reply to: prakasht66

It worked 🙂

But I had to deaktivate   oSelectSet.Select (oDrCurveseg)

 

Thanks a lot 🙂

 

 

 

 Dim inventorApp As Inventor.Application
 Set inventorApp = GetObject(, "Inventor.Application")
 Dim odoc As Inventor.Document
   Set odoc = inventorApp.ActiveDocument
   
If odoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
On Error Resume Next
  Dim oSelectSet As Inventor.SelectSet
  Set oSelectSet = odoc.SelectSet

   Dim oDrCurveseg As Inventor.DrawingCurveSegment
Set oDrCurveseg = inventorApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a drawingCurve")

         '    oSelectSet.Select (oDrCurveseg)
  Dim oCurve As Inventor.DrawingCurve
           Set oCurve = oDrCurveseg.Parent
            If TypeOf oCurve.ModelGeometry Is Inventor.EdgeProxy Then

    Dim oEdge As Inventor.Edge
               Set oEdge = oCurve.ModelGeometry

  Dim oBody As Inventor.SurfaceBody
             Set oBody = oEdge.Parent

  Dim oOC As Inventor.ComponentOccurrence
             Set oOC = oBody.Parent

                If oOC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
                                   Set odoc = oOC.Definition.Document
                                   
                    Dim oPropSet As PropertySet
                    Set oPropSet = odoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

                    Dim oProp As Property
                 '   oProp = odoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}").Item("BENENNUNG2")
                  On Error Resume Next
                    Set oProp = oPropSet.Item("BENENNUNG1")
                    Dim oString1 As String
                    Dim oString2 As String
                    Dim oString3 As String
                    oString1 = oProp.Value
                    Set oProp = oPropSet.Item("BENENNUNG2")
                    oString2 = oProp.Value
                    Set oProp = oPropSet.Item("BEZEICHNUNG1")
                    oString3 = oProp.Value
                    MsgBox ("BENENNUNG1 = " & oString1 & " BENENNUNG2 = " & oString2 & " Bezeichnung1= " & oString3)
                End If

            End If

 End If

Message 4 of 4
prakasht66
in reply to: MR-Keller2014

 

You need to add Selection set clear method to deactivate drawingcurve. 

Something like this...

 

Dim inventorApp As Inventor.Application
 Set inventorApp = GetObject(, "Inventor.Application")
 Dim odoc As Inventor.Document
   Set odoc = inventorApp.ActiveDocument
   
If odoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
On Error Resume Next
  Dim oSelectSet As Inventor.SelectSet
  Set oSelectSet = odoc.SelectSet

   Dim oDrCurveseg As Inventor.DrawingCurveSegment
Set oDrCurveseg = inventorApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a drawingCurve")

         '    oSelectSet.Select (oDrCurveseg)
  Dim oCurve As Inventor.DrawingCurve
           Set oCurve = oDrCurveseg.Parent
            If TypeOf oCurve.ModelGeometry Is Inventor.EdgeProxy Then

    Dim oEdge As Inventor.Edge
               Set oEdge = oCurve.ModelGeometry

  Dim oBody As Inventor.SurfaceBody
             Set oBody = oEdge.Parent

  Dim oOC As Inventor.ComponentOccurrence
             Set oOC = oBody.Parent

                If oOC.DefinitionDocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
                                   Set odoc = oOC.Definition.Document
                                   
                    Dim oPropSet As PropertySet
                    Set oPropSet = odoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

                    Dim oProp As Property
                 '   oProp = odoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}").Item("BENENNUNG2")
                  On Error Resume Next
                    Set oProp = oPropSet.Item("BENENNUNG1")
                    Dim oString1 As String
                    Dim oString2 As String
                    Dim oString3 As String
                    oString1 = oProp.Value
                    Set oProp = oPropSet.Item("BENENNUNG2")
                    oString2 = oProp.Value
                    Set oProp = oPropSet.Item("BEZEICHNUNG1")
                    oString3 = oProp.Value
                    MsgBox ("BENENNUNG1 = " & oString1 & " BENENNUNG2 = " & oString2 & " Bezeichnung1= " & oString3)

                    oSelectSet.clear( )
                End If

            End If

 End If

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report