×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

CATIA VBA - Active Macro Path
3

CATIA VBA - Active Macro Path

CATIA VBA - Active Macro Path

(OP)
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

RE: CATIA VBA - Active Macro Path

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!

RE: CATIA VBA - Active Macro Path

2
Hi weavedreamer.

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

CODE --> vba

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 

RE: CATIA VBA - Active Macro Path

(OP)
Thanks. kantoku and Little Cthulhu.

I can adapt that into the code I've got and be able to work with it accordingly.

RE: CATIA VBA - Active Macro Path

kantoku, do you know if there's a way to get path to a running CATScript?

RE: CATIA VBA - Active Macro Path

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

RE: CATIA VBA - Active Macro Path

Thanks for sharing, kantoku.

Your "VBA reflection" thing brought in some memories of technology we used a few years ago prior to .NET - VBA references

Hope someone will find it helpful someday.

RE: CATIA VBA - Active Macro Path

Great post kantoku and also a great article in coe forum, useful indeed.

I tried in the past for CATScript, I wasn't able to find something...interesting that you can find for simple vbs...

Regards
Fernando

https://www.youtube.com/playlist?list=PL9mSHa4SOed...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close