×
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!
  • Students Click Here

*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

Jobs

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

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

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

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

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

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

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

(OP)
How can I load "Microsoft Scripting Runtime" library for CATScript ?
It's not VBA when I have option to add library in references.

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

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

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

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 --> CATScript

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

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

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

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

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

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 --> CATScript

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 --> vbs

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

    Msgbox scriptdir 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

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

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

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 --> CATVBA

strPath = "\\network_server_location\VBA_Excel\CCC.xlsx" 

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

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

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

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!


Resources