Autor
|
Thema: CATIA V5 über VBExpress starten (3768 mal gelesen)
|
Mjk Mitglied
Beiträge: 14 Registriert: 17.06.2013 CATIA V5-6 R24 WINDOWS 7
|
erstellt am: 19. Jul. 2013 15:47 <-- editieren / zitieren --> Unities abgeben:
Hallo, ich möchte gern CATIA aus einem VBExpress Programm starten, dann einige Operationen durchführen lassen und es dann wieder schließen. Schon am ersten Punkt scheitere ich: Hier ist der aktuelle Code: Imports INFITF Imports PARTITF Module Module1
Sub Main() Dim CatiaType As System.Type = System.Type.GetTypeFromProgID("Catia.Application") Dim oCATIA As Object = System.Activator.CreateInstance(CatiaType) Dim CATIA As INFITF.Application = CType(oCATIA, INFITF.Application) Dim MyFile As String MyFile = CATIA.FileSelectionBox("Look for File", "*.CATPart", CatFileSelectionMode.CatFileSelectionModeOpen) CATIA.Documents.Open(MyFile) 'Wie bestimmt man die Version bzw. das Environment mit dem CATIA automatisch gestartet werden soll? End Sub End Module Ich wüsste gerne wie ich bei diesem automatisierten Start bestimmen kann, welche CATIA-Version geladen wird und welches Environment-File benutzt werden soll, dabei würde ich am liebsten ohne eine Kommandozeile auskommen? Vielen Dank für eure Hilfe. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
RAA Mitglied CAD/PDM-Supporter
Beiträge: 57 Registriert: 05.08.2009 HP Z420 Intel Xeon 3,6GHz 32GB Windows 7 Enterprise V5R19+R22+R24+R26 VB.net 2010
|
erstellt am: 23. Jul. 2013 13:54 <-- editieren / zitieren --> Unities abgeben: Nur für Mjk
Hallo, vielleicht bringt Dich dieser Hinweis etwas weiter. Ich habe einmal einen Batch geschrieben, der aus einer Menge CATDrawings pdf-Dateien erzeugt. Warscheinlich kann man die Batchdatei durch ein shellexecute in VB ersetzen. Die Batchdatei sah im wesentlichen so aus: ' setzen der Umgebungsvariablen ' die sind natürlich Installationsspezifisch SET CATIAPATH="C:\Program Files\Dassault Systemes\B19_64\win_b64\code\bin SET CATENV="CATIA.V5R19.B19.kostal.win" SET CATDIRENV="C:\catiav5\catenv\admv5\r19\config" ' Aufruf von CATIA im Batchprozess %CATIAPATH%\CNEXT.exe" -batch -env %CATENV% -direnv %CATDIRENV% -macro "CATCDB2PDF.CATScript" -object %MDLNAME% über die Variable %MDLNAME% bekommt CATIA mit welches Modell zu bearbeiten ist und in CATCDB2PDF.CATScript steht was CATIA machen soll. Das ist im Prinzip alles mfg Rainer
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Mjk Mitglied
Beiträge: 14 Registriert: 17.06.2013 CATIA V5-6 R24 WINDOWS 7
|
erstellt am: 24. Jul. 2013 23:33 <-- editieren / zitieren --> Unities abgeben:
Vielen Dank für deine Antwort. Ich denke, dass es dann im weitern Verlauf ein Problem geben wird, wenn ich CATIA direkt automatisieren möchte. Ich würde also gerne ohne interne Macros auskommen und den kompletten Programmcode extern halten. Ich muss also die CATIA Befehle mit dem CATIA-Prozess verbinden können bzw. verbunden halten. Wenn ich mit meinem Code starte kann ich den Prozess vollständig kontrollieren bei deiner Version würde müsste nachträglich den Prozess mit dem CATIA-Objekt verbinden. Wie würde ich eine solche Verbindung herstellen können? Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
RAA Mitglied CAD/PDM-Supporter
Beiträge: 57 Registriert: 05.08.2009 HP Z420 Intel Xeon 3,6GHz 32GB Windows 7 Enterprise V5R19+R22+R24+R26 VB.net 2010
|
erstellt am: 25. Jul. 2013 11:38 <-- editieren / zitieren --> Unities abgeben: Nur für Mjk
Hallo Mjk, wenn wir interaktive Programme in VB6 schreiben, so verbinden wir das Programm mit einer laufenden CATIA Session mit: Dim CATIA As Object Set CATIA = GetObject(, "CATIA.Application") das ist aber nur dann problemlos, wenn man davon ausgehen kann, dass auf dem Rechner nur eine CNEXT Instanz läuft. Der Vorteil der anfangs beschriebenen Methode sehe ich darin, dass in der CNEXT Instanz, die ich starte auch der Programmcode aus der CATScript Datei läuft. So vermeide ich Zuordnungsprobleme. mfg Rainer Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
GEL63 Mitglied Mechanical Engineer / Programmer
Beiträge: 3 Registriert: 06.03.2013 Imposible is nothing -GEL
|
erstellt am: 26. Jul. 2013 18:22 <-- editieren / zitieren --> Unities abgeben: Nur für Mjk
Hello Mjk To start a CATIA Session (Instance) of specific version and environment we have three ways to go. One, start a new process(with the aid of Process.Start(Filename As String, Arguments As String)) of the CNEXT assembly and arguments of it. Two, start a new thread of the executable CNEXT.exe and arguments of it. Three, create a new instance of CATIA.Application type with CreateInstance(System.Type.GetTypeByProgID(“CATIA.Application”)) which returns also the CATIA object. In the first case, we can start a CATIA Session (Instance) of specific version and environment in VB.NET as follows
Code: Public Function StartCATIAProcess(ByVal CNEXTFileName As String, _ ByVal AdministrationMode As Boolean, _ ByVal BatchMode As Boolean, _ ByVal StartCommand As String, _ ByVal EnvironmentName As String, _ ByVal EnvironmentDirectory As String, _ ByVal LoadObject As String, _ ByVal StartWorkbenchName As String, _ ByVal RunMacroInBatchMode As Boolean, _ ByVal StartMacro As String, _ ByVal NoWindow As String) As Process ' Handle White Spaces StartCommand = HandleWhiteSpaces(StartCommand) EnvironmentName = HandleWhiteSpaces(EnvironmentName) EnvironmentDirectory = HandleWhiteSpaces(EnvironmentDirectory) LoadObject = HandleWhiteSpaces(LoadObject) StartWorkbenchName = HandleWhiteSpaces(StartWorkbenchName) StartMacro = HandleWhiteSpaces(StartMacro) NoWindow = HandleWhiteSpaces(NoWindow) 'Build Arguments String Dim Arguments As String = "" If AdministrationMode Then Arguments = "-admin " If BatchMode Then Arguments &= "-batch " If Not StartCommand Is Nothing Then Arguments &= StartCommand End If End If If (Not (EnvironmentName Is Nothing)) AndAlso _ (Not (EnvironmentDirectory Is Nothing)) Then Arguments &= "-env " & EnvironmentName & " -direnv " & EnvironmentDirectory End If If Not (LoadObject Is Nothing) Then Arguments &= " -object " & LoadObject If Not (StartWorkbenchName Is Nothing) Then Arguments &= " -workbench " & StartWorkbenchName If Not (StartMacro Is Nothing) Then If RunMacroInBatchMode Then Arguments &= " -macro -batch " & StartMacro Else Arguments &= " -macro " & StartMacro End If End If If Not (NoWindow Is Nothing) Then Arguments &= " -nowindow " & NoWindow End If ' Start CNEXT Process Return Process.Start(CNEXTFileName, Arguments) End Function Public Function HandleWhiteSpaces(ByVal aString As String) As String If (Not String.IsNullOrEmpty(aString)) AndAlso _ aString.First() <> """" AndAlso _ aString.Contains(" ") Then aString = """" & aString & """" End If Return aString End Function
Of course, this method is not returning the CATIA object and so if we need to get it we shall code as follows:
Code: Private Sub btnCreateCATIAProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles btnCreateCATIAProcess.Click Dim CNextFileName As String Dim CATIAProcess As Process Dim oCATIA As INFITF.Application = Nothing CNextFileName = "C:\Program Files\Dassault Systemes\B20\intel_a\code\bin\CNEXT.exe" 'Create CATIA Process CATIAProcess = StartCATIAProcess( _ CNextFileName, _ False, _ False, _ Nothing, _ "AdminCATIA.V5R20.B20", _ "C:\Documents and Settings\All Users\Application Data\DassaultSystemes\CATEnv", _ "none", _ Nothing, _ False, _ "C:\CATIAMacrosManager\Macros\CATScript\MyCATScript2.CATScript", _ Nothing) CATIAProcess.WaitForInputIdle() 'Get CATIA Object Do Until Not oCATIA Is Nothing oCATIA = GetObject(, "CATIA.Application") Loop End Sub
The problem with GetObject function is that it always returns the first instance of CATIA. If we need to have more than one running sessions of CATIA we cannot get access to the second, third,… instance with this function. In this case, we need to use the CSessionServer COM component which will provide us access to all running CATIA Sessions. With the aid of CSessionServer we can create new sessions of specific CATIA version and enviroment file and get access to all, at the time, running CATIA Sessions. Watch this video CATIA Sessions Manager (powered by CSessionsServer)------------------ -GEL Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
sina123 Mitglied
Beiträge: 47 Registriert: 26.11.2018
|
erstellt am: 06. Dez. 2018 13:29 <-- editieren / zitieren --> Unities abgeben: Nur für Mjk
Hello i am doing something like this in C# but i would like to get a help since i will be having env and direnv values in an xml file as: D:\..\CNEXT.exe -env CATIA_P1.V5-6R2016.B26 -direnv "D:\opt\catia\CATEnv" How can i extract these and launch Catia Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 06. Dez. 2018 14:35 <-- editieren / zitieren --> Unities abgeben: Nur für Mjk
Hi Is this a Catia related question? For general reading a xml-file in c# you should find enough manuals, tutorials, answers on the net. Regards, Bernd
------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
sina123 Mitglied
Beiträge: 47 Registriert: 26.11.2018
|
erstellt am: 06. Dez. 2018 14:45 <-- editieren / zitieren --> Unities abgeben: Nur für Mjk
|
| Anzeige.:
Anzeige: (Infos zum Werbeplatz >>)
|