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!

Run CATScript from VBA Application

Status
Not open for further replies.

HarunMusic

Computer
Nov 21, 2014
71
BA
HI guys,

I have some problems for example, i do not have problems when i run catscript to define in Geometrical Set (pardocument1.part.InWorkObject = hybridBody1)
but when i write this line in Visual studio i get error, i have same problems with other things :(

So i think to make simple CATScript for this action and run it from my Vba Application in Visual studio, but again i have problems :(

I tried like this
ScPath = "C:\Users\Me\Desktop\Macro_recoring\"
CATIA.SystemService.ExecuteScript(ScPath, INFITF.CatScriptLibraryType.catScriptLibraryTypeDirectory, "Macro22.CATScript", "CATMain", EmptyPar)

Any ideas?

Thx
 
Replies continue below

Recommended for you

This is what I use...

Sub CATMain()

Dim strPath As String
Dim strModule As String
Dim strProcedure As String
Dim varArgs() As Variant 'Use empty array if procedure has no args
'Dim varArgs(2) 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.
strPath = "\\XXX\YYY.catvba"
strModule = "MAIN"
strProcedure = "MAIN"

'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) = "C:\Data\InputData.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(strPath, _
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top