Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

CATIA VBA - Active Macro Path 3

Status
Not open for further replies.

weavedreamer

Automotive
Aug 1, 2007
279
0
0
US
I did a search for Active Macro Path.
What I am looking for is an equivalent in VBA for CATIA done in VBA for Excel

VBA: Show workbook location
Sub DisplayWorkbookPath()
MsgBox ActiveWorkbook.Path, vbInformation, "Workbook Path"
End Sub

Can something like this be accomplished within a VBA for CATIA macro?

Hard coding a precise path added the steps of executing the macro from the new location, getting a error, identifying the code responsible for the error and correcting the hard coded path.

Thanks for your consideration in this matter.
 
Replies continue below

Recommended for you

Hi.

VBA code in CATIA is very different from what we have in Microsoft Office applications because it's stored in a standalone file (.catvba), which is in fact is proprietary to DS.

And they doesn't expose any methods to work with that file. So you're left with VBE com object that represents VBA editor in which you can get currently active project (written in bold font in project tree) and it's path. There's no way to get currently executing project by any means.

UPD
See kantoku's post below

Great to know we still can access executing project, though not through VBE but APC directly!

 
Hi weavedreamer.

In case of CATIA V5 VBA, it is possible to get the project file path.
try this.
Code:
Option Explicit

Sub CATMain()
    'Apc取得
    Dim Apc As Object: Set Apc = GetApc()
    If Apc Is Nothing Then Exit Sub
    
    '実行中のVBProject取得
    Dim ExecPjt As Object: Set ExecPjt = Apc.ExecutingProject
    
    Dim Info$
    Info = "The project name of the currently executing macro is" & vbNewLine & _
           "[ " & ExecPjt.Name & " ]" & vbNewLine & _
           "The VBA project file path is" & vbNewLine & _
           "[ " & ExecPjt.DisplayName & " ]"
    MsgBox Info
End Sub

Private Function GetApc() As Object
    Set GetApc = Nothing
    
    'VBAバージョンチェック
    Dim COMObjectName$
    #If VBA7 Then
        COMObjectName = "MSAPC.Apc.7.1"
    #ElseIf VBA6 Then
        COMObjectName = "MSAPC.Apc.6.2"
    #Else
        MsgBox "VBA version is not supported"
        Exit Function
    #End If
    
    'APC取得
    Dim Apc As Object: Set Apc = Nothing
    On Error Resume Next
        Set Apc = CreateObject(COMObjectName)
    On Error GoTo 0
    
    If Apc Is Nothing Then
        MsgBox "MSAPC.Apc cannot be obtained"
        Exit Function
    End If
    
    Set GetApc = Apc
End Function
 
I have almost never written CATScript. For that reason, I have never investigated.

I also got the advice from other people on my blog about how to get the above CATVBA pass.

These macros (CATVBA) are created using VBA reflection.
Link
Link
 
Status
Not open for further replies.
Back
Top