Cancel
Showing results for 
Search instead for 
Did you mean: 

Asm Level Count

Genius
Genius

Hello All

 

I want to know asm total levels

Use startcommand(40169) will show Assembly Statistics

And I only want to get Total Levels (yellow mark)

Where I need to get this inforamtion?

擷取.PNG

Thank you.

Base Regards

Best Regards
David
Teamcenter 11.4,Active Workspace 3.4
Solid Edge ST10
4 REPLIES 4

Re: Asm Level Count

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hi,

That information must be found. I used a recursive function to traverse the asm. You have to use it in your code like this:

 

Dim ASMfile as string="<your asm path here>"

Dim n As Integer = numAsmLevels(ASMfile)

 

You have to copy-paste this functions in your project:

 

    ''' <summary>
    ''' This is the function to call. It returns the deepest level for an assembly.
    ''' It uses Revision Manager to analyze the asm.
    ''' </summary>
    ''' <param name="asm">Filename for the ASM to analyze</param>
    ''' <returns>It returns the deepest level number for an assembly</returns>
    Private Function numAsmLevels(asm As String) As Integer
        Dim oRevMan As New RevisionManager.Application
        Dim level As Integer = 1, DeepestLevel As Integer = 1
        Dim oASM As RevisionManager.Document = oRevMan.Open(asm)
        For Each oLinkdoc As RevisionManager.Document In oASM.LinkedDocuments(1)
            level = 1
            If oLinkdoc.LinkedDocuments(1).count > 0 Then
                level = processASM(oLinkdoc, level)
                If level > DeepestLevel Then
                    DeepestLevel = level
                End If
            End If
        Next
        oRevMan.Quit()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oRevMan)
        Return DeepestLevel
    End Function

    ''' <summary>
    ''' Recursive function that returns the deepest level in an assembly
    ''' </summary>
    ''' <param name="oLinkDoc"></param>
    ''' <param name="level"></param>
    ''' <returns></returns>
    Private Function processASM(oLinkDoc As RevisionManager.Document, ByVal level As Integer) As Integer
        Dim DeepestLevel As Integer = level
        For Each oL As RevisionManager.Document In oLinkDoc.LinkedDocuments(1)
            If oL.LinkedDocuments(1).count > 0 Then
                level = processASM(oL, level + 1)
                If level > DeepestLevel Then
                    DeepestLevel = level
                End If
            End If
        Next
        Return DeepestLevel
    End Function
Julian Guillo
Pixel Sistemas SL
Spain

Re: Asm Level Count

Creator
Creator

Hello @Julian,

I try your code, and still have some trouble, my code is:

 

Public Class Form1
Private objSolidEdge As SolidEdgeFramework.Application
 
''' <summary>
''' This is the function to call. It returns the deepest level for an assembly.
''' It uses Revision Manager to analyze the asm.
''' </summary>
''' <param name="asm">Filename for the ASM to analyze</param>
''' <returns>It returns the deepest level number for an assembly</returns>
Private Function numAsmLevels(asm As String) As Integer
Dim oRevMan As New RevisionManager.Application
Dim level As Integer = 1, DeepestLevel As Integer = 1
Dim oASM As RevisionManager.Document = oRevMan.Open(asm)
For Each oLinkdoc As RevisionManager.Document In oASM.LinkedDocuments(1)
level = 1
If oLinkdoc.LinkedDocuments(1).count > 0 Then
level = processASM(oLinkdoc, level)
If level > DeepestLevel Then
DeepestLevel = level
End If
End If
Next
oRevMan.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oRevMan)
Return DeepestLevel
End Function

''' <summary>
''' Recursive function that returns the deepest level in an assembly
''' </summary>
''' <param name="oLinkDoc"></param>
''' <param name="level"></param>
''' <returns></returns>
Private Function processASM(oLinkDoc As RevisionManager.Document, ByVal level As Integer) As Integer
Dim DeepestLevel As Integer = level
For Each oL As RevisionManager.Document In oLinkDoc.LinkedDocuments(1)
If oL.LinkedDocuments(1).count > 0 Then
level = processASM(oL, level + 1)
If level > DeepestLevel Then
DeepestLevel = level
End If
End If
Next
Return DeepestLevel
End Function

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim ASMfile = objSolidEdge.ActiveDocument.FullName
Dim n As Integer = numAsmLevels(ASMfile)
Label1.Text = n
End Sub
End Class

 

But the Total levels is wrong!

1546855013899.jpg

 

I don't know which step I am wrong...

 

Thanks in advance,

Taco.

Highlighted

Re: Asm Level Count

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Sorry, my mistake!

I tested that too quickly...

Here are the changes. Copy & paste these 2 functions:

I think it will be working now.

    ''' <summary>
    ''' This is the function to call. It returns the deepest level for an assembly.
    ''' It uses Revision Manager to analyze the asm.
    ''' </summary>
    ''' <param name="asm">Filename for the ASM to analyze</param>
    ''' <returns>It returns the deepest level number for an assembly</returns>
    Private Function numAsmLevels(asm As String) As Integer
        Dim oRevMan As New RevisionManager.Application
        Dim level As Integer = 1, DeepestLevel As Integer = 1
        Dim oASM As RevisionManager.Document = oRevMan.Open(asm)
        For Each oLinkdoc As RevisionManager.Document In oASM.LinkedDocuments(1)
            If oLinkdoc.LinkedDocuments(1).count > 0 Then
                level = processASM(oLinkdoc, 2)
                If level > DeepestLevel Then
                    DeepestLevel = level
                End If
            End If
        Next
        oRevMan.Quit()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oRevMan)
        Return DeepestLevel
    End Function

    ''' <summary>
    ''' Recursive function that returns the deepest level in an assembly
    ''' </summary>
    ''' <param name="oLinkDoc"></param>
    ''' <param name="level"></param>
    ''' <returns></returns>
    Private Function processASM(oLinkDoc As RevisionManager.Document, ByVal level As Integer) As Integer
        Dim DeepestLevel As Integer = level
        Dim l As Integer = level + 1
        For Each oL As RevisionManager.Document In oLinkDoc.LinkedDocuments(1)
            If oL.LinkedDocuments(1).count > 0 Then
                level = processASM(oL, l)
                If level > DeepestLevel Then
                    DeepestLevel = level
                End If
            End If
        Next
        Return DeepestLevel
    End Function
Julian Guillo
Pixel Sistemas SL
Spain

Re: Asm Level Count

Creator
Creator
Hello @Julian,

That is correct, it can work!!

Thanks in advance,
Taco.