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!

CATIA CATScript: How Can I determine path to the folder where a script is running ?

Status
Not open for further replies.

MichalPon

Industrial
Aug 17, 2016
9
GB
Hello,

I want to create a macro with will be location independent. Right now I have issue with getting string containing location where macro starts.
Using code listed below I get an error msg: Object required 'WScript'

Sub CATMain()

Set objShell = CreateObject("Wscript.Shell")
strPath = Wscript.ScriptFullName <- error in this line
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
msgbox strFolder

End Sub

Can someone help me here ?

Thanks,
Michal
 
Replies continue below

Recommended for you

Are you sure you've loaded the library for 'Microsoft Scripting Runtime'?

"The CAD crashes only when you seek to add another spline" ~ Ancient Chinese Proverb
 
How can I load "Microsoft Scripting Runtime" library for CATScript ?
It's not VBA when I have option to add library in references.
 
I can't recall ever having imported a reference library for CatScript. However, you will find a bunch of forum posts when you search for using Imports for VB.Net, and how to use Catia with Visual Studio (VS201X).

Have you tried just dumping your code into the VBA editor built into Catia and checking that it works?



"Simplicity is the ultimate sophistication." ~ Leonardo Da Vinci
 
Hi,

You can try code bellow, I'm curios if you will get an error (most probably, yes). By the way, there are companies where you have to use only CATScripts or catvbs due to companies policy.

Code:
Sub CATMAin()
    Dim CATIA As Object
    Set CATIA = GetObject(, "CATIA.Application")
Set WScript = CreateObject("WSH.WScript") 
scriptdir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(wshShell.ScriptFullName)

    Msgbox scriptdir

End Sub


Regards
Fernando

- Romania
- EU
 
Hello,

I received following error when I try to use this code in line:
Set WScript = CreateObject("WSH.WScript")

ScriptingERR_1002
Description: ActiveX component can't create object: 'WSH.WScript'
 
Now, you have two solution:

1. See what Google is saying about this.
2. Workaround...create a CATScript who will run a vbs script file to do the job... don't forget to put both of them in same folder [bigsmile] .

If you can use some other language would be great for your purpose....

Code:
Language="VBSCRIPT"
Sub CATMain()
call CATIA.SystemService.ExecuteBackGroundProcessus("WScript.exe c:\Temp\Path_2_script.vbs")
End Sub

VBS file with name with vbs extention Path_2_script.vbs

Code:
scriptdir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)

    Msgbox scriptdir

Regards
Fernando

- Romania
- EU
 
Fernando,

It works well but my case is little more complicated. Let me explain.
Generally there are 3 files: AAA.CATScript, BBB.CATVBA, CCC.xlsx

User start from AAA.CATScript connected with CATVBA.
I need to identify path where AAA.CATScript was run to paste it into "strFilePath" for CATVBA.

Code:
Sub CATMain()

' [ Variables ] ***

Dim param()
Dim strFilePath, strFileName, strModule As String
Dim objSystemService As Variant

Set objSystemService = CATIA.SystemService

' [ Path, Name & Module for catvba ] ***

strFilePath = "\\network_server_location\VBA_Excel\"
strFileName = "BBB.catvba"
strModule = "BBB_1_0"

objSystemService.ExecuteScript strFilePath & strFileName , catScriptLibraryTypeVBAProject , strModule , "CATMain" , param

End Sub

After that step I need also to show same path in CATVBA for Excel file
Code:
strPath = "\\network_server_location\VBA_Excel\CCC.xlsx"

 
Well, I don't understand why you need macros in 3 different files but probably you have a good reason for that. Maybe you can put everything only in catvba or in vba in Excel... Anyway, from a vbs file you can also trigger a macro in an excel file without user intervention. Just check with Google for this workaround.

Regards
Fernando

- Romania
- EU
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top