GetObject not working if CATIA is launched with PowerShell

Samarinder Singh

GetObject not working if CATIA is launched with PowerShell

Hi,

I launched CATIA thru PowerShell and then I got an error when using GetObject. I would like to know if there is any solution to it? Thanks.

Error
System.Exception: Cannot create ActiveX component.
   at Microsoft.VisualBasic.Interaction.GetObject(String PathName, String Class)
 

PS1
$exe1 ="D:\Apps\Dassault Systemes\B28\win_b64\code\bin\CATSTART.exe"
$Args1 = @('-run', '"CNEXT.exe"', '-env', 'CATIA.V5R28' , '-direnv', '"C:\Users\admin\AppData\Roaming\DassaultSystemes\CATEnv"', '-nowindow')
Start-Process -FilePath $exe1 -Argumentlist $Args1

VB.net
Try
    CATIA = GetObject(, "CATIA.Application")
Catch ex As Exception
    'str1 = ex.ToString
End Try

Regards,
Samarinder Singh Cheema

Little Cthulhu

RE: GetObject not working if CATIA is launched with PowerShell
(in response to Samarinder Singh)

Code works fine for me.

How exactly do you run powershell script and vb.net code?

Samarinder Singh

RE: GetObject not working if CATIA is launched with PowerShell
(in response to Little Cthulhu)

Thanks for the reply. I found the problem occurs if ps1 is run in admin mode. And I need to run it in admin mode for CNEXT.exe /regserver. Earlier I didn't mention about the regserver in my ps1 file. I launch this ps script interactively from a shortcut which is set to run in admin mode. Then I run VB.net App as usual in Visual Studio. I wonder if there is any way to avoid this error and keep all in one ps1 file.

Edit: One more thing, Spacepilot 3dmouse doesn't work either in this case.

Regards,
Samarinder Singh Cheema
Edited By:
Samarinder Singh[Organization Members] @ Jul 06, 2021 - 12:12 AM (America/Pacific)

Little Cthulhu

RE: GetObject not working if CATIA is launched with PowerShell
(in response to Samarinder Singh)

Have you tried launching VB.NET app as admin as well?

I also suggest running powershell script in non-admin mode and to execute /regserver in a separate elevated process as described on Stackoverflow.