AnsweredAssumed Answered

C# macro doesn't build

Question asked by Idriss Nwagoum on Mar 13, 2021
Latest reply on Mar 15, 2021 by Rob Edwards

Hello everyone,

I'm pretty new with C# macros and i was trying to create a mate faces  macro within an assembly, but it just won't build in VS, i keep getting the following error:
 'SldWorks' is a 'namespace' but is used like a 'type' 

can somebody help please?

i'm using SW 2020 and  VS 2015.

here is pasted the SolidWorksMacro.cs

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;

using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;


namespace m6
{
public partial class SolidWorksMacro
{
public void Main()
{

ModelDoc2 swDoc = null;
PartDoc swPart = null;
DrawingDoc swDrawing = null;
AssemblyDoc swAssembly = null;
bool boolstatus = false;
int longstatus = 0;
int longwarnings = 0;
//
// Open
swDoc = ((ModelDoc2)(swApp.OpenDoc6("E:\\SW api example\\Table.SLDASM", 2, 0, "", ref longstatus, ref longwarnings)));
swAssembly = swDoc;
swApp.ActivateDoc2("Table.SLDASM", false, ref longstatus);
swDoc = ((ModelDoc2)(swApp.ActiveDoc));
swDoc = ((ModelDoc2)(swApp.ActiveDoc));
ModelView myModelView = null;
myModelView = ((ModelView)(swDoc.ActiveView));
myModelView.FrameLeft = 0;
myModelView.FrameTop = 0;
myModelView = ((ModelView)(swDoc.ActiveView));
myModelView.FrameState = ((int)(swWindowState_e.swWindowMaximized));
myModelView = ((ModelView)(swDoc.ActiveView));
myModelView.FrameState = ((int)(swWindowState_e.swWindowMaximized));
boolstatus = swDoc.Extension.SelectByRay(0.016163017996802864, 0.14690640911069863, 0.15107875313559305, -0.98696628942467179, 0.11206479217465459, 0.11549470071889248, 0.00245922486302195, 2, true, 1, 0);
boolstatus = swDoc.Extension.SelectByRay(-0.020442615198021485, 0.056040609040373113, -0.024999999999991473, -0.98696628942467179, 0.11206479217465459, 0.11549470071889248, 0.00245922486302195, 2, true, 1, 0);
swDoc.ClearSelection2(true);
boolstatus = swDoc.Extension.SelectByRay(0.016163017996802864, 0.14690640911069863, 0.15107875313559305, -0.98696628942467179, 0.11206479217465459, 0.11549470071889248, 0.00245922486302195, 2, true, 1, 0);
boolstatus = swDoc.Extension.SelectByRay(-0.020442615198021485, 0.056040609040373113, -0.024999999999991473, -0.98696628942467179, 0.11206479217465459, 0.11549470071889248, 0.00245922486302195, 2, true, 1, 0);
//
// Create CoincidentMateFeatureData
object MateData = null;
swAssembly = ((AssemblyDoc)(swDoc));
MateData = swAssembly.CreateMateData(0);
//
// Set the Entities To Mate
object EntitiesToMate(1) = null;
Set EntitiesToMate(0) = swDoc.ISelectionManager.GetSelectedObject6(1, -1);
EntitiesToMate(1) = ((object)(swDoc.ISelectionManager.GetSelectedObject6(2, -1)));
Variant EntitiesToMateVar;
EntitiesToMateVar = EntitiesToMate;
MateData.EntitiesToMate = EntitiesToMateVar;
//
// Set the Mate Alignment
MateData.MateAlignment = 0;
//
// Create the mate
object MateFeature = null;
swAssembly = ((AssemblyDoc)(swDoc));
MateFeature = swAssembly.CreateMate(MateData);
swDoc.ClearSelection2(true);
swDoc.EditRebuild3();
//


return;
}

// The SldWorks swApp variable is pre-assigned for you.
public SldWorks swApp;

}
}

Outcomes