 |
SOLIDWORKS Electrical API
2020.0.5
Electrical API
|
Purpose
This document presents some samples of using API in C#.
- Note
- mEwApplicationX: application object previously created.
Samples
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);
}
Open a project
Open a project from name
public void openProjectbyName()
{
EwEnvironmentX ewEnvironment = mEwApplicationX.
getEwEnvironment(out ewErrorCode);
IEwProjectManagerX iEwProjectManagerX = ewEnvironment.getEwProjectManager(out ewErrorCode);
}
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)
{
}
Open a project from file path
public void openProjectbyFilePath()
{
EwEnvironmentX ewEnvironment = mEwApplicationX.
getEwEnvironment(out ewErrorCode);
IEwProjectManagerX iEwProjectManagerX = ewEnvironment.getEwProjectManager(out ewErrorCode);
}
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();
}
}
}
Open a project file
To do that you must use the command EWOPEN command.
\Example 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.
...
\\ ewProjectFile: the file to open. Project must be opened and must be the current one.
string strFilePath = ewProjectFile.getFilePath();
string strCommand = "EWOPEN ";
strCommand += strFilePath;
mEwApplicationX.runcommand(strCommand);
Export report
Export report in Excel
public void doExportReportIn()
{
string strTempFolder = Path.GetTempPath();
}
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();
}
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);
string[] arrayOfFiles = Directory.GetFiles(strPathAndName);
}
Use this interface to manage the report used inside the project.
Definition: EwProjectExportObjects.idl:821
EwOpenProjectMode
All possible open modes for a project.
Definition: EwEnumeration.idl:434
EwErrorCode doExcelExport()
Export reports in Excel type.
EwFileType
File types used in a project.
Definition: EwEnumeration.idl:352
Use this interface to manage IEwProjectX objects.
Definition: EwProjectObjects.idl:1793
Use this interface to manage the export reports used inside the project.
Definition: EwProjectExportObjects.idl:986
IEwProjectX findEwProjectByName(BSTR strName, EwErrorCode *errorCode)
Look for the first project from a name.
EwErrorCode
All errors codes for this API.
Definition: EnumDefinition.idl:21
EwErrorCode setEwProjectDataExportType(EwProjectDataExportType eProjectDataExportType)
Update the type of report to export.
EwErrorCode setBookOrFolderId(long lBookOrFolderId)
Set the id of the destination folder or book where the reports will be exported.
EwErrorCode setEwProjectReportIDArray(VARIANT ewProjectReportIDArray)
Set array of ID of EwProjectReport objects.
IEwEnvironmentX getEwEnvironment(EwErrorCode *errorCode)
EwFileExtension
All file types extension.
Definition: EwEnumeration.idl:510
Use this interface to manage IEwProjectBookX objects.
Definition: EwProjectObjects.idl:788
IEwProjectX findProjectFromFilePath(BSTR strFilePath, EwErrorCode *errorCode)
Return an IEwProjectX from a file path.
EwErrorCode setTargetFolder(BSTR strFolderPath)
Update the exported target folder path.
EwErrorCode openEwProjectID(LONG lID)
Open a project in the application interface.
EwErrorCode setExportAllReports(VARIANT_BOOL bExportAllReports)
Set this flag to true to export all reports of the project.
Use this interface to manage a project.
Definition: EwProjectObjects.idl:1079
EwErrorCode setOneSheetByBreak(VARIANT_BOOL bOneSheetByBreak)
Set this flag to true to export one sheet by break.
EwProjectDataExportType
All data export configuration.
Definition: EwEnumeration.idl:456
EwErrorCode open(EwOpenProjectMode eOpenMode)
open the project
VARIANT getEwProjectBookArray(EwErrorCode *errorCode)
Return the array of IEwProjectBook of associated project.
IEwProjectX findEwProjectByID(LONG lId, EwErrorCode *errorCode)
Look for a project from an ID.
EwErrorCode getSystemInformation(BSTR bstrPath)
Collect information on electrical application.
VARIANT unarchive(BSTR strFilePath, VARIANT_BOOL bWithDependencies, EwErrorCode *errorCode)
Unarchive projects.
Use this interface to manage book inside a project.
Definition: EwProjectObjects.idl:590
EwErrorCode setAddCreatedFileToProject(VARIANT_BOOL bAddCreatedFileToProject)
Set this value to true to add exported files to the project.
EwErrorCode setEwFileExtension(EwFileExtension ewExtension)
Update the report type file extension.