'Written by Lionel Hutz 'Version 1.0 22.12.2024 'first published at ' https://ww3.cad.de/foren/ubb/Forum137/HTML/007077.shtml (German) ' https://ww3.cad.de/foren/ubb/Forum137/HTML/007078.shtml (English) Option Explicit Sub CATMain() Dim SService As SystemService Dim sCATEnvName As String Dim sCATEnvDirectory As String Dim sSetings As String Dim sCATInstallPathAll As String Dim sCATInstallPathArray As String Dim sCATInstallPath As String Dim sCATTemp As String Dim sLicPack As String Dim env_dir As String Dim env_file As String Dim install_path As String Dim sNewBatchFile As String Dim oNewFile as File Dim oStream as TextStream Dim Zeile As String Dim TextStream Dim sInputFile As String Dim FSO As FileSystemObject '####### Get System Imnformation from Catia ####### Set SService = CATIA.SystemService sCATEnvName = SService.Environ("CATEnvName") sCATEnvDirectory = ExtractDirectory(sCATEnvName) sCATEnvName = ExtractFileName(sCATEnvName) sSetings = SService.Environ("CATUserSettingPath") 'Fallst mehrere Installationsverzeichnisse in der Enviroment stehen, wird das erste verwendet sCATInstallPathAll = SService.Environ("CATInstallPath") sCATInstallPathArray = Split(sCATInstallPathAll,";") sCATInstallPath = sCATInstallPathArray(0) sLicPack = LicensePack env_dir = sCATEnvDirectory env_file = sCATEnvName sCATTEMP = SService.Environ("CATTemp") install_path = sCATInstallPath '######### Prepare Targetfile ######### sNewBatchFile = "C:\temp\STP2Catia.bat" ' get oNewFile set FSO = CreateObject("Scripting.FileSystemObject") If FSO.FileExists(sNewBatchFile) then 'MsgBox "FileExists sNewBatchFile" ' oOutputFile bereitstellen Set oStream = FSO.OpenTextFile(sNewBatchFile, 2, True) Else Set oStream = FSO.CreateTextFile(sNewBatchFile) End If '##### Write Targetfile ####### oStream.WriteLine "REM Written by Lionel Hutz" oStream.WriteLine "REM Version 1.0 22.12.2024" oStream.WriteLine "REM first published at " oStream.WriteLine "REM https://ww3.cad.de/foren/ubb/Forum137/HTML/007077.shtml (German)" oStream.WriteLine "REM https://ww3.cad.de/foren/ubb/Forum137/HTML/007078.shtml (English)" oStream.WriteLine "@ECHO OFF" oStream.WriteLine "SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION" oStream.WriteLine "REM ------------Local CATIA Settings---------------" oStream.WriteLine "set sLicPack="&sLicPack oStream.WriteLine "set env_dir="&env_dir oStream.WriteLine "set env_file="&env_file oStream.WriteLine "set sCATTEMP="&sCATTEMP oStream.WriteLine "set install_path="&install_path oStream.WriteLine "" ' '###################### Paste new source-code below this comment. ############################## oStream.WriteLine "REM -------------File Properties----------------" oStream.WriteLine "SET /A count = 0" oStream.WriteLine "SET sTimestamp=%date:~6,4%%date:~3,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,2%" oStream.WriteLine "SET sTimestamp=%sTimestamp: =0%" oStream.WriteLine "SET sBatchfile=Batch_stp_%sTimestamp%_%Random%.xml" oStream.WriteLine "SET BatchFileFull=%sCATTEMP%\%sBatchfile%" oStream.WriteLine oStream.WriteLine "ECHO.^> %BatchFileFull%" oStream.WriteLine "ECHO.^<^^!DOCTYPE root SYSTEM " & """" & "Parameters.dtd" & """" & "^>>> %BatchFileFull%" oStream.WriteLine "ECHO.^>> %BatchFileFull%" oStream.WriteLine "ECHO.^>> %BatchFileFull%" oStream.WriteLine oStream.WriteLine "FOR %%A IN (%*) DO (" oStream.WriteLine " SET sFilePath=%%~A" oStream.WriteLine oStream.WriteLine " ECHO.^>> !BatchFileFull!" oStream.WriteLine ")" oStream.WriteLine "ECHO.^>> %BatchFileFull%" oStream.WriteLine "ECHO.^>> %BatchFileFull%" oStream.WriteLine oStream.WriteLine "FOR %%A IN (%*) DO (" oStream.WriteLine " SET sInputFiletype=%%~xA" oStream.WriteLine " SET sfolderPath=%%~dpA" oStream.WriteLine " SET sfolderPath=!sfolderPath:~0,-1!" oStream.WriteLine " ECHO %%A" oStream.WriteLine " ECHO %%~xA" oStream.WriteLine " REM ECHO sInputFiletype !sInputFiletype!" oStream.WriteLine oStream.WriteLine " IF " & """" & "!sInputFiletype!" & """" & " == " & """" & ".stp" & """" & " (" oStream.WriteLine " SET sOutputFiletype=CATPart/CATProduct" oStream.WriteLine " ) ELSE (" oStream.WriteLine " IF " & """" & "!sInputFiletype!" & """" & " == " & """" & ".step" & """" & " (" oStream.WriteLine " SET sOutputFiletype=CATPart/CATProduct" oStream.WriteLine " ) ELSE (" oStream.WriteLine " IF " & """" & "!sInputFiletype!" & """" & " == " & """" & ".STP" & """" & " (" oStream.WriteLine " SET sOutputFiletype=CATPart/CATProduct" oStream.WriteLine " ) ELSE (" oStream.WriteLine " IF " & """" & "!sInputFiletype!" & """" & " == " & """" & ".STEP" & """" & " (" oStream.WriteLine " SET sOutputFiletype=CATPart/CATProduct" oStream.WriteLine " ) ELSE (" oStream.WriteLine " IF " & """" & "!sInputFiletype!" & """" & " == " & """" & ".CATProduct" & """" & " (" oStream.WriteLine " SET sOutputFiletype=stp" oStream.WriteLine " ) ELSE (" oStream.WriteLine " IF " & """" & "!sInputFiletype!" & """" & " == " & """" & ".CATPart" & """" & " (" oStream.WriteLine " SET sOutputFiletype=stp" oStream.WriteLine " ) ELSE (" oStream.WriteLine " SET sOutputFiletype=unsupported" oStream.WriteLine " ))))))" oStream.WriteLine " ECHO OutputFiletype !sOutputFiletype!" oStream.WriteLine "REM IF !sOutputFiletype! NEQ unsupported (" oStream.WriteLine " SET /A count += 1" oStream.WriteLine " ECHO.^>> !BatchFileFull!" oStream.WriteLine " ECHO.^>> !BatchFileFull!" oStream.WriteLine "REM )" oStream.WriteLine ")" oStream.WriteLine "ECHO.^>> %BatchFileFull%" oStream.WriteLine "ECHO.^>> %BatchFileFull%" oStream.WriteLine "ECHO.^>> %BatchFileFull%" oStream.WriteLine "ECHO.^>> %BatchFileFull%" oStream.WriteLine "ECHO.^>> %BatchFileFull%" oStream.WriteLine "ECHO ^>> %BatchFileFull%" oStream.WriteLine oStream.WriteLine "ECHO xml %BatchFileFull% erstellt." oStream.WriteLine oStream.WriteLine "REM ----------Execute Catia batch-------------" oStream.WriteLine "SET CounterAttempts=3" oStream.WriteLine "SET ERRORLEVEL = 0" oStream.WriteLine "REM ECHO ERRORLEVEL=%ERRORLEVEL%" oStream.WriteLine "ECHO Conversion will be started." oStream.WriteLine ":loop" oStream.WriteLine "%install_path%\code\bin\CATSTART.exe -run " & """" & "CATBatchStarter -input %BatchFileFull%" & """" & " -env %env_file% -direnv %env_dir%" oStream.WriteLine oStream.WriteLine oStream.WriteLine "IF %ERRORLEVEL% NEQ 0 (" oStream.WriteLine " SET /a CounterAttempts=%CounterAttempts%-1" oStream.WriteLine " IF %CounterAttempts% GTR 0 (" oStream.WriteLine " ECHO No Step License available at this moment. " oStream.WriteLine " timeout /T 30" oStream.WriteLine " goto loop" oStream.WriteLine " ) ELSE (" oStream.WriteLine " ECHO." oStream.WriteLine " ECHO ------No Step License available at this moment. Please try again later.-----" oStream.WriteLine " ECHO." oStream.WriteLine " goto exitloop" oStream.WriteLine " )" oStream.WriteLine ") ELSE (" oStream.WriteLine "DEL %BatchFileFull%" oStream.WriteLine " ECHO." oStream.WriteLine " ECHO ----------BATCH SUCCHESSFULL FINISHED-----------" oStream.WriteLine "REM goto exitloop" oStream.WriteLine ")" oStream.WriteLine oStream.WriteLine ":exitloop" oStream.WriteLine "endlocal " oStream.WriteLine "pause" oStream.WriteLine "goto :end" oStream.Close SService.ExecuteProcessus ("Explorer.exe /select, "&""""&sNewBatchFile&"""") End Sub Function ExtractFileName(FileLocation) Dim FileName As String FileName = mid(FileLocation, inStrRev(FileLocation, "\")+1,100) ExtractFileName = FileName End Function Function ExtractDirectory(FileLocation) Dim DirectoryName As String DirectoryName = left(FileLocation, inStrRev(FileLocation, "\")-1) ExtractDirectory = DirectoryName 'MsgBox "ExtractDirectory = " & ExtractDirectory End Function Function LicensePack Dim NameArray() Dim SystemConfiguration1 As SystemConfiguration Dim I, A As Integer Set SystemConfiguration1 = CATIA.SystemConfiguration A = SystemConfiguration1.ProductCount-1 ReDim NameArray(A) 'Create Array with the names of all Licenses possible to activate SystemConfiguration1.GetProductNames NameArray For I = 0 to A If SystemConfiguration1.IsProductAuthorized(NameArray(I)) Then If right(NameArray(I),3) = "slt" Then LicensePack = NameArray(I) Exit Function End If End If Next End Function