6 Replies Latest reply on Sep 19, 2017 5:18 PM by Raymond Yau

    record macros in C#

    Raymond Yau

      Hi,

       

      I'm certain I'm not the only one to ask this, but I can't seem to find anything on recording C# macros within Solidworks. I only have the VBA option.

       

       

      Also, I got MS Visual Studio installed and I can run C# macros from that, but is it possible to run it from within Solidworks i.e. setup a macro shortcut button?

       

      Thanks.

        • Re: record macros in C#
          Alex Burnett

          The short answer is no. SolidWorks macros run from VBA only using the built in tool to create the .swp files. In order to run a macro using c#, you have to create a standalone program that connects to SW with the provided API files for your version of SW. It is very similar from that point forward but getting the references and everything figured out the first time can be a bit frustrating.

          • Re: record macros in C#
            Amen Allah Jlili

            Hope this helps (original thread)

            SolidWorks VB.NET and C# macros are recorded, created, edited, and run using Microsoft Visual Studio Tools for Applications (VSTA), which is installed with the SolidWorks software. VSTA has a software dependency on Microsoft .NET Framework 3.5. Because of this dependency, VSTA might or might not be installed by default when you install SolidWorks.

              

            Operating System

            SolidWorks installs VSTA and Microsoft .NET Framework 3.5 by default?

            Windows Vista

            Yes

            Windows 7

            Yes

            Windows 8

            No

             

            You must select the Visual Studio Tools option during SolidWorks installation. If you select Visual Studio Tools, during the installation, Windows 8 prompts you with:

            An app on your PC needs the following Windows feature:

            .NET Framework 3.5 (includes .NET 2.0 and 3.0)

            • Download and install this feature
              Windows will get the files that it needs from Windows Update and complete the installation.
            • Skip this installation
              Your apps might not work correctly without this feature.
            NOTE: You need internet access if you select Visual Studio Tools during SolidWorks installation. If you do not have internet access, you need your Windows 8 installation DVDs.

            When VSTA and Microsoft .NET Framework 3.5 are installed, the SolidWorks Tools > Macro > Edit > Open > File namedropdown contains:

            • SW VBA Macros (*.swp)
            • SW VSTA VB Macro (*.vbproj)
            • SW VSTA C# Macro (*.csproj)
            • SW Macros (*.swp, *.swb, *.csproj, *.vbproj)

            and the SolidWorks Tools > Macro > New > Save As > Save as type dropdown contains:

            • SW VBA Macros (*.swp)
            • SW VSTA VB Macro (*.vbproj)
            • SW VSTA C# Macro (*.csproj)

             

            VSTA and Windows 8

            If you do not select the Visual Studio Tools option during SolidWorks installation on Windows 8:

            • You cannot modify the installation to add it. You must uninstall SolidWorks, re-install SolidWorks, and select the Visual Studio Tools option during installation.
            • VSTA is not installed, you cannot record, create, edit, or run VB.NET or C# macros, and all of the SolidWorks macro dialog dropdowns contain only:

            SW VBA Macros (*.swp)

            • Re: record macros in C#
              Raymond Yau

              Got it:

               

              I had to turn on .NET 3.5 Framework first from Windows settings

              Then installed VSTA from the disk I had, it was previously unchecked.