See more issues and resolutions

Symptoms

Example for SOLIDWORKS VSTA macro (C# or VB.NET) is copied from the SOLIDWORKS API Help documentation or from any source as a code. Number of compilation error are displayed:

  • MacroName.SolidWorksMacro doesn’t contain a definition for ‘SwApp’
  • The name ‘Main’ doesn’t exist in the current context
Compile error when code is copied from the example into the VSTA macro
Compile error when code is copied from the example into the VSTA macro

Cause

VSTA macro is based on multiple connected files which must reside in the same namespace. When new macro is created the namespace might not be equal to the one used in the example source code.

namespace MacroName.csproj
{
  ...
}

Resolution

Change the namespace in the SolidWorksMacro.cs file to match the default namespace

  • Open the project properties page
VSTA macro project properties
VSTA macro project properties
  • Copy the value in the Default Namespace field of the Application tab
Default namespace of the VSTA project
Default namespace of the VSTA project
  • Rename the namespace to the copied value
Renamed namespace to match the default namespace
Renamed namespace to match the default namespace
  • Rebuild the macro