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: 

Organized ObjectCollection

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
inulobo
1178 Views, 3 Replies

Organized ObjectCollection

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

 

Tags (2)
Labels (2)
3 REPLIES 3
Message 2 of 4
Stakin
in reply to: inulobo

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 

Message 3 of 4
J-Camper
in reply to: inulobo

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.

Message 4 of 4
inulobo
in reply to: J-Camper

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

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

Post to forums  

Autodesk Design & Make Report