String replacement in the macro. This can for instance be carried out on a local copy EPLAN.EPLAN21.MACRO.COPY. All writable properties of pages and devices can be modified by using string variables. String variables are defined by $ followed by a number. Using EPL_PARAM_MACRO_REPLACEPROPS_REPLACESTRINGS, the replacement string can be defined to be any string variable.
Should the string variables begin with another character than $, this character can be specified with the value REPLACEIDENTIFIER which can be found in the registry under the MACROS section.
If the integer values of a device are to be changed, this can only be done via the device property: "Substitution rule for numeric properties" with the number 1140. If the property has the value 5=$3;1028=$4, the properties with the number 5 are replaced by the value of the string variable $3, and the property with the number 1028 will be replaced by the value of the string variable $4.
The EPLAN.EPLAN21.MACRO.REPLACEPROPS command is called up via the API functions as specified in the EPLAN 21 API.
All parameters have the prefix "EPL_PARAM_MACRO_REPLACEPROPS_"!
ParameterID | Type | Description |
---|---|---|
MACRO | [IN] EplHandle |
Handle of the macro on which the replacement is carried out. |
REPLACESTRINGS | [IN] String |
Gives possibility to replace string. $1..n is replaced by a string. Exmp.: $1="TEST" $2="Eplan" replaces $1 with TEST and $2 with Eplan in the placed macro. |
REMOVEUNKNOWNVAR | [IN, OPTIONAL] Boolean |
Variables $1..n, which were not assigned a replacement by REPLACESTRING, can be deleted by setting this parameter to 1. 0 is default. |
The eplExecuteCommand function returns EPL_OK if the macro could be successfully inserted into the page.
If the command fails, eplExecuteCommand returns the value EPL_ERROR. In this case, the error log can contain the following errors:
ErrorID | Description |
---|---|
EPL_ERR_NO_MACROHANDLE | No macro handle. |
EPL_ERR_INVALID_MACROHANDLE | Invalid macro handle. |
EPL_ERR_NO_RIGHT | The current user group is not allowed to modify a macro. |
EPL_ERR_INVALID_ARGUMENT | The replacement string is empty or the macro handle has not been set correctly. |
EPL_ERR_FAILED | Error while replacing. |
// Modifies properties in the macro EplSession hSession; EplHandle copyMacHandle; .. // Copy a macro with EPLAN.EPLAN21.MACRO.COPY .. std::wstring replStr(L"$10=\"Hello\" $1=\"EPLAN\" $5=\"21\""); // Replaces $10 by Hello $1 by EPLAN and $5 by 21 // In front of $10 and behind 21\" there may be any characters bool removeUnknownVar = true; if ( modifyMacro( theSession, copyMacHandle, replStr, removeUnknownVar ) ) { .... } bool modifyMacro( EplSession hSession, EplHandle hMacro, const std::wstring& replaceString, bool removeUnknownVar ) { bool retVal = false; if(hMacro == EPL_ERROR) return retVal; EplHandle modifyMacroCmd = eplCreateCommand(hSession, L"EPLAN.EPLAN21.MACRO.REPLACEPROPS"); if(modifyMacroCmd != EPL_ERROR) { eplSetHandleParam(hSession, modifyMacroCmd, EPL_PARAM_MACRO_REPLACEPROPS_MACRO, hMacro, 0); eplSetParam( hSession, modifyMacroCmd, EPL_PARAM_MACRO_REPLACEPROPS_REPLACESTRINGS, replaceString.c_str(), 0 ); eplSetParam( hSession, modifyMacroCmd, EPL_PARAM_MACRO_REPLACEPROPS_REMOVEUNKNOWNVAR, removeUnknownVar ? L"1" : L"0", 0 ); if(eplExecuteCommand(hSession, modifyMacroCmd) != EPL_ERROR) { retVal = true; } eplCloseObject(hSession, modifyMacroCmd); } return retVal; } |