简体   繁体   中英

Run CATIA VBA macro in batch mode from Visual Studio

I have created a VB class to manipulate a CATIA project. The VB code is compiled into a dll loaded into a C# project.

Imports ProductStructureTypeLib
Imports INFITF
Imports MECMOD

Public Class MyCATIAClass
    Private catia As INFITF.Application

    Public Sub New()
        catia = GetObject(, "CATIA.Application")
    End Sub

    Public Sub doStuff()
        ' do stuff
    End Sub

End Class

And in C#:

MyCATIAClass catOb = new MyCATIAClass();
catOb.doStuff();

This works just fine. My question is: Is it possible to run the method in batch mode? this would significantly increase the performance at run time.

you better create a batch file (and call the vbfile from inside it) and run it from the c# code by the following code Process.Start("path of your batch file\\nameOfBatchFile.bat")

Before that to create a batch file in a note pad write the following commands and save it as fileName.bat

@echo on
cd path of vbfileName    
start vbfileName

In order to execute tasks without visualization, it was enough to set the visible property to false.

Imports ProductStructureTypeLib
Imports INFITF
Imports MECMOD

Public Class MyCATIAClass
Private catia As INFITF.Application

Public Sub New()
    catia = GetObject(, "CATIA.Application")
End Sub

Public Sub doStuff()
    catia.Visible = False
    ' do stuff
End Sub

End Class

批量启动CATIA:“ C:\\ cv5 \\ B20 \\ win_b64 \\ code \\ bin \\ CNEXT.exe-批处理-env CATIA.V5R20.B20 -direnv C:\\ cv5env \\ CATEnv”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM