Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launch CATVBA Macro from CATScript

Status
Not open for further replies.

jzecha

Aerospace
Jan 20, 2016
235
US
I have scoured the internet and I am unable to find a way to launch a CATVBA macro from a CATSCript.

The only purpose of this script is to Launch the VBA Macro.

Can somebody help me out and provide me the basic code I need?
 
Replies continue below

Recommended for you

Why wouldn't you just launch the CATVBA code instead? I'm not understanding why you would need this.
 
The CATVBA code I am trying to launch is a Macro Menu I have created and shared with my department.
The Macro is an Icon on everyone's toolbar.

The issue I have is that I can't modify the Macro Menu because it is being referenced by everyone in my department when Catia launches.
So if I put a buffer in there to the only time it is referenced, is when the CATScript calls it to open, I could modify the Macro Menu it at any point.
 
Try:

Sub CATMain()

DraftingUtilty.Show vbModeless

End Sub



DraftingUtility is the name of my VBA code. Vbmodeless allows it to launch and let the user still work/make selections in catia. The opposite, not allowing any slections in CATIA is Vbmodal. I use this for your exact application, it opens a userform that has many different macros for V5.
 
Sub CATMain()

Dim ProjPath As String
Dim strModule As String
Dim strProcedure As String
'Dim varArgs() As Variant 'Use empty array if procedure has no args
Dim varArgs(0) As Variant 'Or size the array if procedure has args
Dim strMsg As String

'Define where to find the VBA project and what to run inside it.
ProjPath = "C:\temp\PROJECT.catvba"
strModule = "MainModule"
strProcedure = "CATMain"

'If the procedure has arguments, define them in the array
'As an example, a Sub with 3 input arguments in the VBA project
'Sub CATMain(iInputfile, iOutputFile, iPart)
varArgs(0) = InputFile.txt
'varArgs(1) = "C:\Data\OutputData.txt"
'Set varArgs(2) = CATIA.ActiveDocument.Part

'Launch the VBA project
On Error Resume Next
Call CATIA.SystemService.ExecuteScript(ProjPath, _
2, strModule, strProcedure, varArgs)
If Err.Number <> 0 Then 'Any number other than zero is an error
'Add your own custom error message to the user
strMsg = "An error occurred while trying to run the macro..."
MsgBox strMsg, 16, "Error"
End If

End Sub

regards,
LWolf
 
L WOLF, that worked perfectly thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top