Son Trinh-Van

Linking Matlab and SolidWorks

Discussion created by Son Trinh-Van on Jan 19, 2021
Latest reply on Jan 19, 2021 by Son Trinh-Van

Hi everyone, 

 

I have made a VBA code to create a new part in Solidworks and select the Front Plane for sketching, as below:

 

Dim swApp As SldWorks.SldWorks

Dim Part As SldWorks.ModelDoc2

Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2021\templates\Part.prtdot", 0, 0, 0)

boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

End Sub

 

The code is working perfectly.

 

However, when I try to do the same thing with the Matlab code, it is NOT working, My Matlab code is as below:

 

swApp=actxserver('SLDWORKS.application');
invoke(swApp,'Visible','true');
invoke(swApp,'CloseAllDocuments','True');
Part=invoke(swApp,'NewDocument','C:\ProgramData\SolidWorks\SOLIDWORKS 2021\templates\Part.prtdot', 0, 0, 0);
swModel=invoke(swApp,'ActiveDoc');
swSelMgr=invoke(swModel,'SelectionManager');
swModelDocExt=invoke(swModel,'Extension');
slstatus=invoke(swModelDocExt,'SelectByID2','Front Plane','PLANE','0','0','0','False','0','Nothing','0');

 

The error has occurred at the final line. It is said that argument 8th of the method "SelectByID2" is not correct. I do not know why, because I have directly converted from VBA code.

 

If someone could help me to solve the problem in Matlab code, this would be greatly appreciated.

 

Thanks in advance.

Outcomes