Fix invalid namespace in VSTA (C# or VB.NET) SOLIDWORKS macro
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
{ width=450 }
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
{ width=250 }
- Copy the value in the Default Namespace field of the Application tab
{ width=350 }
- Rename the namespace to the copied value
{ width=500 }
- Rebuild the macro