Reply

activate In-place edit on an occurrence

Does anybody know a method to do this?  The main reason is so a user sees the dimensions I set up and can change them.

 

Then, how do I exit the in-place and go back to the main assembly?

1 REPLY

Re: activate In-place edit on an occurrence

You can try to use this two functions.

 

#Region "InactivateInPlace"
    ''' <summary>
    '''InactivateInPlace -- Get back to the top level assembly when occurrence is activated in place.
    ''' </summary>
    ''' <code lang="vbnet">...</code>
    Public Sub InactivateInPlace(
ByRef Int_Result As Integer, _
ByRef Msg_Result As String)

        Int_Result = 1 'NOTIFY
        Msg_Result = "InactivateInPlace -- Succes"


        Dim objApplication As SolidEdgeFramework.Application = Nothing
        Dim ObjAsm As SolidEdgeAssembly.AssemblyDocument = Nothing

        Try
            objApplication = CType(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)
        Catch ex As Exception
            Int_Result = 3 'FAIL
            Msg_Result = "InactivateInPlace -- Can't access Solid Edge"
            If Not (objApplication Is Nothing) Then
                Marshal.ReleaseComObject(objApplication)
                objApplication = Nothing
            End If
            Return
        End Try


        Try
            If objApplication.ActiveDocument.InPlaceActivated Then
                objApplication.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyFileCloseandReturn)
                objApplication.DoIdle()
            Else
                Int_Result = 3 'FAIL
                Msg_Result = "InactivateInPlace -- Active file is not in place activated."
            End If
        Catch ex As Exception
            Int_Result = 3 'FAIL
            Msg_Result = "InactivateInPlace -- Can't access Solid Edge"
            If Not (objApplication Is Nothing) Then
                Marshal.ReleaseComObject(objApplication)
                objApplication = Nothing
            End If
        End Try

        If Not (objApplication Is Nothing) Then
            Marshal.ReleaseComObject(objApplication)
            objApplication = Nothing
        End If

    End Sub
#End Region

#Region "ActivateInPlace"
    ''' <summary>
    '''ActivateInPlace -- Activate in place an assembly occurrence.
    ''' </summary>
    ''' <param name="OccName">Path to the occurrence.</param>
    ''' <param name="OccSep">Occurrence path separator. Default "@"</param>
    ''' <code lang="vbnet">...</code>
    Public Sub ActivateInPlace( _
ByVal OccName As String, _
ByVal OccSep As String, _
ByRef Int_Result As Integer, _
ByRef Msg_Result As String)

        Int_Result = 1 'NOTIFY
        Msg_Result = "ActivateInPlace -- Success"

        If OccSep = "" Then OccSep = "@"

        Dim PathList() As String = OccName.Split(OccSep)

        Dim objApplication As SolidEdgeFramework.Application = Nothing
        Dim ObjAsm As SolidEdgeAssembly.AssemblyDocument = Nothing

        Try
            objApplication = CType(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)
        Catch ex As Exception
            Int_Result = 3 'FAIL
            Msg_Result = "ActivateInPlace -- Can't access Solid Edge"
            If Not (objApplication Is Nothing) Then
                Marshal.ReleaseComObject(objApplication)
                objApplication = Nothing
            End If
            Return
        End Try


        Try
            If objApplication.ActiveDocumentType = SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument Then
                ObjAsm = objApplication.ActiveDocument
                Dim Occs As SolidEdgeAssembly.Occurrences = ObjAsm.Occurrences
                Dim Occ As SolidEdgeAssembly.Occurrence = Nothing

                Dim SubOccs As SolidEdgeAssembly.Occurrences = Nothing
                Dim SubOcc As SolidEdgeAssembly.Occurrence = Nothing

                Select Case PathList.Count
                    Case Is = 1 'Top Level
                        For Each Occ In Occs
                            If OccName=Occ.Name Then
                                Occ.Select(True)
                                objApplication.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyEditActivateembeddedorlinkedobject)
                                objApplication.DoIdle()
                                Exit For
                            End If
                        Next
                    Case Is > 1 ' Sub level
                        'Récupérer la référence
                        Dim ObjOccRef As SolidEdgeFramework.Reference = Nothing
                        Dim ObjOccTempRef As SolidEdgeFramework.Reference = Nothing
                        Dim ObjTopASSY As AssemblyDocument = objApplication.ActiveDocument

                        Dim objOccur1 As Occurrence
                        Dim objOccDoc1 As AssemblyDocument

                        For Each Occ In Occs
                            If NameIsOk(PathList(0), Occ.Name) Then
                                objOccur1 = Occ
                                objOccDoc1 = objOccur1.OccurrenceDocument

                                ObjOccRef = createTopASMRef_IPA(objOccDoc1, objOccur1, PathList, 1)
                                Exit For
                            End If
                        Next
                        If Not ObjOccRef Is Nothing Then
                            ObjAsm.SelectSet.RemoveAll()
                            ObjAsm.SelectSet.Add(ObjOccRef)
                            objApplication.StartCommand(SolidEdgeConstants.AssemblyCommandConstants.AssemblyEditActivateembeddedorlinkedobject)
                            objApplication.DoIdle()
                        End If

                End Select

            Else
                Int_Result = 3 'FAIL
                Msg_Result = "ActivateInPlace -- Active file is not an assembly."
            End If
        Catch ex As Exception
            Int_Result = 3 'FAIL
            Msg_Result = "ActivateInPlace -- Can't access Solid Edge"
            If Not (objApplication Is Nothing) Then
                Marshal.ReleaseComObject(objApplication)
                objApplication = Nothing
            End If
        End Try

        If Not (objApplication Is Nothing) Then
            Marshal.ReleaseComObject(objApplication)
            objApplication = Nothing
        End If

    End Sub
    Private Function createTopASMRef_IPA(ByVal ObjContext As SolidEdgeAssembly.AssemblyDocument, ByVal PreviousOcc As Occurrence, ByVal PathList() As String, ByVal Index As Integer) As SolidEdgeFramework.Reference
        Dim pOcc As SolidEdgeAssembly.Occurrence
        Dim pRef As SolidEdgeFramework.Reference
        Dim SubOccs As Occurrences
        Dim ObjOccTempRef As SolidEdgeFramework.Reference = Nothing
        createTopASMRef_IPA = Nothing

        Try
            If ObjContext.Occurrences.Count > 0 Then
                SubOccs = ObjContext.Occurrences

                For Each SubOcc In SubOccs
                    If PathList(Index)= SubOcc.Name Then
                        If Index = PathList.Count - 1 Then
                            Dim objOccur3 As Occurrence
                            objOccur3 = SubOcc
                            ObjOccTempRef = PreviousOcc.Parent.Parent.CreateReference(Occurrence:=PreviousOcc, Entity:=objOccur3)
                        Else
                            Dim objOccur2 As Occurrence
                            Dim objOccDoc2 As AssemblyDocument
                            objOccur2 = SubOcc
                            objOccDoc2 = objOccur2.OccurrenceDocument

                            ObjOccTempRef = createTopASMRef_IPA(objOccDoc2, objOccur2, PathList, Index + 1)
                            ObjOccTempRef = PreviousOcc.Parent.Parent.CreateReference(Occurrence:=PreviousOcc, Entity:=ObjOccTempRef)
                        End If
                        Exit For

                    End If
                Next
                createTopASMRef_IPA = ObjOccTempRef
            End If
        Catch ex As Exception
            createTopASMRef_IPA = Nothing
        End Try

        'Clean it all.
        pOcc = Nothing
        pRef = Nothing
        'GC.Collect()
    End Function
#End Region

Romuald BERTIN