Hello,
My project compiles alright with no errors or warnings, but when I go to add the dll to SolidWorks (by dragging it in) I get this error:
Unable to initialize Add-in Componet.
Edit: When I try to manually add the dll from the command prompt I get this error.
Edit2: I tried registering it with RegAsm and I got this error.
Since Visual Studio can't point me to what I'm doing wrong I hope someone on here can.
SolidworksApi macrosusing System.Runtime.InteropServices;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;namespace SolidworksPlugin
{
public class SolidworksPlugin
{
int FrameState { get; set; }
public SldWorks swApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");
public SolidworksPlugin()
{
ModelDoc2 swModel = swApp.ActiveDoc as ModelDoc2;
ModelDocExtension swModExt = swModel.Extension;
DrawingDoc swDrawDoc = (DrawingDoc)swModel;
Sheet swSheet = (Sheet)swModel;
string userName = System.Environment.UserName;
string dateTime = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt");
string filePath = swModel.GetPathName();
int Errors = 0;
int Warnings = 0;
string sheetName = swSheet.GetName();
string lineOfText = filePath + " " + sheetName + " " + dateTime + " " + " by " + userName;
string[] obj = null;
bool boolstatus = false;
DispatchWrapper[] dispWrapArr = null;
int swSelNOTES = 15;swModel.EditSketch();
swModel.SelectByID("", "Note", 0.008199680981595, 0.00594718404908, 0);SelectionMgr swSelMgr = swModel.SelectionManager as SelectionMgr;
object selObj;
int selCount = swSelMgr.GetSelectedObjectCount2(-1);
if (selCount != 0)
{
selObj = (object)swSelMgr.GetSelectedObject6(1, -1);
if (swSelMgr.GetSelectedObjectType3(1, -1) == swSelNOTES)
{
swModel.EditSketch();
}
}swModel.SelectByID("1", "SHEET", 0.008199680981595, 0.00594718404908, 0);
swModel.InsertNewNote3(lineOfText, true, true, 1, 0, 0, 0, 0, true);
swModel.EditSketch();swModel.SelectByID("", "NOTE", 0.008199680981595, 0.00594718404908, 0);
swModel.FontPoints(11);
swModel.ClearSelection2(true);
object swActiveView = swModel.ActiveView;
FrameState = 1;ExportPdfData swExportPDFData = (ExportPdfData)swApp.GetExportFileData((int)swExportDataFileType_e.swExportPdfData);
// Get the names of the drawing sheets in the drawing
// to get the size of the array of drawing sheets
swDrawDoc = (DrawingDoc)swModel;
obj = (string[])swDrawDoc.GetSheetNames();
int count = 0;
count = obj.Length;
int i = 0;
object[] objs = new object[count - 1];// Active each drawing sheet, except the last drawing sheet for
// demonstration purposes only, and add each sheet to an array
// of drawing sheets
for (i = 0; i < count - 1; i++)
{
boolstatus = swDrawDoc.ActivateSheet((obj[i]));
swSheet = (Sheet)swDrawDoc.GetCurrentSheet();
objs[i] = swSheet;
}// Convert the .NET array of drawing sheets objects to IDispatch
dispWrapArr = (DispatchWrapper[])ObjectArrayToDispatchWrapperArray((objs));// Save the drawings sheets to a PDF file
boolstatus = swExportPDFData.SetSheets((int)swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, (dispWrapArr));
boolstatus = swModExt.SaveAs(filePath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, swExportPDFData, ref Errors, ref Warnings);
}public DispatchWrapper[] ObjectArrayToDispatchWrapperArray(object[] Objects)
{
int ArraySize = 0;
ArraySize = Objects.GetUpperBound(0);
DispatchWrapper[] d = new DispatchWrapper[ArraySize + 1];
int ArrayIndex = 0;
for (ArrayIndex = 0; ArrayIndex <= ArraySize; ArrayIndex++)
{
d[ArrayIndex] = new DispatchWrapper(Objects[ArrayIndex]);
}
return d;
}
}
}