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.
<p>using System.Runtime.InteropServices;<br>using SolidWorks.Interop.sldworks;<br>using SolidWorks.Interop.swconst;<br>using System;</p><p></p><p>namespace SolidworksPlugin<br>{<br> public class SolidworksPlugin<br> {<br> int FrameState { get; set; }<br> public SldWorks swApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");<br> public SolidworksPlugin()<br> {<br> ModelDoc2 swModel = swApp.ActiveDoc as ModelDoc2;<br> ModelDocExtension swModExt = swModel.Extension;<br> DrawingDoc swDrawDoc = (DrawingDoc)swModel;<br> Sheet swSheet = (Sheet)swModel;<br> string userName = System.Environment.UserName;<br> string dateTime = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt");<br> string filePath = swModel.GetPathName();<br> int Errors = 0;<br> int Warnings = 0;<br> string sheetName = swSheet.GetName();<br> string lineOfText = filePath + " " + sheetName + " " + dateTime + " " + " by " + userName;<br> string[] obj = null;<br> bool boolstatus = false;<br> DispatchWrapper[] dispWrapArr = null;<br> int swSelNOTES = 15;</p><p></p><p> swModel.EditSketch();<br> swModel.SelectByID("", "Note", 0.008199680981595, 0.00594718404908, 0);</p><p></p><p> SelectionMgr swSelMgr = swModel.SelectionManager as SelectionMgr;<br> object selObj;<br> int selCount = swSelMgr.GetSelectedObjectCount2(-1);<br> if (selCount != 0)<br> {<br> selObj = (object)swSelMgr.GetSelectedObject6(1, -1);<br> if (swSelMgr.GetSelectedObjectType3(1, -1) == swSelNOTES)<br> {<br> swModel.EditSketch();<br> }<br> }</p><p></p><p> swModel.SelectByID("1", "SHEET", 0.008199680981595, 0.00594718404908, 0);<br> swModel.InsertNewNote3(lineOfText, true, true, 1, 0, 0, 0, 0, true);<br> swModel.EditSketch();</p><p></p><p> swModel.SelectByID("", "NOTE", 0.008199680981595, 0.00594718404908, 0);<br> swModel.FontPoints(11);<br> swModel.ClearSelection2(true);<br> object swActiveView = swModel.ActiveView;<br> FrameState = 1;</p><p></p><p> ExportPdfData swExportPDFData = (ExportPdfData)swApp.GetExportFileData((int)swExportDataFileType_e.swExportPdfData);</p><p></p><p> // Get the names of the drawing sheets in the drawing<br> // to get the size of the array of drawing sheets<br> swDrawDoc = (DrawingDoc)swModel;<br> obj = (string[])swDrawDoc.GetSheetNames();<br> int count = 0;<br> count = obj.Length;<br> int i = 0;<br> object[] objs = new object[count - 1];</p><p></p><p> // Active each drawing sheet, except the last drawing sheet for<br> // demonstration purposes only, and add each sheet to an array<br> // of drawing sheets<br> for (i = 0; i < count - 1; i++)<br> {<br> boolstatus = swDrawDoc.ActivateSheet((obj[i]));<br> swSheet = (Sheet)swDrawDoc.GetCurrentSheet();<br> objs[i] = swSheet;<br> }</p><p></p><p> // Convert the .NET array of drawing sheets objects to IDispatch<br> dispWrapArr = (DispatchWrapper[])ObjectArrayToDispatchWrapperArray((objs));</p><p></p><p> // Save the drawings sheets to a PDF file<br> boolstatus = swExportPDFData.SetSheets((int)swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, (dispWrapArr));<br> boolstatus = swModExt.SaveAs(filePath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, swExportPDFData, ref Errors, ref Warnings);<br> }</p><p></p><p> public DispatchWrapper[] ObjectArrayToDispatchWrapperArray(object[] Objects)<br> {<br> int ArraySize = 0;<br> ArraySize = Objects.GetUpperBound(0);<br> DispatchWrapper[] d = new DispatchWrapper[ArraySize + 1];<br> int ArrayIndex = 0;<br> for (ArrayIndex = 0; ArrayIndex <= ArraySize; ArrayIndex++)<br> {<br> d[ArrayIndex] = new DispatchWrapper(Objects[ArrayIndex]);<br> }<br> return d;<br> }<br> }<br>}</p>SolidworksApi macros