Help me! In Dimensions....

Valued Contributor
Valued Contributor

 

Hi,

I'm developing an integration of Solid Edge with an ERP, and must see the dimensions used in the model. Got to get the size that the model is presented, but an error occurs when I'm initially working with a traditional paper and read the size of it and then move to a model synchronized. The moment I try to read the dimensions of the synchronous model is the following error:

"Retun argument has type is invalid."

 

This error always occurs when I open the document of a type (sinconizado or traditional) and without closing the Solid Edge, I open the other ...

I'm using VB.NET 2008 and the Solid Edge ST

 

Thank you!

 

===========Conection Object===============

Imports Microsoft.VisualBasic

Imports Microsoft.Win32

Imports SolidEdgeFramework

Imports SolidEdgeConstants

Imports System

Imports System.Collections

Imports System.Reflection

Imports System.Runtime.InteropServices

Imports System.Windows.Forms

Namespace IntegraSE

    ''' Esta é a Classe Base para Solid Edge Addin.

    ''' Se usar este projeto como um template, terá que gerar um novo GuidAttribute e atualizar o ProgId se você mudar o nome.

    _

    Public Class Addin

        Implements SolidEdgeFramework.ISolidEdgeAddIn, SolidEdgeFramework.ISEAddInEvents

 

        Private addin As SolidEdgeFramework.AddIn

        Private application As SolidEdgeFramework.Application

        Private connectionPoints As New Hashtable

 

#Region "Membros de ISolidEdgeAddin"

        Public Sub OnConnection(ByVal Application As Object, ByVal ConnectMode As SolidEdgeFramework.SeConnectMode, ByVal AddInInstance As SolidEdgeFramework.AddIn) Implements SolidEdgeFramework.ISolidEdgeAddIn.OnConnection

            'Informa a versão GUI

            AddInInstance.GuiVersion = 1

 

            'Alimenta as variáveis para usar depois

            Me.addin = AddInInstance

            Me.application = Application

 

            Try

                'SolidEdgeFramework.ISEddInEvents

                HookEvents(Me.addin, New Guid("{0F539244-4816-11D2-B5AC-080036E8B802}"))

            Catch ex As Exception

                MessageBox.Show(ex.Message, "Erro na conexão dos eventos.", MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try

        End Sub

 

        Public Sub OnConnectToEnvironment(ByVal EnvCatID As String, ByVal pEnvironmentDispatch As Object, ByVal bFirstTime As Boolean) Implements SolidEdgeFramework.ISolidEdgeAddIn.OnConnectToEnvironment

            Dim commandNames(4) As String

            Dim commandIDs(4) As Integer

            Try

                commandNames(0) = (String.Format("Cadastro{0}Cadastro da Peça / Conjunto{1}Cadastro da Peça / Conjunto{2}Cadastro da Peça / Conjunto", ControlChars.Lf, ControlChars.Lf, ControlChars.Lf))

                commandNames(1) = (String.Format("Banco{0}Cadastro do Sistema de Gestão{1}Cadastro do Sistema de Gestão{2}Cadastro do Sistema de Gestão", ControlChars.Lf, ControlChars.Lf, ControlChars.Lf))

                commandNames(2) = (String.Format("Configura{0}Configurações{1}Configurações{2}Configurações", ControlChars.Lf, ControlChars.Lf, ControlChars.Lf))

                commandNames(3) = (String.Format("Ajuda{0}Ajuda{1}Ajuda{2}Ajuda", ControlChars.Lf, ControlChars.Lf, ControlChars.Lf))

                commandNames(4) = (String.Format("Sobre{0}Sobre o IntegraSE{1}Sobre o IntegraSE{2}Sobre o IntegraSE", ControlChars.Lf, ControlChars.Lf, ControlChars.Lf))

                commandIDs(0) = 101

                commandIDs(1) = 102

                commandIDs(2) = 103

                commandIDs(3) = 104

                commandIDs(4) = 105

                addin.SetAddInInfo(Marshal.GetHINSTANCE(Me.GetType().Module).ToInt32(), EnvCatID, "IntegraSE", 1, 2, 1, 2, commandIDs.Length, commandNames, commandIDs)

 

                'If (bFirstTime) Then

                Dim environment As SolidEdgeFramework.Environment

                environment = pEnvironmentDispatch

                environment.CommandBars.Add("IntegraSE", SolidEdgeFramework.SeBarPosition.seBarTop, False, False)

                'Botão Cadastro

                Dim btnCadastro, btnBanco, btnConfigura, btnAjuda, btnSobre As SolidEdgeFramework.ISECommandBarButton

                btnCadastro = addin.AddCommandBarButton(EnvCatID, "IntegraSE", 101)

                btnCadastro.LoadFace(My.Application.Info.DirectoryPath + "\Cadastro.bmp")

                btnCadastro.Caption = "Cadastro da Peça / Conjunto"

                btnCadastro.DescriptionText = "Cadastro da Peça / Conjunto"

                btnCadastro.TooltipText = "Cadastro da Peça / Conjunto"

                'Botão Banco

                btnBanco = addin.AddCommandBarButton(EnvCatID, "IntegraSE", 102)

                btnBanco.LoadFace(My.Application.Info.DirectoryPath + "\Banco.bmp")

                btnBanco.Caption = "Cadastro do Sistema de Gestão"

                btnBanco.DescriptionText = "Cadastro do Sistema de Gestão"

                btnBanco.TooltipText = "Cadastro do Sistema de Gestão"

                'Botão Configura

                btnConfigura = addin.AddCommandBarButton(EnvCatID, "IntegraSE", 103)

                btnConfigura.LoadFace(My.Application.Info.DirectoryPath + "\Configura.bmp")

                btnConfigura.Caption = "Configurações"

                btnConfigura.DescriptionText = "Configurações"

                btnConfigura.TooltipText = "Configurações"

                'Botão Ajuda

                btnAjuda = addin.AddCommandBarButton(EnvCatID, "IntegraSE", 104)

                btnAjuda.LoadFace(My.Application.Info.DirectoryPath + "\Ajuda.bmp")

                btnAjuda.Caption = "Ajuda"

                btnAjuda.DescriptionText = "Ajuda"

                btnAjuda.TooltipText = "Ajuda"

                'Botão Sobre

                btnSobre = addin.AddCommandBarButton(EnvCatID, "IntegraSE", 105)

                btnSobre.LoadFace(My.Application.Info.DirectoryPath + "\Lógica.bmp")

                btnSobre.Caption = "Sobre o IntegraSE"

                btnSobre.DescriptionText = "Sobre o IntegraSE"

                btnSobre.TooltipText = "Sobre o IntegraSE"

 

 

                'End If

            Catch ex As Exception

                MessageBox.Show(ex.Message)

            End Try

        End Sub

 

        Public Sub OnDisconnection(ByVal DisconnectMode As SolidEdgeFramework.SeDisconnectMode) Implements SolidEdgeFramework.ISolidEdgeAddIn.OnDisconnection

            On Error Resume Next

            UnhookEvents()

        End Sub

#End Region

#Region "Membros de ISEAddinEvents"

        Public Sub OnCommand(ByVal CommandID As Integer) Implements SolidEdgeFramework.ISEAddInEvents.OnCommand

            'Para saber os números dos comandos usar o SolidEdgeSpy.exe (Jason Program)

            'application.StartCommand(57601)

            Select Case CommandID

                Case 101 'Cadastro

                    Dim objDocumment As SolidEdgeFramework.SolidEdgeDocument = Nothing

                    objDocumment = application.ActiveDocument

                    If Not (objDocumment Is Nothing) Then

                        If objDocumment.Type SolidEdgeFramework.DocumentTypeConstants.igPartDocument And objDocumment.Type SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument _

                        And objDocumment.Type SolidEdgeFramework.DocumentTypeConstants.igSheetMetalDocument And objDocumment.Type SolidEdgeFramework.DocumentTypeConstants.igSyncAssemblyDocument And _

                        objDocumment.Type SolidEdgeFramework.DocumentTypeConstants.igSyncPartDocument And objDocumment.Type SolidEdgeFramework.DocumentTypeConstants.igSyncSheetMetalDocument And _

                        objDocumment.Type SolidEdgeFramework.DocumentTypeConstants.igWeldmentAssemblyDocument And objDocumment.Type SolidEdgeFramework.DocumentTypeConstants.igWeldmentDocument Then

                            MessageBox.Show("O documento aberto é inválido para cadastro!", "IntegraSE", MessageBoxButtons.OK, MessageBoxIcon.Information)

                        Else

                            'Verifica a permissão

                            If Permissão() = True Then                               

                                Dim Cadastro As New Cadastro

                                Cadastro.pApplication = application

                                Cadastro.ShowDialog(New SolidEdgeFwk.ApplicationWindow(application.hWnd))

                            Else

                                MsgBox("O Sistema de Gestão deve estar aberto nesta estação!", MsgBoxStyle.Critical, "IntegraSE")

                                Exit Sub

                            End If

                        End If

                    Else

                        MessageBox.Show("Não há documentos abertos!", "IntegraSE", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

                    End If

                Case 102 'Banco

                    'Verifica se o Banco de Acesso está setado

                    If My.Settings.BancoAcesso Nothing Then

                        'Verifica a permissão

                        If Permissão() = True Then

                            Dim Banco As New Banco

                            Banco.ObjChamada = "Botão"

                            Banco.ShowDialog(New SolidEdgeFwk.ApplicationWindow(application.hWnd))

                        Else

                            MsgBox("O Sistema de Gestão deve estar aberto nesta estação!", MsgBoxStyle.Critical, "IntegraSE")

                            Exit Sub

                        End If

                    Else 'senão

                        'Avisa o Usuário

                        MsgBox("Gerenciador do Banco de Dados não está Definido!", MsgBoxStyle.Critical, "IntegraSE")

                    End If

                Case 103 'Configura

                    Dim Configura As New Configura

                    Configura.ShowDialog(New SolidEdgeFwk.ApplicationWindow(application.hWnd))

                Case 104 'Ajuda

                    MessageBox.Show("Não Implementado")

                Case 105 'Sobre

                    Dim Sobre As New Sobre

                    Sobre.ShowDialog(New SolidEdgeFwk.ApplicationWindow(application.hWnd))

            End Select

        End Sub

 

        Public Sub OnCommandHelp(ByVal hFrameWnd As Integer, ByVal HelpCommandID As Integer, ByVal CommandID As Integer) Implements SolidEdgeFramework.ISEAddInEvents.OnCommandHelp

 

        End Sub

 

        Public Sub OnCommandUpdateUI(ByVal CommandID As Integer, ByRef CommandFlags As Integer, ByRef MenuItemText As String, ByRef BitmapID As Integer) Implements SolidEdgeFramework.ISEAddInEvents.OnCommandUpdateUI

 

        End Sub

#End Region

#Region "Classe de Funções Privadas"

        ''' Método customizado para manipular "hooking" nos eventos do Solid Edge

        '''

        '''        

        Private Sub HookEvents(ByVal source As Object, ByVal eventGUID As Guid)

            Try

                ' Converte o source usando a interface UCOMIConnectionPointContainer.

                Dim connectionPointContainer As UCOMIConnectionPointContainer = source

                Dim connectionPoint As UCOMIConnectionPoint

 

                If Not (connectionPointContainer Is Nothing) Then

                    ' Responde como um objeto conectável somente se  possui um ponto de conexão para uma GUID particular,

                    ' e retorna a interface IConnectionPoint para o ponto de conexão.

                    connectionPointContainer.FindConnectionPoint(eventGUID, connectionPoint)

                    If Not (connectionPoint Is Nothing) Then

                        Dim cookie As Integer = 0

                        ' Estabelece conexão entre o ponto de conexão e a chamada do objeto.

                        connectionPoint.Advise(Me, cookie)

                        If (cookie 0) Then

                            ' Add the UCOMIConnectionPoint to the Hashtable.

                            connectionPoints.Add(connectionPoint, cookie)

                        Else

                            Throw New System.Exception("A Conexão entre o ponto de conexão e o objeto chamado falhou.")

                        End If

                    End If

                Else

                    Throw New System.Exception("Fonte não implementada IConnectionPointContainer.")

                End If

            Catch ex As Exception

                Throw ex

            End Try

        End Sub

        '''Método personalizado para remover qualquer hooks adicionados aos eventos.

        Private Sub UnhookEvents()

            Dim connectionPoint As UCOMIConnectionPoint

 

            Try

                ' Unadvise the UCOMIConnectionPoint objects.

                Dim enumerator As IDictionaryEnumerator = connectionPoints.GetEnumerator()

                While (enumerator.MoveNext())

                    connectionPoint = enumerator.Key

                    connectionPoint.Unadvise(enumerator.Value)

                End While

 

                ' Clear the Hashtable

                connectionPoints.Clear()

            Catch ex As Exception

 

            End Try

        End Sub

#End Region

#Region "Funções Regasm.exe"

        '''

        ''' Specifies the method to call when you register an assembly for use from COM; this allows for the execution of user-written code during the registration process.

        '''

        _

        Public Shared Sub RegisterFunction(ByVal t As Type)

            Dim baseKey As RegistryKey

            Dim summaryKey As RegistryKey

            Dim title As AssemblyTitleAttribute

            Dim description As AssemblyDescriptionAttribute

 

            Try

                title = AssemblyTitleAttribute.GetCustomAttribute(t.Assembly, Type.GetType("System.Reflection.AssemblyTitleAttribute"))

                description = AssemblyDescriptionAttribute.GetCustomAttribute(t.Assembly, Type.GetType("System.Reflection.AssemblyDescriptionAttribute"))

                baseKey = Registry.ClassesRoot.CreateSubKey("CLSID\{" & t.GUID.ToString & "}")

 

                If Not (baseKey Is Nothing) Then

                    ' Write required registry entries for a Solid Edge Addin.

                    baseKey.SetValue("AutoConnect", 1)

                    baseKey.SetValue("409", title.Title)

                    baseKey.CreateSubKey("Implemented Categories\" & SolidEdgeConstants.CATIDS.CATID_SolidEdgeAddIn)

 

                    ' The following keys determine which environments your addin will connect to.

                    baseKey.CreateSubKey("Environment Categories\" & SolidEdgeConstants.CATID_SEApplication)

                    baseKey.CreateSubKey("Environment Categories\" & SolidEdgeConstants.CATID_SEAllEnvironmentDocuments)

                    'baseKey.CreateSubKey("Environment Categories\" & SolidEdgeConstants.CATID_SEAssembly)

                    'baseKey.CreateSubKey("Environment Categories\" & SolidEdgeConstants.CATID_SEDraft)

                    'baseKey.CreateSubKey("Environment Categories\" & SolidEdgeConstants.CATID_SEPart)

                    'baseKey.CreateSubKey("Environment Categories\" & SolidEdgeConstants.CATID_SESheetMetal)

                    'baseKey.CreateSubKey("Environment Categories\" & SolidEdgeConstants.CATID_SEWeldment)

 

                    ' This will be the Description text that is displayed in the SE Addin Manager.

                    summaryKey = baseKey.CreateSubKey("Summary")

                    If Not (summaryKey Is Nothing) Then

                        summaryKey.SetValue("409", description.Description)

                        summaryKey.Close()

                    End If

                    baseKey.Close()

                End If

            Catch

 

            End Try

        End Sub

 

        '''

        ''' Specifies the method to call when you unregister an assembly for use from COM; this allows for the execution of user-written code during the unregistration process.

        '''

        _

        Public Shared Sub UnregisterFunction(ByVal t As Type)

            'On Error Resume Next

            ' Remove any previously written registry entries.

            Try

                Registry.ClassesRoot.DeleteSubKeyTree("CLSID\{" + t.GUID.ToString() + "}")

            Catch ex As Exception

 

            End Try

 

            Try

                CleanupSolidEdgeCurrentUser(Registry.CurrentUser.OpenSubKey("Software\Unigraphics Solutions\Solid Edge"), "{" + t.GUID.ToString() + "}")

            Catch ex As Exception

 

            End Try

 

        End Sub

 

        '''

        ''' Solid Edge does not automatically cleanup some addin entries under HKEY_CURRENT_USER.  This recursive function will delete only keys that match the GUID of this addin.

        '''

        Public Shared Sub CleanupSolidEdgeCurrentUser(ByVal key As RegistryKey, ByVal guid As String)

            Dim subkeys() As String

 

            ' Get all SubKeys names for the passed RegistryKey.

            subkeys = key.GetSubKeyNames()

 

            For Each subkey As String In subkeys

 

Posted by: Fabio Rosa
Post date: 4/7/2009 4:40:00 AM