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
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 ?
"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 ?
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 ?
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 ?
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 SubRegards
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 ?
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 ?
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
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 SubVBS file with name with vbs extention Path_2_script.vbs
CODE --> vbs
scriptdir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) Msgbox scriptdirRegards
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 ?
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
After that step I need also to show same path in CATVBA for Excel file
CODE --> CATVBA
RE: CATIA CATScript: How Can I determine path to the folder where a script is running ?
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU