Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Assembly Groups - hide or delete contents

PLM World Member Genius PLM World Member Genius
PLM World Member Genius

I'm using an assembly with groups to help organize parts related to different product options. I'm trying to write a program to either hide or delete the contents of the group when an option is not needed.

I was hoping it was as simple as traversing a structure similar to how the pathfinder is laid out, but it seems like a lot more is going to have to go into this.

 

Has anyone already done this and has some tips.

1 REPLY 1

Re: Assembly Groups - hide or delete contents

Solution Partner Valued Contributor Solution Partner Valued Contributor
Solution Partner Valued Contributor

Hi,

 

Here is a quick example that allows to Hide or Show components from a nammed group.

 

        Dim GroupeName As String = "Assembly Group_1"
        Dim DisplayElem As Boolean = False

        SolidEdgeCommunity.OleMessageFilter.Register()

        Dim objApplication As SolidEdgeFramework.Application = Nothing
        Dim ObjDoc As SolidEdgeAssembly.AssemblyDocument = Nothing
        Dim objGroups As SolidEdgeAssembly.AssemblyGroups = Nothing
        Dim objGroup As SolidEdgeAssembly.AssemblyGroup = Nothing

        Try

            objApplication = CType(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)
        Catch ex As Exception
            If Not (objApplication Is Nothing) Then
                Marshal.ReleaseComObject(objApplication)
                objApplication = Nothing
            End If
            Return
        End Try

        Try
            If Not (objApplication.ActiveDocumentType = SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument) Then
                If Not (objApplication Is Nothing) Then
                    Marshal.ReleaseComObject(objApplication)
                    objApplication = Nothing
                End If
                Return
            End If

        Catch ex As Exception
            If Not (objApplication Is Nothing) Then
                Marshal.ReleaseComObject(objApplication)
                objApplication = Nothing
            End If
            Return
        End Try

        Try
            ObjDoc = DirectCast(objApplication.ActiveDocument, SolidEdgeAssembly.AssemblyDocument)
            'Get Groups
            objGroups = ObjDoc.AssemblyGroups

            Dim objList As New List(Of Object)

            For Each objGroup In objGroups
                If objGroup.Name.ToUpper = GroupeName.ToUpper Then
                    Dim groupComponents As System.Array = System.Array.CreateInstance(GetType(Object), 0)
                    objGroup.GetComponents(groupComponents)

                    If groupComponents IsNot Nothing Then
                        objList.AddRange(groupComponents)
                    End If
                End If
            Next

            If objList.Count > 0 Then
                For Each elem In objList
                    elem.visible = DisplayElem
                Next
            End If

        Catch ex As Exception

        Finally
            If Not (objGroup Is Nothing) Then
                Marshal.ReleaseComObject(objGroup)
                objGroup = Nothing
            End If
            If Not (objGroups Is Nothing) Then
                Marshal.ReleaseComObject(objGroups)
                objGroups = Nothing
            End If
            If Not (ObjDoc Is Nothing) Then
                Marshal.ReleaseComObject(ObjDoc)
                ObjDoc = Nothing
            End If
            If Not (objApplication Is Nothing) Then
                Marshal.ReleaseComObject(objApplication)
                objApplication = Nothing
            End If
        End Try
        SolidEdgeCommunity.OleMessageFilter.Unregister()

 

Hope this can help you.

 

Regards,

 

Romuald