Last active
March 2, 2021 15:47
-
-
Save ThoughtProcess/6223426 to your computer and use it in GitHub Desktop.
Here are extension methods for the ETAS INCA .NET API that provide a GetItemInFolder() method for the Asap2Project and Asap2ProjectFolder classes. It behaves the same way as DataBase.GetItemInFolder().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using de.etas.cebra.toolAPI.Common; | |
using de.etas.cebra.toolAPI.Inca; | |
namespace IncaExtensions | |
{ | |
public static class GetItemInFolderExtensions | |
{ | |
/// <summary> | |
/// Gets a DataBaseItem from an Asap2Project in an arbitrary subfolder. | |
/// </summary> | |
/// <param name="project">The current Asap2Project</param> | |
/// <param name="itemName">The name of the item that we want to retrieve</param> | |
/// <param name="folderName">The path, delimited by backslashes ('\\')</param> | |
/// <returns>A DataBaseItem matching the request. | |
/// If no matching item is found, or if the path is invalid, return null. | |
/// </returns> | |
public static DataBaseItem GetItemInFolder(this Asap2Project project, | |
string itemName, | |
string folderName) | |
{ | |
DataBaseItem returnItem = null; | |
if ((folderName != null) && | |
(itemName != null)) | |
{ | |
string folderToken = PluckPathToken(ref folderName); | |
Asap2ProjectFolder subFolder = | |
project.GetTopFolderNamed(folderToken); | |
if (subFolder != null) | |
{ | |
returnItem = subFolder.GetItemInFolder(itemName, folderName); | |
} | |
} | |
return returnItem; | |
} | |
/// <summary> | |
/// Recursive call that returns a DataBaseItem in the target path. | |
/// </summary> | |
/// <param name="folder">The Asap2ProjectFolder to drill down</param> | |
/// <param name="itemName">The name of the item that we want to retrieve</param> | |
/// <param name="folderName">The path, delimited by backslashes ('\\')</param> | |
/// <returns>A DataBaseItem matching the request. | |
/// If no matching item is found, or if the path is invalid, return null. | |
/// </returns> | |
public static DataBaseItem GetItemInFolder(this Asap2ProjectFolder folder, | |
string itemName, | |
string folderName) | |
{ | |
DataBaseItem returnItem = null; | |
if ((folderName != null) && | |
(itemName != null)) | |
{ | |
string folderToken = PluckPathToken(ref folderName); | |
Asap2ProjectFolder subFolder = | |
(Asap2ProjectFolder)folder.GetSubFolder(folderToken); | |
if (subFolder != null) | |
{ | |
returnItem = subFolder.GetItemInFolder(itemName, folderName); | |
} | |
} | |
else | |
{ | |
returnItem = folder.GetDataBaseItem(itemName); | |
} | |
return returnItem; | |
} | |
/// <summary> | |
/// Removes a backslash-delimited token from a string and shortens the | |
/// input string. | |
/// </summary> | |
/// <param name="folderName">Backslash-delimited path. This will be | |
/// shortened each time a token is removed.</param> | |
/// <returns>The latest path token</returns> | |
static string PluckPathToken(ref string folderName) | |
{ | |
int slashIdx = folderName.IndexOf('\\'); | |
// If folderName has path tokens, extract the first token and | |
// shorten folderName accordingly. | |
string folderToken = (slashIdx > -1) ? | |
folderName.Substring(0, slashIdx) : folderName; | |
folderName = (slashIdx > -1) ? | |
folderName.Substring(slashIdx + 1) : null; | |
return folderToken; | |
} | |
} | |
} |
Hello, how to get the namespace de.etas.cebra.toolAPI.Common?
Is there any reference code to automate INCA using python..
I've received a few e-mails and comments on this gist over the past few years. Since ETAS continually updates their documentation and API, I would recommend reaching out to your local regional office to get a copy of the latest API documentation. (This documentation is available free of charge to all licensed INCA users). At the time of this writing, you can find that contact info here: https://www.etas.com/en/contact.php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello, Do you have the Tool API document about ETAS INCA? and if I want to Python to develop the script to control Inca, can you give me some advice?