I am trying to create a macro feature a using VB.NET addin and am not having much luck. I have tried both the COM callbacks and .NET add-In callbacks methods described here as well as using some examples I found poking around the form. I am very familiar with making macro features as a VBA macro so I'm guessing there is something that I am unaware of when using .net so hopefully this is easy question.
The code below is just what i have been using to just try and get a feature inserted so there shouldn't be anything else causing an issue. I have the following module and class in separate .vb files in a project called MyProject, which is also the Start Up Project in a Solution. I have actually tried using InsertMacroFeature3 from an addin but know luck with that either.
In MyModule.vb
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Public Module MyModule
Public Sub Main()
Dim _app As SldWorks = GetObject(, "SldWorks.Application")
Dim _model As ModelDoc2 = _app.ActiveDoc
Dim FeatMgr As FeatureManager = _model.FeatureManager
Dim feat As Feature = FeatMgr.InsertMacroFeature3("TestFeature", "MyProject.MacroFeatureClass", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, swMacroFeatureOptions_e.swMacroFeatureByDefault)
If feat Is Nothing Then MsgBox("Macro Feature Failure")
End Sub
End Module
In MacroFeatureClass.vb
Imports SolidWorks.Interop.swpublished
Imports SolidWorks.Interop.swconst
<ComClass(MacroFeatureClass.ClassId, MacroFeatureClass.InterfaceId, MacroFeatureClass.EventsId)>
Public Class MacroFeatureClass
Implements ISwComFeature
Public Const ClassId As String = "1FEC45A4-8300-4FD2-AFC4-ED4952A6F4F5"
Public Const InterfaceId As String = "19DEA4FB-46F6-445D-B996-39BACD9B70CA"
Public Const EventsId As String = "8AF8B870-7455-431C-B5F2-718CCCA1607C"
Public Sub New()
MyBase.New()
End Sub
Public Function Rebuild(ByVal app As Object, ByVal model As Object, ByVal feat As Object) As Object Implements ISwComFeature.Regenerate
Return True
End Function
Public Function Edit(ByVal app As Object, ByVal model As Object, ByVal feat As Object) As Object Implements ISwComFeature.Edit
Return True
End Function
Public Function Security(ByVal app As Object, ByVal model As Object, ByVal feat As Object) As Object Implements ISwComFeature.Security
Return swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityByDefault
End Function
End Class
not true. i use visual studio 2017 and as long as you DO NOT embed interop Types, you can edit live code while running it. you have to launch solidworks through the play button(Debug) in visual studio. then you can edit, it will recompile and continue on. its quite nice and i dont know when the capability became possible. i only recently descovered it.
you cannot have Enable Optimizations set in Advanced Compile Options either.
i add macrofeatures, edit the comserver, then add more, edit some more.
also the COM Server DOES NOT embed in the feature. you can change the COM Server and the rebuild will behave as told to by the new comserver.
i can update my com server to add new functionality, and every feature will obey these rules as it is not embedded. one place to modify the code.
it is howerver suggested i believe that different types of macrofeatures use a different comserver, or a different class in the COMServer project.
like MyComServer.ThisFeature or
MyCOMServer.ThatFeature or
MYCOMServer.OtherFeature.
i do not do this, i set a parameter in each feature that tells my comserver what the feature is. it enables my features to adapt and become any other type of feature.
here is something that is created by my comserver. every feature is a macrofeature.
you can even redeploy your comserver and the rebuild will obey the new DLL File. (read up on strong name versioning in the api help also)