Sort names of PositionalRepresentations and LevelOfDetailRepresentations

Sort names of PositionalRepresentations and LevelOfDetailRepresentations

GeorgK
Advisor Advisor
534 Views
7 Replies
Message 1 of 8

Sort names of PositionalRepresentations and LevelOfDetailRepresentations

GeorgK
Advisor
Advisor

Hello together,

 

is there any way to sort the names of the PositionalRepresentations and LevelOfDetailRepresentations? Manually I copy all the PositionalRepresentations and LevelOfDetailRepresentations in the right order and delete the old ones.

 

 

Private Sub Button28_Click(sender As Object, e As EventArgs) Handles Button28.Click
        Dim m_inventorApp As Inventor.Application = Nothing

        ' Try to get an active instance of Inventor
        Try
            m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Dim oAsmCompDef As AssemblyComponentDefinition
        oAsmCompDef = m_inventorApp.ActiveDocument.ComponentDefinition

        'define pos rep 
        Dim oPosRep As PositionalRepresentation
        Dim MyArrayList As New ArrayList

        'record the active view rep name
        Dim sActivePosRep As String
        sActivePosRep = oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name

        For Each oPosRep In oAsmCompDef.RepresentationsManager.PositionalRepresentations
            MyArrayList.Add(oPosRep.Name)
        Next

        Dim MyArrayList1 As New ArrayList

        Dim oRepManager As RepresentationsManager
        oRepManager = oAsmCompDef.RepresentationsManager

        For Each oLODRep In oRepManager.LevelOfDetailRepresentations
            MyArrayList1.Add(oLODRep.Name)
        Next

        MyArrayList.Remove("Hauptansicht")

        MyArrayList1.Remove("Hauptansicht")
        MyArrayList1.Remove("Alle Komponenten unterdrückt")
        MyArrayList1.Remove("Alle Bauteile unterdrückt")
        MyArrayList1.Remove("Gesamtes Inhaltscenter unterdrückt")


        ' Sorts the values of the ArrayList.
        MyArrayList.Sort()

        ' Displays the values of the ArrayList.
        Console.WriteLine("After sorting:")
        PrintValues(MyArrayList)



        ' Sorts the values of the ArrayList.
        MyArrayList1.Sort()

        ' Displays the values of the ArrayList.
        Console.WriteLine("After sorting:")
        PrintValues(MyArrayList1)


    End Sub

    Public Shared Sub PrintValues(myList As IEnumerable)
        Dim obj As [Object]
        For Each obj In myList
            Console.WriteLine("   {0}", obj)
        Next obj
        Console.WriteLine()
    End Sub 'PrintValues

Thank you

 

Georg

 

0 Likes
Accepted solutions (1)
535 Views
7 Replies
Replies (7)
Message 2 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @GeorgK,

 

Unfortunately, Inventor API does not support sorting of PositionalRepresentations and LevelOfDetailRepresentations.

 

Default PositionalRepresentations and LevelOfDetailRepresentations can not be sorted. Due to fact that it can not deleted.

 

Other than defaults, Representations can be stored in ArrayList and delete it. Then, after sorting names in ArrayList, Representations can be added.

 

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 8

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

I know the limitations. But I can change those which I created by my own.

 

Is there a way to save the existing PositionalRepresentations and LevelOfDetailRepresentations, delete them and recreate them in a new order?

 

Georg

 

 

0 Likes
Message 4 of 8

GeorgK
Advisor
Advisor

It's much easier:

 

Dim oDoc As Inventor.Document = m_inventorApp.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim oPR As PositionalRepresentation = oCD.RepresentationsManager.PositionalRepresentations("Position1")
oPR.Copy("01_Position1")
0 Likes
Message 5 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi @GeorgK,

 

Try the following VB.Net code to sort PositionalRepresentations and LevelOfDetailRepresentaions.

 

Dim mApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = mApp.ActiveDocument.ComponentDefinition

Dim oRepManager As RepresentationsManager
oRepManager = oAsmCompDef.RepresentationsManager Call oRepManager.PositionalRepresentations.Item(1).Activate() If oRepManager.PositionalRepresentations.Count > 1 Then Dim arrPos As New ArrayList For i As Integer = oRepManager.PositionalRepresentations.Count To 2 Step -1 Dim oPosRep As PositionalRepresentation oPosRep = oRepManager.PositionalRepresentations.Item(i) arrPos.Add(oPosRep.Name) oPosRep.Delete() Next arrPos.Sort() For Each str As String In arrPos oRepManager.PositionalRepresentations.Add(str) Next End If Call oRepManager.PositionalRepresentations.Item(1).Activate() Call oRepManager.LevelOfDetailRepresentations.Item(1).Activate() If oRepManager.LevelOfDetailRepresentations.Count > 4 Then Dim arrLOD As New ArrayList
For i As Integer = oRepManager.LevelOfDetailRepresentations.Count To 5 Step -1 Dim oLOD As LevelOfDetailRepresentation oLOD = oRepManager.LevelOfDetailRepresentations.Item(i) arrLOD.Add(oLOD.Name) oLOD.Delete() Next ' Sorts the values of the ArrayList. arrLOD.Sort() For Each str As String In arrLOD oRepManager.LevelOfDetailRepresentations.Add(str) Next End If Call oRepManager.LevelOfDetailRepresentations.Item(1).Activate()

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 8

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

thats great for a new design. But I would like to change the order for an existing design. All values are deleted with your code. Therefore I thougt of copy all PositionalRepresentations and LevelOfDetailRepresentations in the right order and delete afterwards the old list.

 

Old:

05_Position

03_Position

02_Position

01_Position

04_Position

 

 

New with copy:

05_Position

03_Position

02_Position

01_Position

04_Position

01_Position1

02_Position1

03_Position1

04_Position1

05_Position1

 

 

Dim oDoc As Inventor.Document = m_inventorApp.ActiveDocument
Dim oCD As ComponentDefinition = oDoc.ComponentDefinition
Dim oPR As PositionalRepresentation = oCD.RepresentationsManager.PositionalRepresentations("02_Position")
oPR.Copy("01_Position1")
oPR.Delete

 

 

Delete old order:

01_Position1

02_Position1

03_Position1

04_Position1

05_Position1

 

 

Rename:

01_Position

02_Position

03_Position

04_Position

05_Position

 

I hope it is more clear what I try to get.

 

Georg

0 Likes
Message 7 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi @GeorgK,

 

Try the following VB.Net code.

 

        Dim mApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

        Dim oAsmCompDef As AssemblyComponentDefinition
        oAsmCompDef = mApp.ActiveDocument.ComponentDefinition

        Dim oRepManager As RepresentationsManager
        oRepManager = oAsmCompDef.RepresentationsManager

        Call oRepManager.PositionalRepresentations.Item(1).Activate()

        If oRepManager.PositionalRepresentations.Count > 1 Then
            Dim arrPos As New ArrayList
            For i As Integer = oRepManager.PositionalRepresentations.Count To 2 Step -1
                arrPos.Add(oRepManager.PositionalRepresentations.Item(i).Name)
            Next
            arrPos.Sort()
            Dim j As Integer = 0
            For i As Integer = oRepManager.PositionalRepresentations.Count To 2 Step -1
                oRepManager.PositionalRepresentations.Item(i).Copy(arrPos.Item(j) & "1")
                j = j + 1
            Next
            For i As Integer = oRepManager.PositionalRepresentations.Count To 2 Step -1
                Dim str As String
                str = oRepManager.PositionalRepresentations.Item(i).Name
                If str.Substring(str.Length - 1) <> "1" Then
                    Call oRepManager.PositionalRepresentations.Item(i).Delete()
                End If
            Next
            For i As Integer = oRepManager.PositionalRepresentations.Count To 2 Step -1
                Dim str As String
                str = oRepManager.PositionalRepresentations.Item(i).Name
                If str.Substring(str.Length - 1) = "1" Then
                    oRepManager.PositionalRepresentations.Item(i).Name = str.Remove(str.Length - 1)
                End If
            Next

        End If

        Call oRepManager.PositionalRepresentations.Item(1).Activate()

        Call oRepManager.LevelOfDetailRepresentations.Item(1).Activate()

        If oRepManager.LevelOfDetailRepresentations.Count > 4 Then
            Dim arrLOD As New ArrayList

            For i As Integer = oRepManager.LevelOfDetailRepresentations.Count To 5 Step -1
                arrLOD.Add(oRepManager.LevelOfDetailRepresentations.Item(i).Name)
            Next
            ' Sorts the values of the ArrayList.
            arrLOD.Sort()
            Dim j As Integer = 0
            For i As Integer = oRepManager.LevelOfDetailRepresentations.Count To 5 Step -1
                oRepManager.LevelOfDetailRepresentations.Item(i).Copy(arrLOD.Item(j) & "1")
                j = j + 1
            Next
            For i As Integer = oRepManager.LevelOfDetailRepresentations.Count To 5 Step -1
                Dim str As String
                str = oRepManager.LevelOfDetailRepresentations.Item(i).Name
                If str.Substring(str.Length - 1) <> "1" Then
                    Call oRepManager.LevelOfDetailRepresentations.Item(i).Delete()
                End If
            Next
            For i As Integer = oRepManager.LevelOfDetailRepresentations.Count To 5 Step -1
                Dim str As String
                str = oRepManager.LevelOfDetailRepresentations.Item(i).Name
                If str.Substring(str.Length - 1) = "1" Then
                    oRepManager.LevelOfDetailRepresentations.Item(i).Name = str.Remove(str.Length - 1)
                End If
            Next
        End If

        Call oRepManager.LevelOfDetailRepresentations.Item(1).Activate()

 

Please feel free to contact if there is any doubt.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 8

GeorgK
Advisor
Advisor

@chandra.shekar.g

 

Thats a great tool. Thank you very much. This should be in Inventor 2018!

 

Georg

0 Likes