How to run solidworks vba macros from matlab?

14 visualizaciones (últimos 30 días)
Anish Chitnis
Anish Chitnis el 3 de Feb. de 2022
Respondida: Pratyush el 18 de En. de 2024
I am trying to run a VBA macro from a .m file. I've been able to successfully get Solidworks to start and open a part using:
swApp=actxserver('SLDWORKS.application')
set(swApp, 'Visible', true);
O1 =invoke(swApp,'OpenDoc','[file location]',1);
However, when trying to run a macro using the code below, the macro doesn't seem to run. No error is returned, but the macro hasn't run.
S1=invoke(swApp ,'RunAttachedMacro','Macro2.swp', 'Macro21', 'main')
Is there a problem in the way I'm calling the macro from matlab?
Thanks!

Respuestas (1)

Pratyush
Pratyush el 18 de En. de 2024
Hi Anish,
You're using "invoke" to call methods on the SolidWorks application object. The usage of "invoke" seems correct, but there might be an issue with the parameters you're passing to the "RunAttachedMacro" method.
Ensure the following:
  1. The file path to the macro is correct and accessible by MATLAB.
  2. The macro file name, module name, and procedure name are all correct.
  3. The SolidWorks application has permissions to execute macros (consider security settings).
  4. Another alternative is to use "run" method.
Hope this helps.

Categorías

Más información sobre Data Export to MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by