Purpose
This document presents some samples of using API in C#.
- Note
- mEwApplicationX: application object previously created.
Create a new project
Create a project from specified template
public void createProjectFromTemplate()
{
EwEnvironmentX ewEnvironment = mEwApplicationX.getEwEnvironment(out ewErrorCode);
IEwProjectManagerX iEwProjectManagerX = ewEnvironment.getEwProjectManager(out ewErrorCode);
Array lIdArray = iEwProjectManagerX.
unarchive(strFilePath,
true, out ewErrorCode);
long lId = (long)lIdArray.GetValue(0);
ewErrorCode = mEwApplicationX.openEwProjectID((int) lId);
}
EwErrorCode
All errors codes for this API.
Definition: EnumDefinition.idl:21
Use this interface to manage IEwProjectX objects.
Definition: EwProjectObjects.idl:2398
IEwProjectX findEwProjectByID(LONG lId, EwErrorCode *errorCode)
Look for a project from an ID.
VARIANT unarchive(BSTR strFilePath, VARIANT_BOOL bWithDependencies, EwErrorCode *errorCode)
Unarchive projects.
Use this interface to manage a project.
Definition: EwProjectObjects.idl:1557
Open a project
Open a project from name
public void openProjectbyName()
{
EwEnvironmentX ewEnvironment = mEwApplicationX.getEwEnvironment(out ewErrorCode);
IEwProjectManagerX iEwProjectManagerX = ewEnvironment.getEwProjectManager(out ewErrorCode);
}
EwOpenProjectMode
All possible open modes for a project.
Definition: EwEnumeration.idl:474
IEwProjectX findEwProjectByName(BSTR strName, EwErrorCode *errorCode)
Look for the first project from a name.
EwErrorCode open(EwOpenProjectMode eOpenMode)
open the project
Open a project from id
public void openProjectbyId(int lID)
{
EwEnvironmentX ewEnvironment = mEwApplicationX.getEwEnvironment(out ewErrorCode);
IEwProjectManagerX iEwProjectManagerX = ewEnvironment.getEwProjectManager(out ewErrorCode);
}
Open a project from id in the Application
public void openProjectbyName(int lID)
{
ewErrorCode = mEwApplicationX.openEwProjectID(lID);
}
Open a project from file path
public void openProjectbyFilePath()
{
EwEnvironmentX ewEnvironment = mEwApplicationX.getEwEnvironment(out ewErrorCode);
IEwProjectManagerX iEwProjectManagerX = ewEnvironment.getEwProjectManager(out ewErrorCode);
}
IEwProjectX findProjectFromFilePath(BSTR strFilePath, EwErrorCode *errorCode)
Return an IEwProjectX from a file path.
Use project file
- Note
- mEwProjectX: project object previously created.
Delete a Project file
public void deleteProjectFile()
{
EwProjectFileManagerX ewProjectFileManager = mEwProjectX.getEwProjectFileManager(out ewErrorCode);
if (ewProjectFileManager.getCount(out ewErrorCode) > 0)
{
EwProjectFileX[] array = ewProjectFileManager.getEwProjectFileArray(out ewErrorCode);
for (int i = 0; i < ewProjectFileManager.getCount(out ewErrorCode); i++)
{
EwProjectFileX ewProjectFile = array[0];
if(ewProjectFile.getFileType() ==
EwFileType.kFileLineDiagram)
ewErrorCode = ewProjectFile.remove();
}
}
}
EwFileType
File types used in a project.
Definition: EwEnumeration.idl:386
Open a project file
To do that you must use the command EWOPEN command.
EWOPENFILE "D:\\ProgramData\\...\\Projects\\1216\\Drawings\\11319.ewg"
This command takes one parameter, the file path to open. To obtain this path use the getFilePath API from EwProjectFile object.
...
string strFilePath = ewProjectFile.getFilePath();
string strCommand = "EWOPEN ";
strCommand += strFilePath;
mEwApplicationX.runcommand(strCommand);
Get the project file description
public void descriptionFileProject()
{
EwProjectFileManagerX ewProjectFileManager = mEwProjectX.getEwProjectFileManager(out ewErrorCode);
if (ewProjectFileManager.getCount(out ewErrorCode) > 0)
{
EwProjectFileX[] array = ewProjectFileManager.getEwProjectFileArray(out ewErrorCode);
EwProjectConfigurationX mEwProjectConfigurationX = mEwProjectX.getEwProjectConfiguration(out ewErrorCode);
string strLanguage = mEwProjectConfigurationX.getCurrentCodeLanguage(out ewErrorCode);
for (int i = 0; i < ewProjectFileManager.getCount(out ewErrorCode); i++)
{
EwProjectFileX ewProjectFile = array[0];
string strDescription = ewProjectFile.getTranslatedData(0, strLanguage, out ewErrorCode);
}
}
}
Insert a symbol in a project file
public void insertSymbol()
{
EwProjectComponentManagerX ewProjectComponentManager = mEwProjectX.getEwProjectComponentManager(out ewErrorCode);
ewProjectComponentX.
setTag(
"ComponentMark");
ewErrorCode = ewProjectComponentX.
insert();
mEwProjectSymbolX = ewProjectFileX.newEwProjectSymbol(out ewErrorCode);
mEwProjectSymbolX.setEwSymbolName("TR-DI007");
mEwProjectSymbolX.setRotationAngle(90);
mEwProjectSymbolX.setXPosition(150);
mEwProjectSymbolX.setYPosition(100);
mEwProjectSymbolX.setObjectID(ewProjectComponentX.
getID());
ewErrorCode = mEwProjectSymbolX.insert();
}
EwErrorCode insert()
Insert the object inside the current project.
Use this interface to manage a component inside a project.
Definition: EwProjectComponentObjects.idl:522
EwErrorCode setTag(BSTR strValue)
Set the mark of this object.
Use classification
Get a class name
public void classificationGetClassName()
{
dynamic ewClassArray = iEwClassificationManagerX.
getEwClassArray(out ewErrorCode);
{
string strClassComplete = "";
string strParent = "";
if (ewClassX != null)
{
strClassComplete = strParent + "\\" + strClass;
}
else
strClassComplete = strClass;
}
}
EwClassificationType
Classification for components, symbols and manufacturer parts Enum Change due to TEW-49235 kComponent...
Definition: EwEnumeration.idl:580
Use this interface to manage an EwClassX object.
Definition: EwClassificationObjects.idl:25
LONG getParentID(EwErrorCode *errorCode)
Return the ID of the parent of the class.
Use this interface to manage EwClassificationX objects.
Definition: EwClassificationObjects.idl:392
IEwClassificationX getEwClassification(EwClassificationType eClassificationType, EwErrorCode *errorCode)
Get an interface of classificationX from classification type.
IEwClassX findEwClassByID(long lID, EwErrorCode *errorCode)
Get node find by id in current classification.
VARIANT getEwClassArray(EwErrorCode *errorCode)
Get array of all nodes found in current classification.
Use this interface to manage an IEwClassificationX object.
Definition: EwClassificationObjects.idl:214
BSTR getTranslatedData(LONG nUserDataNumber, BSTR strLanguage, EwErrorCode *errorCode)
Get the value of a translated text.
Get a class name from a component
public void classificationGetClassNameByComponent()
{
EwProjectComponentX ewComponent = nullptr;
...
int iClassId = ewComponent.getClassComponentType(out ewErrorCode);
}
Export report
Export report in Excel
public void doExportReportIn()
{
string strTempFolder = Path.GetTempPath();
}
EwProjectDataExportType
All data export configuration.
Definition: EwEnumeration.idl:497
EwFileExtension
All file types extension.
Definition: EwEnumeration.idl:554
Use this interface to manage the export reports used inside the project.
Definition: EwProjectExportObjects.idl:997
EwErrorCode setExportAllReports(VARIANT_BOOL bExportAllReports)
Set this flag to true to export all reports of the project.
EwErrorCode doExcelExport()
Export reports in Excel type.
EwErrorCode setOneSheetByBreak(VARIANT_BOOL bOneSheetByBreak)
Set this flag to true to export one sheet by break.
EwErrorCode setTargetFolder(BSTR strFolderPath)
Update the exported target folder path.
EwErrorCode setEwFileExtension(EwFileExtension eFileExtension)
Update the report type file extension.
EwErrorCode setEwProjectDataExportType(EwProjectDataExportType eProjectDataExportType)
Update the type of report to export.
Export specified report in Excel
public void exportSpecifiedReportInExcel()
{
EwProjectReportManagerX ewProjectReportManagerX = mEwProjectX.getEwProjectReportManager(out ewErrorCode);
string strToFolder = Path.GetTempPath() + Guid.NewGuid() + "\\";
if (Directory.Exists(strToFolder) == true)
Directory.Delete(strToFolder, true);
Directory.CreateDirectory(strToFolder);
int lBookOrFolderId = ewProjectBook.
getID();
long[] aArrayId = new long[2];
IEwProjectReportX ewProjectReport = ewProjectReportManagerX.find(
"Folio_Metric.xml",
"", out ewErrorCode);
if (ewProjectReport == null)
return;
aArrayId[0] = ewProjectReport.
getID();
ewProjectReport = ewProjectReportManagerX.find(“CableGroupedByReference_Metric.xmlâ€, "", out ewErrorCode)
if (ewProjectReport == null)
return;
aArrayId[1] = ewProjectReport.
getID();
}
Use this interface to manage IEwProjectBookX objects.
Definition: EwProjectObjects.idl:1260
VARIANT getEwProjectBookArray(EwErrorCode *errorCode)
Return the array of IEwProjectBook of associated project.
Use this interface to manage book inside a project.
Definition: EwProjectObjects.idl:1043
EwErrorCode setBookOrFolderId(long lBookOrFolderId)
Set the id of the destination folder or book where the reports will be exported.
EwErrorCode setEwProjectReportIDArray(VARIANT vProjectReportIDArray)
Set array of ID of EwProjectReport objects.
EwErrorCode setAddCreatedFileToProject(VARIANT_BOOL bAddCreatedFileToProject)
Set this value to true to add exported files to the project.
Use this interface to manage the report used inside the project.
Definition: EwProjectExportObjects.idl:825
Renumber Wire
Renumber Wire Manually
public void doRenumberWireManuallyInABook()
{
EwProjectNumberWiresX ewProjectNumberWires = mEwProjectX.newEwProjectNumberWires(out ewErrorCode);
long[] aBookArrayId = new long[1];
aBookArrayId[0] = 1;
ewErrorCode = mEwProjectNumberWires.setSelectionType(
EwSelectionType.kSelectionBook);
ewErrorCode = mEwProjectNumberWires.setSelection(aBookArrayId);
ewErrorCode = mEwProjectNumberWires.process(action);
}
public void doRenumberWireManuallyInScheme()
{
EwProjectNumberWiresX ewProjectNumberWires = mEwProjectX.newEwProjectNumberWires(out ewErrorCode);
int iSize = aFileArray.Length;
long[] aFileArrayId = new long[iSize];
for (int i = 0; i < iSize; i++)
{
aFileArrayId[i] = ewProjectFileX.
getID();
}
ewErrorCode = mEwProjectNumberWires.setSelectionType(
EwSelectionType.kSelectionScheme);
ewErrorCode = mEwProjectNumberWires.setSelection(aFileArrayId);
ewErrorCode = mEwProjectNumberWires.process(action);
}
EwSelectionType
All the selection types.
Definition: EnumDefinition.idl:298
Use this interface to manage EwProjectFileManagerx objects.
Definition: EwProjectObjects.idl:1088
VARIANT getEwProjectFileArray(EwErrorCode *errorCode)
Return the array of IEwProjectFile of associated project.
Use this interface to manage file inside a project.
Definition: EwProjectObjects.idl:757
Renumber Wire
public void doRenumberWireAutomatic()
{
EwProjectNumberWiresX ewProjectNumberWires = mEwProjectX.newEwProjectNumberWires(out ewErrorCode);
ewErrorCode = ewProjectNumberWires.setActionOnManualNumber(false);
ewErrorCode = ewProjectNumberWires.setResetPosition(false);
ewErrorCode = ewProjectNumberWires.setSelectionType(
EwSelectionType.kSelectionAll);
}
EwNumberWireAction
All the possible actions for renumber wires.
Definition: EnumDefinition.idl:283
Add Origin-Destination Arrow
Add Origin-Destination Arrow Manually
public void doOriginDestinationArrowManually()
{
EwProjectSymbolX ewProjectSymbolX = mEwProjectFile.newEwProjectSymbol(out ewErrorCode);
ewProjectSymbolX.setEwSymbolName("TR-OLINK");
ewErrorCode = ewProjectSymbolX.setXPosition(160;
ewErrorCode = ewProjectSymbolX.setYPosition(180);
ewErrorCode = ewProjectSymbolX.setRotationAngle(90);
ewErrorCode = ewProjectSymbolX.insert();
int iComponentID = ewProjectSymbolX.getObjectID(out ewErrorCode);
ewProjectSymbolX = mEwProjectFile.newEwProjectSymbol(out ewErrorCode);
ewProjectSymbolX.setEwSymbolName("TR-ILINK");
ewErrorCode = ewProjectSymbolX.setXPosition(180);
ewErrorCode = ewProjectSymbolX.setYPosition(180);
ewErrorCode = ewProjectSymbolX.setRotationAngle(90);
ewErrorCode = ewProjectSymbolX.setObjectID(iComponentID);
ewErrorCode = ewProjectSymbolX.insert();
EwProjectNumberWiresX ewProjectNumberWires = mEwProjectX.newEwProjectNumberWires(out ewErrorCode);
ewErrorCode = ewProjectNumberWires.setActionOnManualNumber(false);
ewErrorCode = ewProjectNumberWires.setResetPosition(false);
ewErrorCode = ewProjectNumberWires.setSelectionType(
EwSelectionType.kSelectionAll);
}
Add Origin-Destination Arrow Automatically
public void doOriginDestinationArrowAutomatically()
{
EwProjectAutomaticArrowsX mEwProjectAutomaticArrows;
mEwProjectAutomaticArrows = mEwProjectX.newEwProjectAutomaticArrows(out ewErrorCode);
ewErrorCode = mEwProjectAutomaticArrows.setActionOnManual(false);
ewErrorCode = mEwProjectAutomaticArrows.setSelectionType(
EwSelectionType.kSelectionAll);
ewErrorCode = mEwProjectAutomaticArrows.setEquipotentialConnectionType(
EwAutoArrowMarkType.kAutoArrowMarkManualAndAuto);
ewErrorCode = mEwProjectAutomaticArrows.setLocationConnectionType(
EwAutoArrowLocConnectType.kAutoArrowLocConnectAllLocation);
}
EwAutoArrowActionType
Enum which contains all action for the origin destination automatic insertion.
Definition: EwEnumeration.idl:910
EwAutoArrowMarkType
Enum which contains marks type that we want to be aware for the origin destination automatic insertio...
Definition: EwEnumeration.idl:899
EwAutoArrowLocConnectType
Enum which contains all connection types related with the file location for the Origin Destination au...
Definition: EwEnumeration.idl:887
Some samples with the application
Collect information on electrical application
public void collectInformation()
{
string strPathAndName = Path.Combine(Path.GetTempPath(), "getSystemInformation\\");
if (Directory.Exists(strPathAndName) == true)
Directory.Delete(strPathAndName, true);
Directory.CreateDirectory(strPathAndName);
EwErrorCode ewErrorCode = mEwApplicationX.getSystemInformation(strPathAndName);
string[] arrayOfFiles = Directory.GetFiles(strPathAndName);
}