Good day! Please tell me how to add multiple parts in an Assembly in C#. The macro does not help. Created the Assembly, but the part is not added.
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
namespace Macro1.csproj
{
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;
swDoc = ((ModelDoc2)(swApp.NewDocument("C:\\ProgramData\\SolidWorks\\SolidWorks 2016\\templates\\gost-assy.asmdot", 0, 0, 0)));
swApp.ActivateDoc2("Сборка2", false, ref longstatus);
swDoc = ((ModelDoc2)(swApp.ActiveDoc));
ModelView myModelView = null;
myModelView = ((ModelView)(swDoc.ActiveView));
myModelView.FrameState = ((int)(swWindowState_e.swWindowMaximized));
swAssembly = ((AssemblyDoc)(swDoc));
boolstatus = swAssembly.AddComponent("C:\\Users\\Desktop\\fgfg.SLDPRT", 0.027620825299025514, 0.072698020262157451, 0.15179969937013105);
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}
There is a difference otherwise it would have not been called VB.NET. VBA runs on a VB6 engine and VB.NET runs on the .NET platform. Here's the VBA example: 2013 SOLIDWORKS API Help - Add Component and Mate Example (VBA)