vb.net put component occurence into class

vb.net put component occurence into class

snappyjazz
Collaborator Collaborator
779 Views
4 Replies
Message 1 of 5

vb.net put component occurence into class

snappyjazz
Collaborator
Collaborator

Hello,

I am setting up a class that will:

  • hold the component occurrence
  • get the name of the comp occ
  • define a position quadrant from the matrix of the comp occ
  • define the direction the part is facing from the matrix of the comp occ

I can pass a component occurrence to the class via "Public Sub New" however I cannot pass that occurrence to a variable which can be read to make the above list. Is a component occurrence an unacceptable data type to be handled by a class?

    Public Sub IntGussetsEconToStack()
        'get inventor session
        Dim InvApp As Inv.Application = SysInter.Marshal.GetActiveObject("Inventor.Application")
        Dim InvDoc As Inv.AssemblyDocument = InvApp.ActiveDocument


        '===================================================
#Region "get the Interior Stiff occurances"

        Console.Write(vbNewLine & vbNewLine)
        'Dim ExistingIntFBGussList As New List(Of Inv.ComponentOccurrence)
        Dim ExistingIntFBGussList As New List(Of Gusset)
        Dim ExistingIntLRGussList As New List(Of Inv.ComponentOccurrence)


        For Each OccItem As Inv.ComponentOccurrence In InvDoc.ComponentDefinition.Occurrences
            If OccItem.Name.Contains("GUSSET,INT,F&B") Then
                Dim Gusset As New Gusset(OccItem)
                ExistingIntFBGussList.Add(Gusset)
            End If
        Next
        Console.WriteLine("Existing F/B gussets: " & ExistingIntFBGussList.Count & vbNewLine & "Existing L/R gussets: " & ExistingIntLRGussList.Count & vbNewLine & vbNewLine)
#End Region
    End Sub
        '===================================================

#Region "Gusset Class"
    Public Class Gusset

        Protected InvApp As Inv.Application = SysInter.Marshal.GetActiveObject("Inventor.Application")
        Protected InvDoc As Inv.AssemblyDocument = InvApp.ActiveDocument
        Protected TransGeo As Inv.TransientGeometry = InvApp.TransientGeometry

        Protected _Occ As Inv.ComponentOccurrence
        Protected GussTrans As Inv.Vector = _Occ.Transformation.Translation
        Protected UoM As Inv.UnitsOfMeasure = InvDoc.UnitsOfMeasure

        Protected _Name As String = _Occ.Name

        'Protected _Location As Inv.Point = TransGeo.CreatePoint(UoM.ConvertUnits(GussTrans.X, Inv.UnitsTypeEnum.kCentimeterLengthUnits, Inv.UnitsTypeEnum.kInchLengthUnits), UoM.ConvertUnits(GussTrans.Y, Inv.UnitsTypeEnum.kCentimeterLengthUnits, Inv.UnitsTypeEnum.kInchLengthUnits), UoM.ConvertUnits(GussTrans.Z, Inv.UnitsTypeEnum.kCentimeterLengthUnits, Inv.UnitsTypeEnum.kInchLengthUnits))

        Protected _Quadrant As Quad

        Protected _Direction As Direction

        Public Sub New(CompOcc As Inv.ComponentOccurrence)
            _Occ = CompOcc
        End Sub

        Public Enum Quad
            FR
            RR
            FL
            RL
        End Enum

        Private Sub AssignQuad()
            Select Case True
                Case _Location.X >= 0 AndAlso _Location.Z > 0
                    _Quadrant = Quad.FL
                Case _Location.X >= 0 AndAlso _Location.Z < 0
                    _Quadrant = Quad.RR
                Case _Location.X < 0 AndAlso _Location.Z > 0
                    _Quadrant = Quad.FR
                Case _Location.X < 0 AndAlso _Location.Z < 0
                    _Quadrant = Quad.RL
            End Select
        End Sub

        Public ReadOnly Property Name As String
            Get
                Return _Name
            End Get
        End Property

        Public ReadOnly Property Location As Inv.Point
            Get
                Return _Location
            End Get
        End Property

        Public ReadOnly Property Quadrant As String
            Get
                Return _Quadrant
            End Get
        End Property

        Public Enum Direction
            FRONT
            BACK
            LEFT
            RIGHT
        End Enum

        Private Sub AssignDirection()
            Select Case True
                Case GussTrans.Cell(1, 4) > 0 AndAlso GussTrans.Cell(3, 4) > 0
                    _Direction = Direction.BACK
                Case GussTrans.Cell(1, 4) > 0 AndAlso GussTrans.Cell(3, 4) < 0
                    _Direction = Direction.FRONT
                Case GussTrans.Cell(1, 4) < 0 AndAlso GussTrans.Cell(3, 4) > 0
                    _Direction = Direction.BACK
                Case GussTrans.Cell(1, 4) < 0 AndAlso GussTrans.Cell(3, 4) < 0
                    _Direction = Direction.FRONT
            End Select
        End Sub

    End Class
#End Region
0 Likes
Accepted solutions (1)
780 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

I don't see where you are trying to Add the Occurrence variable to a list, but you should be able to to what you want with the Gusset._Occ.

I believe the issue is you have defined it as Protected, try defining it as Public. Protected means it can only be used in your Gusset class or any derived from it.

0 Likes
Message 3 of 5

snappyjazz
Collaborator
Collaborator

@Anonymous 

Thanks for responding. I switched the _Occ variable to Public and it still comes up empty.

 

image.png

0 Likes
Message 4 of 5

Anonymous
Not applicable
Accepted solution

Oh I see. I think the issue is that it's trying to set your class variables before it runs your Sub New. So you're going to want to put anything that uses _Occ in Sub New or where ever you actually us the variable. For example, 

 

Public Sub New(CompOcc As Inv.ComponentOccurrence)
            _Occ = CompOcc
            GussTrans = _Occ.Transformation.Translation
        End Sub

 

Private Sub AssignDirection()
            Select Case True
                GussTrans = _Occ.Transformation.Translation
                Case GussTrans.Cell(1, 4) > 0 AndAlso GussTrans.Cell(3, 4) > 0
                    _Direction = Direction.BACK
                Case GussTrans.Cell(1, 4) > 0 AndAlso GussTrans.Cell(3, 4) < 0
                    _Direction = Direction.FRONT
                Case GussTrans.Cell(1, 4) < 0 AndAlso GussTrans.Cell(3, 4) > 0
                    _Direction = Direction.BACK
                Case GussTrans.Cell(1, 4) < 0 AndAlso GussTrans.Cell(3, 4) < 0
                    _Direction = Direction.FRONT
            End Select
        End Sub
Message 5 of 5

snappyjazz
Collaborator
Collaborator

That's what I was missing. Thank you!

0 Likes