The EPLAN API allows accessing object properties, i.e. characteristics that are visible in GUI in the Properties dialog.
This is possible through the Properties property which is defined for almost all data model objects.
The list of all available properties for a particular object can be found in the properties of the Properties class (for example Properties::AllMDSymbolLibraryPropIDs).
EPLAN properties are typed. The property values can have one of the following types:
With help of the PropertyDefinition.PropertyType, you can determine the type of a property:
PropertyDefinition.PropertyType | Corresponding .NET Framework type |
---|---|
Point | |
MultilangString | |
Variable | System.String |
String | System.String |
Time | System.DateTime |
Bool | System.Boolean |
Double | System.Double |
Coord | System.Double |
Long | System.Int64 |
The following example gets the type of a page property:
The following example shows how to set a bool property:
The following example shows how to get a MultiLangString property (project description):
As an alternative syntax, you can also write:
Finally an example that loops over all string properties of a project:
It is possible to get a property as a value of the .NET Framework type or EPLAN API type (for example Eplan.EplApi.Base.MultiLangString). It can be done explicitly by the PropertyValue.To<type>(), for example:
C# |
Copy Code
|
---|---|
string strStringValue = oFunction.Properties.FUNC_CODE.ToString();
|
or implicitly:
C# |
Copy Code
|
---|---|
int nValue = oFunction.Properties.FUNC_CRAFT;
|
It is not allowed to convert the property value to a non-matching type, for example MultiLangString to int. In such cases, a runtime warning is generated (as an EPLAN system message) or an exception is thrown:
C# |
Copy Code
|
---|---|
string strValue = oArticle.Properties.ARTICLE_DEPTH.ToString(); // Will generate a system warning double dValue = oArticle.Properties.ARTICLE_DEPTH.ToDouble(); // OK string strValue2 = oArticle.Properties.ARTICLE_DEPTH.ToDouble().ToString("0.00", CultureInfo.InvariantCulture); // Also OK |
Here is a table that shows which conversions are allowed:
|
Eplan.EplApi.Base.Point PropertyValue.ToPointD() |
Eplan.EplApi.Base.MultiLangString PropertyValue.ToMultiLangString() |
System.String PropertyValue.ToString() |
System.DateTime PropertyValue.ToTime() |
bool PropertyValue.ToBool() |
double PropertyValue.ToDouble() |
long PropertyValue.ToInt() |
---|---|---|---|---|---|---|---|
PropertyType.Point | ✓ | ||||||
PropertyType.MultilangString | ✓ | ||||||
PropertyType.Variable | ✓ | ||||||
PropertyType.String | ✓ | ||||||
PropertyType.Time | ✓ | ||||||
PropertyType.Bool | ✓ | ||||||
PropertyType.Double | ✓ | ||||||
PropertyType.Coord | ✓ | ||||||
PropertyType.Long |
✓ | ✓ |
Properties can have more than one value. In this case, we call it an "indexed property". The index is passed after the property designation. The example gets the index 1 of the function property FUNC_CONNECTIONDESIGNATION:
Alternatively:
EPLAN API supports also user-defined properties that were introduced in EPLAN 2.4.
The following enhancements were added due to it:
C# |
Copy Code
|
---|---|
// Setting user-defined property oProject.Properties["EPLAN.Project.UserSupplementaryField1"] = "test1"; // Getting user-defined property string strValue = oProject.Properties["EPLAN.Project.UserSupplementaryField1"]; |
C# |
Copy Code
|
---|---|
// Create a new property definition: UserDefinedPropertyDefinition oUDPDProject = UserDefinedPropertyDefinition.Create(oCurrentProject, "API.Property.Project", UserDefinedPropertyDefinition.Enums.ClientType.Project); oCurrentProject.Properties["API.Property.Project"] = "something"; var oCategory = oProject.Properties["EPLAN.Project.UserSupplementaryField1"].Category; // Gets the category information MultiLangString strDisplayedName = oProject.Properties["EPLAN.Project.UserSupplementaryField1"].DisplayedName; // Gets the name that is displayed in the GUI properties window |
C# |
Copy Code
|
---|---|
public AnyPropertyId( ref Eplan::EplApi::DataModel::Project pProject, ref System::String strUserDefiniedPropertyIdentName ); |
Some user-defined properties are created by default, for example "EPLAN.Project.UserSupplementaryField1".
They have the same internal IDs as the old *_CUSTOM_SUPPLEMENTARYFIELD* properties (like "PROJ_CUSTOM_SUPPLEMENTARYFIELD01", etc).
The use of old identifiers is still possible for compatibility reasons, but they generate warnings and will be removed in the future.
Therefore, please replace them with the new IDs to avoid problems in forthcoming EPLAN versions:
C# |
Copy Code
|
---|---|
MultiLangString oMLS = oProject.Properties.PROJ_CUSTOM_SUPPLEMENTARYFIELD01; // Old code, generates warning MultiLangString oMLS = oProject.Properties["EPLAN.Project.UserSupplementaryField1"]; // New code m_oTestProject.Properties.FUNC_ARTICLE_CUSTOM_SUPPLEMENTARYFIELD01[1] = strTestValue; // Old code, generates warning: ArticleReference oArticleReference = oProject.ArticleReferences[0]; // New code oArticleReference.Properties["EPLAN.PartRef.UserSupplementaryField1"] = strTestValue; oArticleReference.StoreToObject(); |
In the case of an ArticleReference object, when accessing a user-defined property through a parent ArticleReference, it is necessary to add the EPLAN.ArticleRef. prefix to its identifying name. In addition, an index must be provided to indicate the position of the ArticleReference in the parent object.
C# |
Copy Code
|
---|---|
var propertyValue1 = oArticleReference.Properties["UserProperty.1"].ToString(); // Accessing user-defined property from ArticleReference var propertyValue2 = oArticleReference.Parent.Properties["EPLAN.ArticleRef.UserProperty.1"][1].ToString(); // Accessing user-defined property from a parent of the ArticleReference |