Projekt/globale Bibliothek in Teamcenter speichern - TIAPortal

TIA Portal Openness: API für die Automatisierung von Engineering-Workflows

ft:publication_title
TIA Portal Openness: API für die Automatisierung von Engineering-Workflows
Product
TIAPortal
Version
V20
Publication date
01/2025
Language
de-DE
Projekt/globale Bibliothek in Teamcenter speichern

Voraussetzung

Einleitung

Sie können mit TIA Portal Openness ein Projekt oder eine globale Bibliothek über den Dienst TcGatewayWorkflowProvider speichern. Dieser Dienst steht bei der Zusammensetzung des Projekts/der globalen Bibliothek zur Verfügung.

Parameter

Parametername

Datentyp

Obligatorisch

Beschreibung

tcGatewayConnectionInfo

TcGatewayConnectionInfo

Ja

Gibt während des Verbindungsaufbaus zu Teamcenter tcGatewayConnectionInfo zurück.

tcGatewayConnectionInfo wurde übergeben und stimmt mit der tcGatewayConnectionInfo der aktiven Verbindung überein.

localCacheOption

LocalCacheOption(Enum)

Ja

TcGateway LocalCacheOption überschreibt das TIA-Projekt/die globale Bibliothek im Teamcenter-Cache.

.

DataType

Beschreibung

Siemens.Engineering.TeamcenterGateway.ItemInfo

Wenn das Projekt / die globale Bibliothek erfolgreich in Teamcenter gespeichert ist, gibt die API das folgende Objekt ItemInfo zurück:

  • ItemId [System.String]

  • RevisionId [System.String]

  • ItemName [System.String]

  • ItemType [Siemens.Engineering.TeamcenterGateway.ItemType(Enum)]

Programmcode

Kopiert den nachfolgenden Programmcode in die Zwischenablage.

//Program code: Saving Project/gobal library in Teamcenter using Save()

private void SaveProjectInTeamCenter(SecureString password)

{

    // Refer Connecting to the TIA Portal section

    TiaPortal tiaPortal = new TiaPortal();

    TeamcenterConnectionProvider tcGatewayConnectionProvider = tiaPortal.GetService<TeamcenterConnectionProvider>();

    TcGatewayLockProvider tcGatewayLockProvider = tiaPortal.GetService<TcGatewayLockProvider>();

    try

    {

    // Define user-specific credentials and connection details.

    string userName = "name";

    string userRole = "role";

    string userGroup = "group";

    string serverURL = "teamcenter_server_url";

    string teamcenterInstance = "instance";

    // Connect to Teamcenter using the provided credentials

    TcGatewayConnectionInfo connectionInfo = tcGatewayConnectionProvider.Connect(userName, password,

    userGroup, userRole, serverURL, teamcenterInstance);

    // Checkout a specific dataset from Teamcenter for editing.

    tcGatewayLockProvider.CheckoutDataset(connectionInfo, "000495", "A", DatasetType.T4TiaProjectDataset, "Project30");

    // Access the project composition in the TiaPortal instance

    ProjectComposition projectComposition = tiaPortal.Projects;

    // Define the project path for the dataset checked out earlier

    // or download it using the TcGateway API.

    string projectPath = "project_path";

    // Open the project using the specified project path.

    Project tcgProject = projectComposition.Open(new FileInfo(projectPath));

    // Create a device group within the project.

    tcgProject.DeviceGroups.Create("Group_1");

    // Save the project locally in the TC cache (optional step).

    tcgProject.Save();

    // Access the TcGatewayWorkflowProvider from the project

    // instance using GetService()

    TcGatewayWorkflowProvider tcgWorkflowProvider = tcgProject.GetService<TcGatewayWorkflowProvider>();

    // Choose an appropriate local cache option

    // and save the changes made to the project.

    LocalCacheOption cacheOption = LocalCacheOption.Overwrite;

    // Choose the appropriate option

    ItemInfo response = tcgWorkflowProvider.Save(connectionInfo, cacheOption);

    // Check in the dataset back to Teamcenter after making changes.

    tcGatewayLockProvider.CheckinDataset(connectionInfo, "000495", "A", DatasetType.T4TiaProjectDataset, "Project30");

    }

    catch (TcGatewayException ex)

    {

     // Handle exception or log error

    }

}