Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I created a class of objects (Gussets), of which I want to put in 1 of 2 lists. However when I fill the lists with objects (gussets) of that class, any previously created objects are overwritten by the most recently created object. So by then end of the code, I have 2 lists containing multiple objects of the same object (2 lists containing "Gusset:4"). I hope that last part makes sense. Do you know what I'm getting wrong?
Sub Main()
Dim ExistingIntFBGussList As New List(Of Gusset)
Dim ExistingIntLRGussList As New List(Of Gusset)
For Each OccItem As Inv.ComponentOccurrence In AppDoc.AssyCompDef.Occurrences
Dim GussetType As Gusset = Nothing
Select Case True
Case OccItem.Name.Contains("GUSSET,INT,F&B")
GussetType = New Gusset(OccItem)
ExistingIntFBGussList.Add(GussetType)
Case OccItem.Name.Contains("GUSSET,INT,L&R")
GussetType = New Gusset(OccItem)
ExistingIntLRGussList.Add(GussetType)
End Select
End Sub
Public Class Gusset
Protected Shared _CompOcc As Inv.ComponentOccurrence
Protected Shared GussTrans As Inv.Vector
Protected Shared DocDef As Inv.PartComponentDefinition
Protected Shared _Name As String
Protected Shared _Location As Inv.Point
Protected Shared _Quadrant As Quad
Protected Shared _Direction As DirectionEnum
Protected Shared _Centered As Boolean
Protected Shared _PlaneXY As Inv.WorkPlane
Protected Shared _PlaneYZ As Inv.WorkPlane
Protected Shared _PlaneXZ As Inv.WorkPlane
Protected Shared _ProxyXY As Inv.WorkPlaneProxy
Protected Shared _ProxyYZ As Inv.WorkPlaneProxy
Protected Shared _ProxyXZ As Inv.WorkPlaneProxy
Protected Shared _i As Integer = 1
Public Sub New(ByRef ComponentOccurrence As Inv.ComponentOccurrence)
Console.WriteLine("Class: Gusset | " & _i)
_i += 1
_CompOcc = ComponentOccurrence
GussTrans = _CompOcc.Transformation.Translation
DocDef = _CompOcc.Definition
_Name = _CompOcc.Name
_Location = AppDoc.InvTransGeo.CreatePoint(Convert.Cent2In(GussTrans.X), Convert.Cent2In(GussTrans.Y), Convert.Cent2In(GussTrans.Z))
'Quardrant
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
'Direction
Select Case True
Case GussTrans.X > 0 AndAlso GussTrans.Z > 0
_Direction = DirectionEnum.BACK
Case GussTrans.X > 0 AndAlso GussTrans.Z < 0
_Direction = DirectionEnum.FRONT
Case GussTrans.X < 0 AndAlso GussTrans.Z > 0
_Direction = DirectionEnum.BACK
Case GussTrans.X < 0 AndAlso GussTrans.Z < 0
_Direction = DirectionEnum.FRONT
End Select
'Planes
_PlaneXY = DocDef.WorkPlanes.Item("XY Plane")
_PlaneYZ = DocDef.WorkPlanes.Item("YZ Plane")
_PlaneXZ = DocDef.WorkPlanes.Item("XZ Plane")
'Proxy
_CompOcc.CreateGeometryProxy(_PlaneXY, _ProxyXY)
_CompOcc.CreateGeometryProxy(_PlaneYZ, _ProxyYZ)
_CompOcc.CreateGeometryProxy(_PlaneXZ, _ProxyXZ)
End Sub
#Region "Property public: CompOcc"
Public Property CompOcc As Inv.ComponentOccurrence
Set(ByVal CompontOccurence As Inv.ComponentOccurrence)
_CompOcc = CompontOccurence
GussTrans = _CompOcc.Transformation.Translation
DocDef = _CompOcc.Definition
_Name = _CompOcc.Name
_Location = AppDoc.InvTransGeo.CreatePoint(Convert.Cent2In(GussTrans.X), Convert.Cent2In(GussTrans.Y), Convert.Cent2In(GussTrans.Z))
'Quardrant
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
'Direction
Select Case True
Case GussTrans.X > 0 AndAlso GussTrans.Z > 0
_Direction = DirectionEnum.BACK
Case GussTrans.X > 0 AndAlso GussTrans.Z < 0
_Direction = DirectionEnum.FRONT
Case GussTrans.X < 0 AndAlso GussTrans.Z > 0
_Direction = DirectionEnum.BACK
Case GussTrans.X < 0 AndAlso GussTrans.Z < 0
_Direction = DirectionEnum.FRONT
End Select
'Planes
_PlaneXY = DocDef.WorkPlanes.Item("XY Plane")
_PlaneYZ = DocDef.WorkPlanes.Item("YZ Plane")
_PlaneXZ = DocDef.WorkPlanes.Item("XZ Plane")
'Proxy
_CompOcc.CreateGeometryProxy(_PlaneXY, _ProxyXY)
_CompOcc.CreateGeometryProxy(_PlaneYZ, _ProxyYZ)
_CompOcc.CreateGeometryProxy(_PlaneXZ, _ProxyXZ)
End Set
Get
Return _CompOcc
End Get
End Property
#End Region
#Region "Enum: Quad"
Public Enum Quad
FR
RR
FL
RL
End Enum
#End Region
#Region "Property readonly: Name"
Public ReadOnly Property Name As String
Get
Return _Name
End Get
End Property
#End Region
#Region "Property readonly: Location"
Public Property Location As Inv.Point
Set(Point As Inv.Point)
_Location = AppDoc.InvTransGeo.CreatePoint(Point.X, Point.Y, Point.Z)
End Set
Get
Return _Location
End Get
End Property
#End Region
#Region "Property readonly: Quandrant"
Public ReadOnly Property Quadrant As String
Get
Return _Quadrant
End Get
End Property
#End Region
#Region "Enum: Direction"
Public Enum DirectionEnum
FRONT
BACK
LEFT
RIGHT
End Enum
#End Region
#Region "Property readonly: Direction"
Public ReadOnly Property Direction As String
Get
Return _Direction
End Get
End Property
#End Region
#Region "Property: Centered"
Public Property Centered As Boolean
Set(value As Boolean)
If _Location.X = 0 OrElse _Location.Z = 0 Then
_Centered = True
Else
_Centered = False
End If
End Set
Get
Return _Centered
End Get
End Property
#End Region
#Region "Property readonly: PlaneXY"
Public ReadOnly Property PlaneXY As Inv.WorkPlane
Get
Return _PlaneXY
End Get
End Property
#End Region
#Region "Property readonly: PlaneYZ"
Public ReadOnly Property PlaneYZ As Inv.WorkPlane
Get
Return _PlaneYZ
End Get
End Property
#End Region
#Region "Property readonly: PlaneXZ"
Public ReadOnly Property PlaneXZ As Inv.WorkPlane
Get
Return _PlaneXZ
End Get
End Property
#End Region
#Region "Property readonly: ProxyXY"
Public ReadOnly Property ProxyXY As Inv.WorkPlaneProxy
Get
Return _ProxyXY
End Get
End Property
#End Region
#Region "Property readonly: ProxyYZ"
Public ReadOnly Property ProxyYZ As Inv.WorkPlaneProxy
Get
Return _ProxyYZ
End Get
End Property
#End Region
#Region "Property readonly: ProxyXZ"
Public ReadOnly Property ProxyXZ As Inv.WorkPlaneProxy
Get
Return _ProxyXZ
End Get
End Property
#End Region
End Class
Solved! Go to Solution.