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.
I am not a MatLab user, but I suspect the issue is that you pass all parameters as string. Nothing is a null reference to an object and MatLab cannot cast it from 'Nothing' string. Same applies to the boolean values 'True' and 'False'. As this is weak cast language it does not fail, but it might get a wrong cast. So you might also pas those values as True and False instead of 'True' and 'False'.