Voraussetzung
-
TIA Portal Openness ist mit dem TIA Portal verbunden.
Siehe Verbindung zum TIA Portal aufbauen -
Ein Projekt ist geöffnet.
Siehe Öffnen eines Projekts
Einleitung
Mit TIA Portal Openness können Sie die benutzerdefinierten Attributwerte in Teamcenter Gateway abrufen und einstellen.
Parameter
Das ItemType in Teamcenter bezieht sich auf T4TiaLibrary, T4TiaProject und Subtypen im Teamcenter-Datenmodell, für die benutzerdefinierte Attribute in Teamcenter dargestellt werden.
|
Parametername |
Datentyp |
Obligatorisch |
Beschreibung |
|---|---|---|---|
|
tcGatewayConnectionInfo |
Siemens.Engineering.TeamcenterGateway.TcGatewayConnectionInfo |
Ja |
Gibt während des Verbindungsaufbaus zu Teamcenter tcGatewayConnectionInfo zurück. tcGatewayConnectionInfo wurde übergeben und muss mit der tcGatewayConnectionInfo der aktiven Verbindung übereinstimmen. |
|
itemType |
System.String |
Ja |
Gibt den Teamcenter-itemType an. |
Nach der erfolgreichen Ausführung gibt die API eine Sammlung benutzerdefinierter Attribute zurück, wenn diese in Teamcenter für den angegebenen itemtype verfügbar sind.
|
Datentyp |
Beschreibung |
|---|---|
|
IList<Siemens.Engineering.TeamcenterGateway.TeamcenterProperty> |
Gibt die Liste der benutzerdefinierten Eigenschaften in Teamcenter für das Objekt oder die Version an.
|
Die API Call SetValue setzt den Wert für benutzerdefinierte Attribute, die mit Hilfe der API GetTeamcenterCustomAttributes abgefragt werden, zusammen mit dem errorCallback-Delegate.
|
Parametername |
Datentyp |
Obligatorisch |
Beschreibung |
|---|---|---|---|
|
value |
System.String |
Ja |
Gibt den Wert für das benutzerdefinierte Attribut an. |
|
errorCallback |
Siemens.Engineering.TeamcenterGateway.ErrorCallback |
Ja |
Delegate für die Fehlerbehandlung bei Aufrufen/Aktionen der API. |
Programmcode
|
private void AccessCustomattributes(SecureString password) { // Refer the Connecting to the TIA Portal section TiaPortal tiaPortal = new TiaPortal(); var tcGatewayConnectionProvider = tiaPortal.GetService<TeamcenterConnectionProvider>(); var tcGatewayLockProvider = tiaPortal.GetService<TcGatewayLockProvider>(); try { // Define user-specific credentials information string userName = string.Empty; string userRole = "your_role"; string userGroup = "your_group"; string serverURL = "serverURL"; string teamcenterInstance = "teamcenterInstance"; // Delegate for item details ItemDetailsDelegate itemDetailsDelegate = ItemDetailsForCreation; void ItemDetailsForCreation(ItemDetails itemDetails) { itemDetails.ItemId = "..."; itemDetails.ItemName = "Project30"; itemDetails.RevisionId = "..."; itemDetails.TeamcenterItemType = "T4TiaProject"; itemDetails.Comment = "Project Comments."; } // Connect to Teamcenter using provided credentials TcGatewayConnectionInfo connectionInfo = tcGatewayConnectionProvider.Connect(userName, password, userGroup, userRole, serverURL, teamcenterInstance); // Open project or global library in TIA Portal var project = tiaPortal.Projects.Open(new FileInfo(@"~\UserData\Documents\Automation\Project30\Project30.ap18")); var tcGatewayWorkflowProviderForProject = project.GetService<TcGatewayWorkflowProvider>(); //OR var library = tiaPortal.GlobalLibraries.Open(new FileInfo(@"~\Documents\Automation\Library7\Library7.al18"), OpenMode.ReadWrite); // Get the workflow provider for the project or library var tcGatewayWorkflowProviderForLibrary = library.GetService<TcGatewayWorkflowProvider>(); // Get the custom attributes from Teamcenter Project var attributes = tcGatewayWorkflowProviderForProject. GetTeamcenterCustomAttributes(connectionInfo,"T4TiaProject"); // Error callback for property value setting ErrorCallback errorCallback = PropertyValueSettingErrorCallback; void PropertyValueSettingErrorCallback(string errorMessage) { Console.WriteLine(errorMessage); } // Loop through attributes and update values foreach (var arr in attributes) { // Display values from ListOfValueInfo if available if (arr.ListOfValueInfo != null) { foreach (var l in arr.ListOfValueInfo.Values) { Console.WriteLine(l); } } switch (arr.DataType) { case MappedCustomAttributeType.String: arr.SetValue("23232323232", errorCallback); break; case MappedCustomAttributeType.Char: arr.SetValue("d", errorCallback); break; case MappedCustomAttributeType.Integer: arr.SetValue("232", errorCallback); break; case MappedCustomAttributeType.Float: arr.SetValue(23.4f.ToString(), errorCallback); break; } } } catch (TcGatewayException ex) { // Handle exception or log error or other operations or other operations } } |