mschaedler1982
Goto Top

CATIA Dateikonvertierung in STP

Hallo zusammen,

Ich möchte über eine Batch einen Konvertierungsprozess anstoßen.

Die Lösung momentan schaut so aus.

"C.\Program Files\Dassault Systemes\B24_BMW\win_b64\code\bin\CATBatchStarter.exe" -input C:\Temp\Test.xml

Das xml File wird von mal zu mal händisch angepasst.

Inhalt der Test.xml

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE root SYSTEM "Parameters.dtd">  
<root batch_name="BatchDataExchange" user="" password="" env="" version="5 24 1 29 10-08-2014.12.15" licfile="" >  
<inputParameters>
<file id="FileToProcess" destination="" filePath="C:\Projekt\513270\Product1_00513260.CATProduct" type="bin" upLoadable="RightNow" automatic="1"/>  
</inputParameters>
<outputParameters>
<folder id="OutputFolder" destination="C:\Projekt\513270\Output" folderPath="C:\Projekt\513270\Output" type="bin" upLoadable="RightNow" extension="*" automatic="1"/>  
<simple_arg id="OutputExtension1" value="stp"/>  
</outputParameters>
<PCList>
<PC name="HD2.slt" />  
<PC name="ST1.prd" />  
</PCList>
</root>

Optionen der CATBatchStarter.exe

arguments :
-u / -h / -? : arguments help
-input parametersfile : fullpath of the batch xml parameter file.
-host <hostname> : where hostname is the name of the remote machine,
resquest a remote execution
-allow_visu : to allow the batch to access the graphical adapter (if any),
otherwise batch which need one will exit with RC = 7
-output <path> : where path is the fullpath of a file or a directory
where to put the execution log of the batch
-verbose : activates the execution traces

FilePath und folderpath variiert, zudem ändert sich auch immer der Dateiname. Muss hier über ein vbs Skript eine xml Datei erzeugt werden?

Kann mir hierzu jemand weiterhelfen?

Danke!

Content-Key: 266457

Url: https://administrator.de/contentid/266457

Printed on: April 18, 2024 at 18:04 o'clock

Mitglied: 114757
114757 Mar 16, 2015, updated at Mar 18, 2015 at 19:39:21 (UTC)
Goto Top
Moin,
ich würde das mit Powershell machen:
Das lässt sich dann direkt auf eine ganze Ordnerstruktur anwenden die es automatisch auf bestimmte Files durchläuft
Das sieht dann in etwa so aus ...
# XML Vorlage
$xmlIN = "C:\vorlage.xml"  
# temporäre Ausgabe
$xmlOUT= "C:\temp.xml"  
$xml = new-object xml
$xml.Load($xmlIN)
# Lade alle Files mit *.CATProduct aus allen Projektordnern
$files = gci 'c:\Projekt\*\*.CATProduct'  

# erstelle für jede dieser Dateien ein XML File und starte die Konvertierung
$files | %{
	$xml.root.inputParameters.file.filePath = $_.Fullname
	$xml.root.outputParameters.destination = $_.Directory.Fullname + '\Output'  
	$xml.root.outputParameters.folderPath = $_.Directory.Fullname + '\Output'  
	$xml.Save($xmlOut)
	start-process "C:\Program Files\Dassault Systemes\B24_BMW\win_b64\code\bin\CATBatchStarter.exe" -Argumentlist "-input $xmlOUT" -wait  
}
Gruß jodel
Member: mschaedler1982
mschaedler1982 Mar 18, 2015 updated at 13:49:52 (UTC)
Goto Top
Hallo Jodel.

Ich erhalte diese Fehlermeldung. Ist evtl nur ein Tippfehler. Schaust es dir bitte nochmal an?

C:\Projekt>powershell C:\Projekt\workaround_catpart.ps1   .CATpart
In C:\Projekt\workaround_catpart.ps1:14 Zeichen:73
+ $xml.root.outputParameters.folderPath = $_.Directory.Fullname + '\Output'  
+                                                                         ~
Die Zeichenfolge hat kein Abschlusszeichen: '.  
    + CategoryInfo          : ParserError: (:) , ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString


C:\Projekt>pause
Drücken Sie eine beliebige Taste . . .


Ich habe CatProduct durch CATPart ersetzt.

Danke!
Mitglied: 114757
114757 Mar 18, 2015 updated at 14:35:26 (UTC)
Goto Top
Sorry Zeile 8 korrigiert
Member: mschaedler1982
mschaedler1982 Mar 18, 2015 at 19:33:01 (UTC)
Goto Top
Hallo Jodel.

Daran hat es nicht gelegen. Ich erhalte nun diese Meldung.

PS C:\Projekt> C:\Projekt\workaround_catpart.ps1
In C:\Projekt\workaround_catpart.ps1:16 Zeichen:87
+ ... chStarter.exe" -input $xmlOUT  
+                    ~~~~~~
Unerwartetes Token "-input" in Ausdruck oder Anweisung.  
In C:\Projekt\workaround_catpart.ps1:16 Zeichen:94
+ ... er.exe" -input $xmlOUT  
+                    ~~~~~~~
Unerwartetes Token "$xmlOUT" in Ausdruck oder Anweisung.  
    + CategoryInfo          : ParserError: (:) , ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

Grüße
Mitglied: 114757
114757 Mar 18, 2015 updated at 19:46:06 (UTC)
Goto Top
Daran hat es nicht gelegen
Doch schon ....Na ja, ein bisschen Eigeninitiative hatte ich eigentlich schon erwartet ...Das ist hier ja kein Automat dem man Fragen stellt und der einem dann fertige Lösungen ausspuckt.

Da ich die ausführbare exe hier nicht testen kann, habe ich die Ausführung des Prozesses oben noch mal abgeändert.
s.o.

Viel Erfolg dann noch

Gruß jodel
Member: mschaedler1982
mschaedler1982 Mar 19, 2015 at 10:53:48 (UTC)
Goto Top
Hallo Jodel.

Von Powershell hab ich keine Ahnung! Deswegen ja auch meine Frage. Ich bin mal vor 2-3 Jahren über eine Installationsthema gestoßen wo über ein vbs eine Antwort Datei erzeugt worden ist (Windows XP Installation) Daher auch meine Frage ob das über ein vbs realisiert werden muss...

Aber im Grunde genommen ist mir das egal ob das über Batch, VBS oder Powershell realisiert werden kann.

Diese CATBATCHStarter.exe verlangt eben diese -input Parameter + *.xml File

Im unten aufgeführte Beispiel sieht man wie es sein muss.

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE root SYSTEM "Parameters.dtd">  
<root batch_name="BatchDataExchange" user="" password="" env="" version="5 24 1 29 10-08-2014.12.15" licfile="" >  
<inputParameters>
<file id="FileToProcess" destination="" filePath="C:\Projekt\541515\sp_cylinder-head-gasket_8656976_AllCATPart_00536076.CATPart" type="bin" upLoadable="RightNow" automatic="1"/>  
<file id="FileToProcess" destination="" filePath="C:\Projekt\541515\sp_cylinder-head-gasket__8648209_AllCATPartCATPart_00536075.CATPart" type="bin" upLoadable="RightNow" automatic="1"/>  
</inputParameters>
<outputParameters>
<folder id="OutputFolder" destination="C:\Projekt\Output" folderPath="C:\Projekt\Output" type="bin" upLoadable="RightNow" extension="*" automatic="1"/>  
<simple_arg id="OutputExtension1" value="stp"/>  
<folder id="OutputFolder" destination="C:\Projekt\Output" folderPath="C:\Projekt\Output" type="bin" upLoadable="RightNow" extension="*" automatic="1"/>  
<simple_arg id="OutputExtension2" value="stp"/>  
</outputParameters>
<PCList>
<PC name="HD2.slt" />  
<PC name="ST1.prd" />  
</PCList>
</root>

Mein Lösungsansatz geht eher in die Richtung Batch...

1. Verzeichnis auslesen
2. Ausgabe als Variable definieren
3. Dateiname.Catpart oder Dateiname.CatProduct auslesen
4. Ausgabe als 2.Variable definieren

Meine xml Datei aus den 2 Variablen zusammenbauen und im Anschluß die Konvertierung mit diesem Befehl anstoßen.

C.\Program Files\Dassault Systemes\B24_BMW\win_b64\code\bin\CATBatchStarter.exe" -input C:\Temp\Test.xml

Dadurch das du Powershell vorgeschlagen hast, was mir ehrlich gesagt auch recht ist, denn unsere alte Lösung basierte bereits auf Powershell. Anbei die Skripte

1. Skript

powershell C:\ProgramData\procad\NDF_Batch\createSTP.ps1 %1 %2 .CATpart

2. Skript
param( 
[string]$Sourcefile, # Quelldatei mit Pfad und falscher Extension!!! 
[string]$Targetfile, # Zieldatei mit Pfad 
[string]$Type # .CATpart, .CATproduct 
) 
 
[System.IO.FileInfo]$fi = New-Object System.IO.FileInfo($Sourcefile) 
$newfilename = $fi.BaseName + $Type 
$newFileFullname = Join-Path $fi.DirectoryName $newfilename 
# Prozess der Konvertierung starten 
$proc = start-process "C:\coretechnologie2014\evolution64\evolution.exe" -ArgumentList "-batch C:\coretechnologie2014\evolution64\scripts\convert.scp $newFileFullname ProEngineer Step $Targetfile C:\catiawork\3D_Evolution\test1.log" -passthru   
 
# Maximale Wartezeit fuer eine Konvertierung solange der Prozess laeuft 
[int]$maxwaittime = 600 
[int]$cTime = $maxwaittime 
# Solange der Konvertierungsprozess noch laeuft zeige eine Vortschrittsanzeige 
while(!$proc.HasExited){ 
if($cTime -gt 0){ 
Write-Progress -Activity "Konvertierung laeuft..." -Status "Bitte warten." -CurrentOperation "(Nach einer maximalen Wartezeit von 5 Minuten wird der Vorgang automatisch abgebrochen)" -SecondsRemaining $cTime -PercentComplete ([Math]::Round((($maxwaittime-$cTime)/$maxwaittime)*100))   
# warte eine Sekunde bis zur naechsten Pruefung 
sleep(1) 
$cTime-- 
}else{ 
# sollte die maximale Wartezeit erreicht sein und der Prozess noch laufen, beende den Konvertierungsprozess 
$proc.Kill() 
write-host "Die maximale Wartezeit von $maxwaittime Sekunden wurde erreicht und die Konvertierung abgebrochen." -ForegroundColor Red   
# verlasse die Schleife sofort 
break 
} 
} 
 
if ((dir "C:\catiawork\NdfWork\*_NdfWork\*.stp")){   
write-host "Konvertierung wurde erfolgreich abgeschlossen." -ForegroundColor Green   
}else{ 
write-host "STP File wurde nicht erzeugt!." -ForegroundColor Red   

Ich muss meiner Batch nur noch beibringen dass Sie die Parameter % % übergibt, was mit Skript 1 erledigt wird.


Dann mal rechtherzlichen Dank Jodel, vielleicht haben ja noch andere die hier im Forum aktiv sind andere Lösungsansätze.
Member: mschaedler1982
mschaedler1982 Mar 20, 2015 at 15:28:59 (UTC)
Goto Top
Lösung!

Skript 1:

start /wait C:\ProgramData\procad\NDF_Batch\CATProduct.bat %1 %2 .CATproduct

Skript 2:

rem Wechsel in das Verzeichnis
pushd C:\catiawork\NdfWork || exit /b 1
rem Ausgabe in dir.log ausgeben
dir /AD /B > C:\catiawork\NdfWork\dir.log
for /f %%f IN (C:\catiawork\NdfWork\dir.log) DO set Ordner=%%f
set name=%1
rem Nur der Dateiname (ohne .ext) - die Option "~n" (Name der Datei oder des Ordners)   
rem wird angesprochen, %% weil Ausfuehrung aus einem Script heraus, am Ende ist das 
rem Element der for Schleife

for %%a in (%name%) do set data=%%~na

set typ=CATProduct

dir /B /S C:\catiawork\NdfWork\%Ordner%\%data%.%typ% > C:\catiawork\NdfWork\dir2.log
echo ^<?xml version="1.0" encoding="UTF-8"?^> >> C:\catiawork\NdfWork\vorlage2.xml  
echo ^<!DOCTYPE root SYSTEM "Parameters.dtd"^> >> C:\catiawork\NdfWork\vorlage2.xml  
echo ^<root batch_name="BatchDataExchange" user="" password="" env="" version="5 24 1 29 10-08-2014.12.15" licfile=""^> >> C:\catiawork\NdfWork\vorlage2.xml  
echo ^<inputParameters^> >> C:\catiawork\NdfWork\vorlage2.xml
echo ^<file id="FileToProcess" destination="" filePath="C:\catiawork\NdfWork\%Ordner%\%data%.%typ%" type="bin" upLoadable="RightNow" automatic="1"/^> >> C:\catiawork\NdfWork\vorlage2.xml  
echo ^</inputParameters^> >> C:\catiawork\NdfWork\vorlage2.xml
echo ^<outputParameters^> >> C:\catiawork\NdfWork\vorlage2.xml
echo ^<folder id="OutputFolder" destination="C:\catiawork\NdfWork\%Ordner%" folderPath="C:\catiawork\NdfWork\%Ordner%" type="bin" upLoadable="RightNow" extension="*" automatic="1"/^> >> C:\catiawork\NdfWork\vorlage2.xml  
echo ^<simple_arg id="OutputExtension1" value="stp"/^> >> C:\catiawork\NdfWork\vorlage2.xml  
echo ^</outputParameters^> >> C:\catiawork\NdfWork\vorlage2.xml
echo ^<PCList^> >> C:\catiawork\NdfWork\vorlage2.xml
echo ^<PC name="HD2.slt"/^> >> C:\catiawork\NdfWork\vorlage2.xml  
echo ^<PC name="ST1.prd"/^> >> C:\catiawork\NdfWork\vorlage2.xml  
echo ^</PCList^> >> C:\catiawork\NdfWork\vorlage2.xml
echo ^</root^> >> C:\catiawork\NdfWork\vorlage2.xml

pushd "C:\Program Files\Dassault Systemes\B24_BMW\win_b64\code\bin"  
CATBatchStarter.exe -input C:\catiawork\NdfWork\vorlage2.xml

del C:\catiawork\NdfWork\vorlage2.xml
del C:\catiawork\NdfWork\dir.log
del C:\catiawork\NdfWork\dir2.log
del /Q C:\Temp\  
rd /S /Q C:\Temp
md C:\Temp

exit