简体   繁体   English

从Visual Studio以批处理模式运行CATIA VBA宏

[英]Run CATIA VBA macro in batch mode from Visual Studio

I have created a VB class to manipulate a CATIA project. 我创建了一个VB类来操纵CATIA项目。 The VB code is compiled into a dll loaded into a C# project. VB代码被编译成一个DLL,该DLL加载到C#项目中。

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#: 在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") 您最好创建一个批处理文件(并从其内部调用vbfile)并通过以下代码Process.Start(“批处理文件的路径\\ nameOfBatchFile.bat”)从c#代码运行该文件

Before that to create a batch file in a note pad write the following commands and save it as fileName.bat 在此之前,要在记事本中创建批处理文件,请编写以下命令并将其另存为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. 为了在不可视化的情况下执行任务,将visible属性设置为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”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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