Organized ObjectCollection

Organized ObjectCollection

inulobo
Advocate Advocate
1,424 Views
3 Replies
Message 1 of 4

Organized ObjectCollection

inulobo
Advocate
Advocate

I can't figure out how to add items to an object collection in a specific order. How do you do it? Is it possible? Do I need to use arrays instead? I need the front view to always be the first item and so on. 

 

Dim oReturnColl(1 To 3) As ObjectCollection

For Each DrawingView In oSheet.DrawingViews
    Select Case oSheet.DrawingViews.item(i).Type
        Case ViewOrientationTypeEnum.kBackViewOrientation
        Case ViewOrientationTypeEnum.kBottomViewOrientation
        Case ViewOrientationTypeEnum.kFrontViewOrientation
            oReturnColl.item(1) = DrawingView
            CurrentScale = oSheet.DrawingViews.item(i).Scale
        Case ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation
        Case ViewOrientationTypeEnum.kIsoBottomRightViewOrientation
        Case ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
        Case ViewOrientationTypeEnum.kIsoTopRightViewOrientation
        Case ViewOrientationTypeEnum.kLeftViewOrientation
            oReturnColl.item(2) = DrawingView
        Case ViewOrientationTypeEnum.kRightViewOrientation
        Case ViewOrientationTypeEnum.kTopViewOrientation
        Case Else
            oReturnColl.item(3) = DrawingView
        End Select
Next
i = i + 1

 

0 Likes
Accepted solutions (1)
1,425 Views
3 Replies
Replies (3)
Message 2 of 4

Stakin
Collaborator
Collaborator

Maybe:

Dim oReturnColl(1 To 3) As ObjectCollection
Dim oDrawingView As DrawingView
For Each oDrawingView In oSheet.DrawingViews
    Select Case oDrawingView.Type
        Case ViewOrientationTypeEnum.kBackViewOrientation
        Case ViewOrientationTypeEnum.kBottomViewOrientation
        Case ViewOrientationTypeEnum.kFrontViewOrientation
            oReturnColl.item(1) = oDrawingView
            CurrentScale = oDrawingView.Scale
        Case ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation
        Case ViewOrientationTypeEnum.kIsoBottomRightViewOrientation
        Case ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
        Case ViewOrientationTypeEnum.kIsoTopRightViewOrientation
        Case ViewOrientationTypeEnum.kLeftViewOrientation
            oReturnColl.item(2) = oDrawingView
        Case ViewOrientationTypeEnum.kRightViewOrientation
        Case ViewOrientationTypeEnum.kTopViewOrientation
        Case Else
            oReturnColl.item(3) = oDrawingView
        End Select
Next

 try again 

0 Likes
Message 3 of 4

J-Camper
Advisor
Advisor

I'm not sure what your end goal is since this is only part of you code, but in order to use an object collection, you need to add all objects and the sort them.  A NameValueMap lets you collection Objects with a unique Key attached to each of them, this means the Object/Key can be retrieved by searching with the other.

 

Either way you need to create them before you can fill them, so let me know if either route works for your purposes:

 

'ObjectCollections collect as a running list. If you want it sorted, it can be done after collection
Dim oReturnColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
'NameValueMaps collect items with an associated unique Key
Dim oReturnMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

For Each DrawingView In oSheet.DrawingViews
    Select Case DrawingView.Type
        Case ViewOrientationTypeEnum.kBackViewOrientation
        Case ViewOrientationTypeEnum.kBottomViewOrientation
        Case ViewOrientationTypeEnum.kFrontViewOrientation
			Try
				oReturnMap.Add("1", DrawingView) 'NameValueMap.Add(Unique Name, Object)
			Catch
				'Key is already used
			End Try
			oReturnColl.Add(DrawingView) 'ObjectCollection.Add(Object)
            CurrentScale = oSheet.DrawingViews.item(i).Scale
        Case ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation
        Case ViewOrientationTypeEnum.kIsoBottomRightViewOrientation
        Case ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
        Case ViewOrientationTypeEnum.kIsoTopRightViewOrientation
        Case ViewOrientationTypeEnum.kLeftViewOrientation
			Try
				oReturnMap.Add("2", DrawingView) 'NameValueMap.Add(Unique Name, Object)
			Catch
				'Key is already used
			End Try
			oReturnColl.Add(DrawingView) 'ObjectCollection.Add(Object)
        Case ViewOrientationTypeEnum.kRightViewOrientation
        Case ViewOrientationTypeEnum.kTopViewOrientation
        Case Else
            Try
				oReturnMap.Add("3", DrawingView) 'NameValueMap.Add(Unique Name, Object)
			Catch
				'Key is already used
			End Try
			oReturnColl.Add(DrawingView) 'ObjectCollection.Add(Object)
        End Select
Next

 

I put the NameValueMap setting into a Try/Catch Block because if you have 2 views on your sheet that are both "ViewOrientationTypeEnum.kFrontViewOrientation", you need a unique key for each.

 

Let me know if you have any questions or if this is not working as intended.

0 Likes
Message 4 of 4

inulobo
Advocate
Advocate
Accepted solution

I believe your solution is iLogic I am working in vba in particular. I did come up with a solution last night !

 

Dim oReturnColl As Collection
Set oReturnColl = New Collection

For Each DrawingView In oSheet.DrawingViews
    Select Case oSheet.DrawingViews.item(i).Camera.ViewOrientationType
        Case ViewOrientationTypeEnum.kBackViewOrientation
        Case ViewOrientationTypeEnum.kBottomViewOrientation
        Case ViewOrientationTypeEnum.kFrontViewOrientation
            oReturnColl.Add DrawingView
            CurrentScale = oSheet.DrawingViews.item(i).Scale
        Case ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation
        Case ViewOrientationTypeEnum.kIsoBottomRightViewOrientation
        Case ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
        Case ViewOrientationTypeEnum.kIsoTopRightViewOrientation
        Case ViewOrientationTypeEnum.kLeftViewOrientation
            oReturnColl.Add (DrawingView), After:=1
        Case ViewOrientationTypeEnum.kRightViewOrientation
        Case ViewOrientationTypeEnum.kTopViewOrientation
        Case Else
            oReturnColl.Add (DrawingView), After:=2
        End Select
Next
i = i + 1
0 Likes